-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.frontend
More file actions
48 lines (38 loc) · 1.94 KB
/
Dockerfile.frontend
File metadata and controls
48 lines (38 loc) · 1.94 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
# ─────────────────────────────────────────────────────────────────────────────
# Stage 1: builder — install deps and build the Vite SPA
# ─────────────────────────────────────────────────────────────────────────────
FROM node:20-alpine AS builder
WORKDIR /app
# VITE_APP_URL is injected at build time so the compiled bundle knows the API URL
ARG VITE_APP_URL
ENV VITE_APP_URL=$VITE_APP_URL
ARG VITE_APP_TITLE=APP_TITLE
ENV VITE_APP_TITLE=$VITE_APP_TITLE
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# ─────────────────────────────────────────────────────────────────────────────
# Stage 2: runner — serve the built SPA with nginx
# ─────────────────────────────────────────────────────────────────────────────
FROM nginx:alpine AS runner
# Remove the default nginx config
RUN rm /etc/nginx/conf.d/default.conf
# SPA routing config — try the requested file, fall back to index.html
RUN printf 'server {\n\
listen 80;\n\
root /usr/share/nginx/html;\n\
index index.html;\n\
\n\
location / {\n\
try_files $uri $uri/ /index.html;\n\
}\n\
\n\
location /health {\n\
return 200 '"'"'ok'"'"';\n\
add_header Content-Type text/plain;\n\
}\n\
}\n' > /etc/nginx/conf.d/app.conf
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]