From 42841bcd834435bca3ff055060b4c4162b153e0e Mon Sep 17 00:00:00 2001 From: MUIS1436 Date: Sat, 31 Jan 2026 11:26:19 +0500 Subject: [PATCH] chore(docker): update ports and switch frontend to serve static files - Change frontend port from 80 to 8847 and backend port from 3001 to 9173 in .env.example - Replace nginx stage in frontend Dockerfile with node alpine and serve for static hosting - Remove nginx.conf and related configuration for frontend static serving - Update docker-compose ports and healthcheck URLs to match new port assignments - Adjust server Dockerfile to expose new backend port 9173 and update healthcheck URL - Create non-root user in frontend Dockerfile and run serve command on port 8847 - Update healthcheck commands to use wget on new ports for both frontend and backend --- .env.example | 4 ++-- Dockerfile | 27 ++++++++++++++++----------- docker-compose.yml | 10 +++++----- nginx.conf | 31 ------------------------------- server/Dockerfile | 4 ++-- 5 files changed, 25 insertions(+), 51 deletions(-) delete mode 100644 nginx.conf diff --git a/.env.example b/.env.example index 717ab0c..307f866 100644 --- a/.env.example +++ b/.env.example @@ -29,8 +29,8 @@ REDIRECT_URI=http://localhost:5173/auth/callback # ====================== # Ports (Coolify will override these) # ====================== -FRONTEND_PORT=80 -BACKEND_PORT=3001 +FRONTEND_PORT=8847 +BACKEND_PORT=9173 # ====================== # Environment diff --git a/Dockerfile b/Dockerfile index 67739ee..114720f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Frontend Dockerfile (Coolify Optimized) +# Frontend Dockerfile (Coolify Optimized - Static Server) FROM node:20-alpine AS builder WORKDIR /app @@ -25,21 +25,26 @@ COPY . . # Build the app RUN npm run build -# Production stage -FROM nginx:alpine +# Production stage - lightweight static server +FROM node:20-alpine -# Install wget for healthcheck -RUN apk add --no-cache wget +WORKDIR /app + +# Install serve for static file hosting +RUN npm install -g serve # Copy built assets -COPY --from=builder /app/dist /usr/share/nginx/html +COPY --from=builder /app/dist ./dist -# Copy nginx config -COPY nginx.conf /etc/nginx/conf.d/default.conf +# Create non-root user +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 +USER nodejs -EXPOSE 80 +EXPOSE 8847 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD wget -q --spider http://localhost:80 || exit 1 + CMD wget -q --spider http://localhost:8847 || exit 1 -CMD ["nginx", "-g", "daemon off;"] +# Serve static files with SPA fallback +CMD ["serve", "-s", "dist", "-l", "8847"] diff --git a/docker-compose.yml b/docker-compose.yml index a6d80c0..6248c09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,13 +10,13 @@ services: - VITE_GOOGLE_CLIENT_ID=${VITE_GOOGLE_CLIENT_ID} - VITE_API_URL=${VITE_API_URL:-} ports: - - "${FRONTEND_PORT:-80}:80" + - "${FRONTEND_PORT:-8847}:8847" depends_on: backend: condition: service_healthy restart: unless-stopped healthcheck: - test: [ "CMD", "wget", "-q", "--spider", "http://localhost:80" ] + test: [ "CMD", "wget", "-q", "--spider", "http://localhost:8847" ] interval: 30s timeout: 10s retries: 3 @@ -29,9 +29,9 @@ services: context: ./server dockerfile: Dockerfile ports: - - "${BACKEND_PORT:-3001}:3001" + - "${BACKEND_PORT:-9173}:9173" environment: - - PORT=3001 + - PORT=9173 - NODE_ENV=${NODE_ENV:-production} - VITE_MS_CLIENT_ID=${VITE_MS_CLIENT_ID} - MS_CLIENT_SECRET=${MS_CLIENT_SECRET} @@ -40,7 +40,7 @@ services: - REDIRECT_URI=${REDIRECT_URI} restart: unless-stopped healthcheck: - test: [ "CMD", "wget", "-q", "--spider", "http://localhost:3001/health" ] + test: [ "CMD", "wget", "-q", "--spider", "http://localhost:9173/health" ] interval: 30s timeout: 10s retries: 3 diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index deab397..0000000 --- a/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # Gzip compression - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml; - - # Handle SPA routing - location / { - try_files $uri $uri/ /index.html; - } - - # Cache static assets - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { - expires 1y; - add_header Cache-Control "public, immutable"; - } - - # Proxy API requests to backend - location /api { - proxy_pass http://backend:3001; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } -} diff --git a/server/Dockerfile b/server/Dockerfile index d6cdb8d..1394a79 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -35,9 +35,9 @@ RUN addgroup -g 1001 -S nodejs && \ adduser -S nodejs -u 1001 USER nodejs -EXPOSE 3001 +EXPOSE 9173 HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ - CMD wget -q --spider http://localhost:3001/health || exit 1 + CMD wget -q --spider http://localhost:9173/health || exit 1 CMD ["node", "dist/index.js"]