From dbd8770f2065d7ccb36342c5bab2216902a18ca5 Mon Sep 17 00:00:00 2001 From: ishikabhoyar Date: Fri, 31 Oct 2025 16:28:37 +0530 Subject: [PATCH] refactor Dockerfile and configuration for cloudflared tunnel setup --- Frontend/Dockerfile.tunnel | 81 +++++++----------------------- Frontend/config.json | 6 ++- Frontend/docker-compose.tunnel.yml | 18 +++---- 3 files changed, 32 insertions(+), 73 deletions(-) diff --git a/Frontend/Dockerfile.tunnel b/Frontend/Dockerfile.tunnel index ede41e4..2c582e2 100644 --- a/Frontend/Dockerfile.tunnel +++ b/Frontend/Dockerfile.tunnel @@ -1,26 +1,10 @@ -FROM node:18-alpine AS builder +# Final stage +FROM alpine:latest -WORKDIR /app - -# Copy package files -COPY package*.json ./ - -# Install dependencies -RUN npm ci - -# Copy source code -COPY . . - -# Build the application -RUN npm run build - -# Production stage -FROM nginx:alpine - -# Install supervisor and cloudflared +# Install supervisor and wget RUN apk update && apk add --no-cache supervisor wget -# Get cloudflared +# Get cloudflared directly from GitHub RUN wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/download/2023.5.0/cloudflared-linux-amd64 && \ chmod +x cloudflared && \ mv cloudflared /usr/local/bin/ @@ -28,51 +12,24 @@ RUN wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/downl # Create directories for cloudflared RUN mkdir -p /etc/cloudflared -# Copy the credentials and config +# Copy the cloudflared config and credentials COPY credentials.json /etc/cloudflared/credentials.json COPY config.json /etc/cloudflared/config.json -# Copy built files from builder -COPY --from=builder /app/dist /usr/share/nginx/html - -# Create nginx config for port 8001 -RUN echo 'server {' > /etc/nginx/conf.d/default.conf && \ - echo ' listen 8001;' >> /etc/nginx/conf.d/default.conf && \ - echo ' server_name localhost;' >> /etc/nginx/conf.d/default.conf && \ - echo ' root /usr/share/nginx/html;' >> /etc/nginx/conf.d/default.conf && \ - echo ' index index.html;' >> /etc/nginx/conf.d/default.conf && \ - echo '' >> /etc/nginx/conf.d/default.conf && \ - echo ' location / {' >> /etc/nginx/conf.d/default.conf && \ - echo ' try_files $uri $uri/ /index.html;' >> /etc/nginx/conf.d/default.conf && \ - echo ' }' >> /etc/nginx/conf.d/default.conf && \ - echo '}' >> /etc/nginx/conf.d/default.conf - -# Create supervisord config +# Create supervisord config (only cloudflared, no frontend inside container) RUN mkdir -p /etc/supervisor/conf.d/ -RUN echo '[supervisord]' > /etc/supervisor/conf.d/supervisord.conf && \ - echo 'nodaemon=true' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'user=root' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo '' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo '[program:nginx]' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'command=nginx -g "daemon off;"' >> /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 'stdout_logfile=/dev/stdout' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'stdout_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'stderr_logfile=/dev/stderr' >> /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 '[program:cloudflared]' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'command=cloudflared tunnel --config /etc/cloudflared/config.json run' >> /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 'stdout_logfile=/dev/stdout' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'stdout_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'stderr_logfile=/dev/stderr' >> /etc/supervisor/conf.d/supervisord.conf && \ - echo 'stderr_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf +RUN echo "[supervisord]" > /etc/supervisor/conf.d/supervisord.conf && \ + echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "user=root" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "[program:cloudflared]" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "command=cloudflared tunnel --config /etc/cloudflared/config.json run" >> /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 "stdout_logfile=/dev/stdout" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "stdout_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "stderr_logfile=/dev/stderr" >> /etc/supervisor/conf.d/supervisord.conf && \ + echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf -# Expose port 8001 -EXPOSE 8001 - -# Use supervisord to manage processes +# Use supervisord to manage cloudflared CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/Frontend/config.json b/Frontend/config.json index 5056f07..64bf007 100644 --- a/Frontend/config.json +++ b/Frontend/config.json @@ -4,10 +4,12 @@ "ingress": [ { "hostname": "monaco.ishikabhoyar.tech", - "service": "http://localhost:8001" + "service": "http://host.docker.internal:8001" }, { "service": "http_status:404" } - ] + ], + "protocol": "http2", + "loglevel": "info" } diff --git a/Frontend/docker-compose.tunnel.yml b/Frontend/docker-compose.tunnel.yml index aaa18e9..876a910 100644 --- a/Frontend/docker-compose.tunnel.yml +++ b/Frontend/docker-compose.tunnel.yml @@ -1,19 +1,19 @@ -version: '3.8' - services: - frontend-tunnel: + tunnel: build: context: . dockerfile: Dockerfile.tunnel - ports: - - "8001:8001" restart: unless-stopped - container_name: monaco-frontend-tunnel + # Use extra_hosts to map host.docker.internal to host machine + extra_hosts: + - "host.docker.internal:host-gateway" environment: - - NODE_ENV=production + # Define cloudflared environment variables + - NO_AUTOUPDATE=true + # Isolated network networks: - - monaco-network + - monaco-tunnel-network networks: - monaco-network: + monaco-tunnel-network: driver: bridge