feat: add Docker deployment — multi-stage build + nginx SPA serving

This commit is contained in:
kevin-asprec
2026-03-17 04:13:40 +08:00
parent 5376d1b1d5
commit 2340ae58c6
4 changed files with 66 additions and 0 deletions

8
.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
node_modules
dist
.git
.gitignore
*.md
.vscode
pencil-new.pen
Reports.jpg

25
Dockerfile Normal file
View File

@@ -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;"]

9
docker-compose.yml Normal file
View File

@@ -0,0 +1,9 @@
services:
taptrack-website:
build:
context: .
dockerfile: Dockerfile
container_name: taptrack-website
ports:
- "3000:80"
restart: unless-stopped

24
nginx.conf Normal file
View File

@@ -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;
}
}