From 2682feef3e635ea53e9f676fd5b7f8086dce1a38 Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 12 Mar 2026 00:25:43 +0530 Subject: [PATCH 1/5] feat: add nginx reverse proxy and fix docker build env args --- docker-compose.yml | 38 +++++++++++++++++++++++++++++++++++--- nginx/default.conf | 16 ++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 nginx/default.conf diff --git a/docker-compose.yml b/docker-compose.yml index bbf12f3..fadfb00 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,10 +4,42 @@ services: build: context: . dockerfile: Dockerfile - ports: - - "3000:3000" + args: + - NEXT_PUBLIC_FIREBASE_API_KEY=${NEXT_PUBLIC_FIREBASE_API_KEY} + - NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN} + - NEXT_PUBLIC_FIREBASE_PROJECT_ID=${NEXT_PUBLIC_FIREBASE_PROJECT_ID} + - NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET} + - NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID} + - NEXT_PUBLIC_FIREBASE_APP_ID=${NEXT_PUBLIC_FIREBASE_APP_ID} + container_name: systemcraft_web + expose: + # Expose port 3000 internally to Nginx, but block it from the host machine + - "3000" env_file: - .env environment: - NODE_ENV=production - restart: unless-stopped \ No newline at end of file + restart: unless-stopped + networks: + - systemcraft_net + + nginx: + # Use the tiny official Nginx image + image: nginx:alpine + container_name: systemcraft_nginx + ports: + # Open port 80 to your computer/the internet + - "80:80" + volumes: + # Mount the configuration file you just wrote directly into the Nginx container + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + depends_on: + # Don't start Nginx if the web app crashes or isn't running + - web + restart: unless-stopped + networks: + - systemcraft_net + +# Create an isolated internal network for them to talk securely +networks: + systemcraft_net: diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..44346ae --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,16 @@ +server{ + listen 80; + server_name localhost; + + location / { + proxy_pass http://web:3000; + 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; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} \ No newline at end of file From e7dcec282e951cdfbd734fb9757462fbc4b8a009 Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 12 Mar 2026 19:38:42 +0530 Subject: [PATCH 2/5] fix: api endpoints due to the pre built docker image --- app/api/health/route.ts | 5 +++++ docker-compose.yml | 11 ++++++++--- nginx/default.conf | 41 +++++++++++++++++++++++++---------------- 3 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 app/api/health/route.ts diff --git a/app/api/health/route.ts b/app/api/health/route.ts new file mode 100644 index 0000000..4e09dd5 --- /dev/null +++ b/app/api/health/route.ts @@ -0,0 +1,5 @@ +import { NextResponse } from 'next/server'; + +export async function GET() { + return NextResponse.json({ status: 'ok' }, { status: 200 }); +} diff --git a/docker-compose.yml b/docker-compose.yml index fadfb00..9ccc14e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.8' services: web: build: @@ -22,6 +21,12 @@ services: restart: unless-stopped networks: - systemcraft_net + healthcheck: + test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/api/health || exit 1"] + interval: 10s + timeout: 5s + retries: 3 + start_period: 15s nginx: # Use the tiny official Nginx image @@ -34,8 +39,8 @@ services: # Mount the configuration file you just wrote directly into the Nginx container - ./nginx/default.conf:/etc/nginx/conf.d/default.conf depends_on: - # Don't start Nginx if the web app crashes or isn't running - - web + web: + condition: service_healthy restart: unless-stopped networks: - systemcraft_net diff --git a/nginx/default.conf b/nginx/default.conf index 44346ae..9299ca4 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -1,16 +1,25 @@ -server{ - listen 80; - server_name localhost; - - location / { - proxy_pass http://web:3000; - 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; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } -} \ No newline at end of file +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +server { + listen 80; + server_name localhost; + + # Enable runtime DNS re-resolution (use Docker's internal DNS resolver) + resolver 127.0.0.11 valid=30s; + set $upstream_endpoint http://web:3000; + + location / { + proxy_pass $upstream_endpoint; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} \ No newline at end of file From 33d53d49f4c73a4186d9c784a3efc7b5c8219b8a Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 12 Mar 2026 19:53:09 +0530 Subject: [PATCH 3/5] fix(docker-compose): update healthcheck to use BusyBox-compatible wget flags --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9ccc14e..17a900d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,7 @@ services: networks: - systemcraft_net healthcheck: - test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/api/health || exit 1"] + test: ["CMD-SHELL", "wget --spider --tries=1 http://127.0.0.1:3000/api/health || exit 1"] interval: 10s timeout: 5s retries: 3 From 439d5e6eae01eb7c08112ba63a66a779afa14f30 Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 12 Mar 2026 22:43:18 +0530 Subject: [PATCH 4/5] fix: Nextjs environment variables in the - docker-compose.yml --- docker-compose.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 17a900d..96f2cc4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,12 +4,12 @@ services: context: . dockerfile: Dockerfile args: - - NEXT_PUBLIC_FIREBASE_API_KEY=${NEXT_PUBLIC_FIREBASE_API_KEY} - - NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN} - - NEXT_PUBLIC_FIREBASE_PROJECT_ID=${NEXT_PUBLIC_FIREBASE_PROJECT_ID} - - NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET} - - NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID} - - NEXT_PUBLIC_FIREBASE_APP_ID=${NEXT_PUBLIC_FIREBASE_APP_ID} + - NEXT_PUBLIC_FIREBASE_API_KEY=${NEXT_PUBLIC_FIREBASE_API_KEY:?NEXT_PUBLIC_FIREBASE_API_KEY is required} + - NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN:?NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN is required} + - NEXT_PUBLIC_FIREBASE_PROJECT_ID=${NEXT_PUBLIC_FIREBASE_PROJECT_ID:?NEXT_PUBLIC_FIREBASE_PROJECT_ID is required} + - NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET:?NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET is required} + - NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID:?NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID is required} + - NEXT_PUBLIC_FIREBASE_APP_ID=${NEXT_PUBLIC_FIREBASE_APP_ID:?NEXT_PUBLIC_FIREBASE_APP_ID is required} container_name: systemcraft_web expose: # Expose port 3000 internally to Nginx, but block it from the host machine From 61238021bd14c8e7f01d5bbfd194654029d55036 Mon Sep 17 00:00:00 2001 From: Shashank Date: Sat, 14 Mar 2026 00:59:03 +0530 Subject: [PATCH 5/5] fix: necessary refinements to our Docker and Nginx configurations --- Dockerfile | 2 ++ docker-compose.yml | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19ff66c..22e1b4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,8 @@ ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs +RUN apk add --no-cache wget + RUN mkdir .next RUN chown nextjs:nodejs .next diff --git a/docker-compose.yml b/docker-compose.yml index 96f2cc4..ce13f31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ services: - NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET:?NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET is required} - NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID:?NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID is required} - NEXT_PUBLIC_FIREBASE_APP_ID=${NEXT_PUBLIC_FIREBASE_APP_ID:?NEXT_PUBLIC_FIREBASE_APP_ID is required} - container_name: systemcraft_web expose: # Expose port 3000 internally to Nginx, but block it from the host machine - "3000" @@ -31,13 +30,12 @@ services: nginx: # Use the tiny official Nginx image image: nginx:alpine - container_name: systemcraft_nginx ports: # Open port 80 to your computer/the internet - "80:80" volumes: # Mount the configuration file you just wrote directly into the Nginx container - - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro depends_on: web: condition: service_healthy