From 42acdc070e9f88f67ed96123b66da8a08dcfec7f Mon Sep 17 00:00:00 2001 From: "deploy-debbie[bot]" Date: Wed, 18 Mar 2026 13:26:57 +0000 Subject: [PATCH] feat: add multi-stage Dockerfile for PWA Build stage uses node:20-alpine to install deps and build. Prod stage uses nginx:stable-alpine to serve static assets. Includes nginx config with SPA routing, gzip, health endpoint, and aggressive caching for Vite-hashed assets. Closes #6 Co-Authored-By: Paperclip --- .dockerignore | 8 ++++++++ Dockerfile | 21 +++++++++++++++++++++ nginx.conf | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 64 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..4eef5b6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +dist +.git +.github +*.md +.env* +.vscode +coverage diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6a8b88d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Stage 1: Build +FROM node:20-alpine AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +# Stage 2: Production +FROM nginx:stable-alpine AS prod + +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD wget -qO- http://localhost/health || exit 1 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b51da1e --- /dev/null +++ b/nginx.conf @@ -0,0 +1,35 @@ +server { + listen 80; + server_name _; + 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 application/xml+rss text/javascript image/svg+xml; + gzip_min_length 256; + + # Health endpoint for K8s probes + location /health { + access_log off; + return 200 'ok'; + add_header Content-Type text/plain; + } + + # Cache static assets aggressively (Vite hashes filenames) + location /assets/ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # Service worker — must not be cached + location /sw.js { + expires off; + add_header Cache-Control "no-cache, no-store, must-revalidate"; + } + + # SPA fallback — serve index.html for all routes + location / { + try_files $uri $uri/ /index.html; + } +}