diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4acc6cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +dist +.env.local +.env.*.local diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..43c6cdc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Stage 1: Build +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . + +ARG VITE_API_BASE_URL=https://tripwisedaily.ir/api +ARG VITE_USE_MOCKS=false + +ENV VITE_API_BASE_URL=$VITE_API_BASE_URL +ENV VITE_USE_MOCKS=$VITE_USE_MOCKS + +RUN npm run build + +# Stage 2: Serve +FROM nginx:1.27-alpine + +COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/dist /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..d991ab4 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # Gzip + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml; + + # Cache static assets + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # SPA fallback — all routes go to index.html + location / { + try_files $uri $uri/ /index.html; + } +}