From 2340ae58c67b776574ee9e84315b75856819229d Mon Sep 17 00:00:00 2001 From: kevin-asprec Date: Tue, 17 Mar 2026 04:13:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20Docker=20deployment=20=E2=80=94?= =?UTF-8?q?=20multi-stage=20build=20+=20nginx=20SPA=20serving?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 8 ++++++++ Dockerfile | 25 +++++++++++++++++++++++++ docker-compose.yml | 9 +++++++++ nginx.conf | 24 ++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..851dc77 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +dist +.git +.gitignore +*.md +.vscode +pencil-new.pen +Reports.jpg diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2d17e36 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# ── Stage 1: Build ─────────────────────────────────────── +FROM node:22-alpine AS builder + +WORKDIR /app + +# Install dependencies first (layer cache) +COPY package.json package-lock.json ./ +RUN npm ci + +# Copy source and build +COPY . . +RUN npm run build + +# ── Stage 2: Serve ─────────────────────────────────────── +FROM nginx:alpine AS runner + +# Copy built assets from builder +COPY --from=builder /app/dist /usr/share/nginx/html + +# Copy custom nginx config for SPA routing +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a6e9884 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + taptrack-website: + build: + context: . + dockerfile: Dockerfile + container_name: taptrack-website + ports: + - "3000:80" + restart: unless-stopped diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..75effb5 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Gzip compression + gzip on; + gzip_types text/plain text/css application/javascript application/json image/svg+xml; + gzip_min_length 1024; + + # Cache static assets aggressively + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } + + # SPA fallback — all routes serve index.html + location / { + try_files $uri $uri/ /index.html; + } +}