Add Dockerfile and Makefile for cloudflared tunnel setup; include startup script

This commit is contained in:
2025-08-14 23:49:19 +05:30
parent 5902300c95
commit 9474d2f633
3 changed files with 40 additions and 9 deletions

View File

@@ -40,15 +40,9 @@ COPY config.json /etc/cloudflared/config.json
# Copy the binary from builder
COPY --from=builder /app/monaco-backend /monaco-backend
# Add startup script
RUN echo '#!/bin/sh\n\
# Start the backend\n\
/monaco-backend & \n\
# Wait for backend to start\n\
sleep 5\n\
# Start cloudflared tunnel using config file\n\
cloudflared tunnel --no-autoupdate run --config /etc/cloudflared/config.json\n\
' > /start.sh && chmod +x /start.sh
# Copy the startup script
COPY start.sh /start.sh
RUN chmod +x /start.sh
# Expose port for local access
EXPOSE 8080

21
new-backend/Makefile Normal file
View File

@@ -0,0 +1,21 @@
.PHONY: build run run-detached stop logs
# Build the image
build:
docker-compose -f docker-compose.tunnel.yml build
# Run the container
run: build
docker-compose -f docker-compose.tunnel.yml up
# Run in detached mode
run-detached: build
docker-compose -f docker-compose.tunnel.yml up -d
# Stop the container
stop:
docker-compose -f docker-compose.tunnel.yml down
# View logs
logs:
docker-compose -f docker-compose.tunnel.yml logs -f

16
new-backend/start.sh Normal file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
# Start the backend
/monaco-backend &
BACKEND_PID=$!
echo "Backend started with PID: $BACKEND_PID"
# Wait for backend to start
echo "Waiting for backend to initialize..."
sleep 5
# Start cloudflared tunnel using config file
echo "Starting Cloudflare tunnel to api.ishikabhoyar.tech..."
cloudflared tunnel --no-autoupdate run --config /etc/cloudflared/config.json
# If cloudflared exits, kill the backend too
kill $BACKEND_PID