From 395b895686513a4fdac4f302099af57d89a0f476 Mon Sep 17 00:00:00 2001 From: Kavehhn174 Date: Mon, 17 Aug 2026 12:42:42 +0330 Subject: [PATCH] ADD: Production multi-stage Dockerfile with Nginx and .dockerignore --- .dockerignore | 16 ++++++++++++++++ Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ nginx.conf | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3d3b4e8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +node_modules +dist +npm-debug.log +.git +.gitignore +.github +.editorconfig +.idea +.vscode +.eslintcache +.env +.env.* +Dockerfile* +.dockerignore +README.md +CHANGELOG.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..437a737 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Stage 1: Build the Vue SPA application +FROM node:20-alpine AS builder + +WORKDIR /app + +# Copy dependency definitions +COPY package*.json ./ + +# Install all dependencies (including devDependencies required for Vite build) +RUN npm ci + +# Pass build arguments for environment variables +ARG VITE_API_URL="" +ARG VITE_ENV=production + +ENV VITE_API_URL=$VITE_API_URL +ENV VITE_ENV=$VITE_ENV + +# Copy application source files +COPY . . + +# Build production static bundle +RUN npm run build + +# Stage 2: Serve application with Nginx +FROM nginx:alpine AS runner + +# Remove default nginx static assets +RUN rm -rf /usr/share/nginx/html/* + +# Copy custom nginx configuration +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Copy compiled assets from the builder stage +COPY --from=builder /app/dist /usr/share/nginx/html + +# Expose web server port +EXPOSE 80 + +# Run nginx in foreground +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..69d2155 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,51 @@ +server { + listen 80; + listen [::]:80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Gzip Compression + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_proxied any; + gzip_comp_level 6; + gzip_types + text/plain + text/css + text/xml + text/javascript + application/json + application/javascript + application/x-javascript + application/xml + application/xml+rss + image/svg+xml; + + # Security Headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-XSS-Protection "1; mode=block" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; + + # Cache static assets (Vite generates unique hashes for files in /assets) + location /assets/ { + expires 1y; + add_header Cache-Control "public, max-age=31536000, immutable"; + access_log off; + } + + # SPA routing - route all queries to index.html + location / { + try_files $uri $uri/ /index.html; + add_header Cache-Control "no-cache, no-store, must-revalidate"; + } + + # Error handling + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +}