Repository navigation
Expand file tree
/
Copy pathDockerfile.frontend.prod
More file actions
73 lines (60 loc) · 2.04 KB
/
Copy pathDockerfile.frontend.prod
File metadata and controls
73 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
FROM node:20-alpine AS builder
WORKDIR /app
# Copy root package files
COPY package*.json ./
# Copy shared package
COPY packages/shared/package*.json ./packages/shared/
# Copy frontend package
COPY packages/frontend/package*.json ./packages/frontend/
# Install all dependencies
RUN npm install
# Copy shared source and build
COPY packages/shared ./packages/shared
RUN npm run build:shared
# Copy frontend source
COPY packages/frontend ./packages/frontend
# Build frontend (skip tsc type checking, use vite directly)
WORKDIR /app/packages/frontend
RUN npx vite build
# Production stage with nginx
FROM nginx:alpine
# Copy built frontend files
COPY --from=builder /app/packages/frontend/dist/ /usr/share/nginx/html/
# Copy nginx config for SPA.
# Order matters: more-specific no-cache locations MUST come before the
# catch-all immutable-asset rule. sw.js / registerSW.js / manifest.json /
# index.html cannot be cached or PWA users get stuck on stale builds forever.
RUN echo 'server { \
listen 80; \
root /usr/share/nginx/html; \
index index.html; \
location = /sw.js { \
add_header Cache-Control "no-cache, no-store, must-revalidate"; \
add_header Pragma "no-cache"; \
expires off; \
} \
location = /registerSW.js { \
add_header Cache-Control "no-cache, no-store, must-revalidate"; \
add_header Pragma "no-cache"; \
expires off; \
} \
location = /manifest.json { \
add_header Cache-Control "no-cache, no-store, must-revalidate"; \
add_header Pragma "no-cache"; \
expires off; \
} \
location = /index.html { \
add_header Cache-Control "no-cache, no-store, must-revalidate"; \
add_header Pragma "no-cache"; \
expires off; \
} \
location / { \
try_files $uri $uri/ /index.html; \
} \
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { \
expires 1y; \
add_header Cache-Control "public, immutable"; \
} \
}' > /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]