Browse Source

feat(staging): add dockerfile, staging compose, and nginx internal proxy for habib shop

main
Ali Alavi 1 week ago
parent
commit
862e8ca846
  1. 7
      .dockerignore
  2. 4
      .env.staging
  3. 37
      Dockerfile
  4. 31
      docker-compose.staging.yml
  5. 77
      nginx.staging.conf

7
.dockerignore

@ -0,0 +1,7 @@
node_modules
dist
.git
.gitignore
*.log
README.md
BACKEND_SPEC.md

4
.env.staging

@ -0,0 +1,4 @@
VITE_USE_MOCK_DATA=false
VITE_API_BASE_URL=/api/shop
VITE_MEDIA_ORIGIN=
VITE_BACKEND_ORIGIN=http://najm_staging_web:8000

37
Dockerfile

@ -0,0 +1,37 @@
# syntax=docker/dockerfile:1.7
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install
FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG VITE_USE_MOCK_DATA=false
ARG VITE_API_BASE_URL=/api/shop
ARG VITE_MEDIA_ORIGIN=
ENV VITE_USE_MOCK_DATA=$VITE_USE_MOCK_DATA
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
ENV VITE_MEDIA_ORIGIN=$VITE_MEDIA_ORIGIN
ENV NODE_ENV=production
RUN npm run build
FROM nginx:1.27-alpine AS runner
RUN apk add --no-cache wget
COPY nginx.staging.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO- http://127.0.0.1:3000/healthz || exit 1
CMD ["nginx", "-g", "daemon off;"]

31
docker-compose.staging.yml

@ -0,0 +1,31 @@
services:
web:
build:
context: .
dockerfile: Dockerfile
args:
VITE_USE_MOCK_DATA: "false"
VITE_API_BASE_URL: "/api/shop"
VITE_MEDIA_ORIGIN: ""
image: shop_staging_web:latest
container_name: shop_staging_web
restart: unless-stopped
env_file:
- .env.staging
ports:
- "127.0.0.1:5562:3000"
environment:
- NODE_ENV=production
- API_BASE_URL=http://najm_staging_web:8000
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3000/healthz"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
networks:
- najm_staging_net
networks:
najm_staging_net:
external: true

77
nginx.staging.conf

@ -0,0 +1,77 @@
server {
listen 3000;
server_name _;
root /usr/share/nginx/html;
index index.html;
client_max_body_size 100M;
# Docker internal DNS resolver so upstream container IPs re-resolve dynamically
resolver 127.0.0.11 valid=10s ipv6=off;
set $backend_upstream http://najm_staging_web:8000;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript image/svg+xml;
location = /healthz {
access_log off;
default_type application/json;
return 200 '{"status":"ok","service":"habib-shop-staging"}';
}
location /api/shop/ {
proxy_pass $backend_upstream;
proxy_http_version 1.1;
proxy_set_header Host habib.nwhco.ir;
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;
proxy_read_timeout 300s;
}
location /upload-tmp-media/ {
proxy_pass $backend_upstream;
proxy_http_version 1.1;
proxy_set_header Host habib.nwhco.ir;
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;
proxy_read_timeout 300s;
}
location /habcoin/ {
proxy_pass $backend_upstream;
proxy_http_version 1.1;
proxy_set_header Host habib.nwhco.ir;
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;
proxy_read_timeout 300s;
}
location /media/ {
proxy_pass $backend_upstream;
proxy_http_version 1.1;
proxy_set_header Host habib.nwhco.ir;
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;
expires 30d;
add_header Cache-Control "public, immutable";
}
location /assets/ {
try_files $uri =404;
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
}
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
}
}
Loading…
Cancel
Save