-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (44 loc) · 2.72 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (44 loc) · 2.72 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
# ──────────────────────────────────────────────────────────────────────────
# Evolith Tracker Web (React + Vite SPA) — multi-stage build → nginx.
#
# BUILD CONTEXT: the tracker monorepo `src/` directory (the folder with the
# root package.json / nx.json).
# docker build -f apps/tracker-web/Dockerfile -t evolith-tracker-web:local src/
#
# The SPA reads its BFF base URL from VITE_TRACKER_BFF_BASE_URL at BUILD time
# (import.meta.env). We default it to the relative path `/api`, and nginx (see
# nginx.conf) proxies `/api` → the tracker-api service, so the same image works
# in any cluster without rebuilding. Override VITE_TRACKER_BFF_BASE_URL as a
# build-arg to bake an absolute URL instead.
# ──────────────────────────────────────────────────────────────────────────
FROM node:20-alpine AS build
WORKDIR /repo
# Install deps against the monorepo lockfile first (layer caching).
COPY package.json package-lock.json nx.json tsconfig.base.json ./
RUN npm ci --legacy-peer-deps
# Bring in the workspace and build only the web app via the Nx/Vite target.
COPY . ./
ARG VITE_TRACKER_BFF_BASE_URL=/api
ENV VITE_TRACKER_BFF_BASE_URL=${VITE_TRACKER_BFF_BASE_URL}
RUN npx nx build tracker-web --configuration=production \
|| npx nx build tracker-web
# ── Runtime: rootless nginx serving the static SPA ─────────────────────────
# nginx-unprivileged runs as uid 101 with writable temp/cache paths and an
# entrypoint that envsubsts templates into a writable dir — so it starts cleanly
# under a hardened (non-root) pod securityContext.
FROM nginxinc/nginx-unprivileged:1.27-alpine AS runtime
LABEL org.opencontainers.image.title="Evolith Tracker Web"
LABEL org.opencontainers.image.source="https://github.com/beyondnetcode/evolith_tracker"
USER root
RUN apk add --no-cache curl
USER 101
# Vite build output lands in dist/apps/tracker-web (see vite.config.mts).
COPY --from=build /repo/dist/apps/tracker-web /usr/share/nginx/html
COPY apps/tracker-web/nginx.conf /etc/nginx/templates/default.conf.template
# `TRACKER_API_UPSTREAM` is substituted into the nginx config at container
# start (the entrypoint runs /docker-entrypoint.d/20-envsubst-on-templates.sh),
# so the `/api` proxy target is configurable per environment.
ENV TRACKER_API_UPSTREAM=http://evolith-tracker-api:80
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/healthz || exit 1