Update Dockerfile and docker-compose to enhance cloudflared configuration and startup process
This commit is contained in:
@@ -55,7 +55,7 @@ RUN echo "[supervisord]" > /etc/supervisor/conf.d/supervisord.conf && \
|
|||||||
echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
echo "" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
echo "[program:cloudflared]" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "[program:cloudflared]" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
echo "command=cloudflared tunnel --no-autoupdate run --config /etc/cloudflared/config.json" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "command=cloudflared tunnel --no-autoupdate --config /etc/cloudflared/config.json run" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
echo "autostart=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "autostart=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
echo "autorestart=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "autorestart=true" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
echo "stdout_logfile=/dev/stdout" >> /etc/supervisor/conf.d/supervisord.conf && \
|
echo "stdout_logfile=/dev/stdout" >> /etc/supervisor/conf.d/supervisord.conf && \
|
||||||
|
|||||||
66
new-backend/Dockerfile.tunnel.new
Normal file
66
new-backend/Dockerfile.tunnel.new
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
FROM golang:1.19-alpine AS builder
|
||||||
|
|
||||||
|
# Install git and required dependencies
|
||||||
|
RUN apk update && apk add --no-cache git
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy go mod and sum files
|
||||||
|
COPY go.mod go.sum* ./
|
||||||
|
|
||||||
|
# Download dependencies
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application with optimizations
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o monaco-backend .
|
||||||
|
|
||||||
|
# Final stage
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# Install Docker client and tools
|
||||||
|
RUN apk update && apk add --no-cache docker-cli bash wget
|
||||||
|
|
||||||
|
# Get cloudflared directly
|
||||||
|
RUN wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/download/2023.7.3/cloudflared-linux-amd64 && \
|
||||||
|
chmod +x cloudflared && \
|
||||||
|
mv cloudflared /usr/local/bin/
|
||||||
|
|
||||||
|
# Create directories for cloudflared
|
||||||
|
RUN mkdir -p /etc/cloudflared
|
||||||
|
|
||||||
|
# Copy the certificate file and config
|
||||||
|
COPY cert.pem /etc/cloudflared/cert.pem
|
||||||
|
COPY config.json /etc/cloudflared/config.json
|
||||||
|
|
||||||
|
# Copy the binary from builder
|
||||||
|
COPY --from=builder /app/monaco-backend /monaco-backend
|
||||||
|
|
||||||
|
# Create a simple bash script to run both services
|
||||||
|
RUN echo '#!/bin/bash\n\
|
||||||
|
# Start the backend in the background\n\
|
||||||
|
/monaco-backend &\n\
|
||||||
|
BACKEND_PID=$!\n\
|
||||||
|
echo "Backend started with PID: $BACKEND_PID"\n\
|
||||||
|
\n\
|
||||||
|
# Wait for backend to start\n\
|
||||||
|
echo "Waiting for backend to initialize..."\n\
|
||||||
|
sleep 5\n\
|
||||||
|
\n\
|
||||||
|
# Start cloudflared with proper arguments\n\
|
||||||
|
echo "Starting Cloudflare tunnel to api.ishikabhoyar.tech..."\n\
|
||||||
|
# Use the specific tunnel name from config.json\n\
|
||||||
|
cloudflared tunnel run monaco-backend-tunnel\n\
|
||||||
|
\n\
|
||||||
|
# If cloudflared exits, kill the backend\n\
|
||||||
|
kill $BACKEND_PID\n\
|
||||||
|
' > /start.sh && chmod +x /start.sh
|
||||||
|
|
||||||
|
# Expose port for local access
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Run the startup script
|
||||||
|
CMD ["/start.sh"]
|
||||||
13
new-backend/config.json.new
Normal file
13
new-backend/config.json.new
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"tunnel": "monaco-backend-tunnel",
|
||||||
|
"credentials-file": "/etc/cloudflared/cert.pem",
|
||||||
|
"ingress": [
|
||||||
|
{
|
||||||
|
"hostname": "api.ishikabhoyar.tech",
|
||||||
|
"service": "http://localhost:8080"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "http_status:404"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -16,6 +16,9 @@ services:
|
|||||||
- DEFAULT_TIMEOUT=30
|
- DEFAULT_TIMEOUT=30
|
||||||
- SANDBOX_NETWORK_DISABLED=true
|
- SANDBOX_NETWORK_DISABLED=true
|
||||||
- SANDBOX_PIDS_LIMIT=50
|
- SANDBOX_PIDS_LIMIT=50
|
||||||
|
# Define cloudflared environment variables
|
||||||
|
- TUNNEL_ORIGIN_CERT=/etc/cloudflared/cert.pem
|
||||||
|
- NO_AUTOUPDATE=true
|
||||||
# Isolated network to prevent conflicts with host cloudflared
|
# Isolated network to prevent conflicts with host cloudflared
|
||||||
networks:
|
networks:
|
||||||
- monaco-backend-network
|
- monaco-backend-network
|
||||||
|
|||||||
Reference in New Issue
Block a user