From 720a37fa821a8268d38f2f128fd48581f321eda2 Mon Sep 17 00:00:00 2001 From: Arnab-Afk Date: Thu, 14 Aug 2025 23:52:05 +0530 Subject: [PATCH] Refactor Dockerfile to create startup script dynamically, ensuring correct line endings and improved backend initialization --- new-backend/Dockerfile.tunnel | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/new-backend/Dockerfile.tunnel b/new-backend/Dockerfile.tunnel index c0f4b16..c879479 100644 --- a/new-backend/Dockerfile.tunnel +++ b/new-backend/Dockerfile.tunnel @@ -40,9 +40,21 @@ COPY config.json /etc/cloudflared/config.json # Copy the binary from builder COPY --from=builder /app/monaco-backend /monaco-backend -# Copy the startup script -COPY start.sh /start.sh -RUN chmod +x /start.sh +# Create startup script inside the container to ensure correct line endings +RUN printf '#!/bin/sh\\n' > /start.sh && \ + printf '# Start the backend\\n' >> /start.sh && \ + printf '/monaco-backend &\\n' >> /start.sh && \ + printf 'BACKEND_PID=$!\\n' >> /start.sh && \ + printf 'echo "Backend started with PID: $BACKEND_PID"\\n\\n' >> /start.sh && \ + printf '# Wait for backend to start\\n' >> /start.sh && \ + printf 'echo "Waiting for backend to initialize..."\\n' >> /start.sh && \ + printf 'sleep 5\\n\\n' >> /start.sh && \ + printf '# Start cloudflared tunnel using config file\\n' >> /start.sh && \ + printf 'echo "Starting Cloudflare tunnel to api.ishikabhoyar.tech..."\\n' >> /start.sh && \ + printf 'cloudflared tunnel --no-autoupdate run --config /etc/cloudflared/config.json\\n\\n' >> /start.sh && \ + printf '# If cloudflared exits, kill the backend too\\n' >> /start.sh && \ + printf 'kill $BACKEND_PID\\n' >> /start.sh && \ + chmod +x /start.sh # Expose port for local access EXPOSE 8080