-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.frontend
More file actions
98 lines (84 loc) · 2.15 KB
/
Dockerfile.frontend
File metadata and controls
98 lines (84 loc) · 2.15 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Development stage
FROM node:22-bookworm-slim AS development
WORKDIR /app
ARG VITE_API_URL
ARG VITE_CONTACT_EMAIL
ARG VERSION=0.0.0
ARG GIT_SHA=unknown
ARG BUILD_TIME=unknown
ARG CHANNEL=local
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_CONTACT_EMAIL=$VITE_CONTACT_EMAIL
ENV APP_VERSION=$VERSION
ENV APP_GIT_SHA=$GIT_SHA
ENV APP_BUILD_TIME=$BUILD_TIME
ENV APP_CHANNEL=$CHANNEL
COPY ./frontend/package*.json ./
RUN npm ci
COPY ./frontend .
EXPOSE 3000
CMD ["npm", "run", "dev", "--", "--port", "3000"]
# Build stage
FROM node:22-bookworm-slim AS builder
WORKDIR /app
ARG VITE_API_URL
ARG VITE_CONTACT_EMAIL
ARG VERSION=0.0.0
ARG GIT_SHA=unknown
ARG BUILD_TIME=unknown
ARG CHANNEL=local
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_CONTACT_EMAIL=$VITE_CONTACT_EMAIL
ENV APP_VERSION=$VERSION
ENV APP_GIT_SHA=$GIT_SHA
ENV APP_BUILD_TIME=$BUILD_TIME
ENV APP_CHANNEL=$CHANNEL
COPY ./frontend/package*.json ./
RUN npm ci
COPY ./frontend .
RUN npm run build
# Serve stage
FROM nginx:alpine AS production
COPY --from=builder /app/dist /usr/share/nginx/html
RUN echo 'server { \
listen 3000; \
root /usr/share/nginx/html; \
index index.html; \
\
# Service worker - must always revalidate \
location /sw.js { \
add_header Cache-Control "no-cache"; \
try_files $uri =404; \
} \
\
# Build version metadata - must always revalidate \
location = /version.json { \
add_header Cache-Control "no-cache"; \
add_header Content-Type "application/json"; \
try_files $uri =404; \
} \
\
# Web app manifest - must always revalidate \
location ~* \.webmanifest$ { \
add_header Cache-Control "no-cache"; \
add_header Content-Type "application/manifest+json"; \
try_files $uri =404; \
} \
\
# Workbox runtime chunks \
location /workbox- { \
add_header Cache-Control "no-cache"; \
try_files $uri =404; \
} \
\
# Vite hashed assets - immutable long cache \
location /assets/ { \
add_header Cache-Control "public, max-age=31536000, immutable"; \
try_files $uri =404; \
} \
\
# SPA fallback \
location / { try_files $uri $uri/ /index.html; } \
}' > /etc/nginx/conf.d/default.conf
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]