2026-07-27 21:54:31 +07:00
|
|
|
# ---- Stage 1: Build Next.js static export ----
|
|
|
|
|
FROM node:22-slim AS frontend-builder
|
2026-07-04 03:03:36 +07:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Install pnpm
|
|
|
|
|
RUN corepack enable
|
2026-07-04 03:03:36 +07:00
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Install build essentials for native deps
|
|
|
|
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
|
|
|
|
|
python3 make g++ && rm -rf /var/lib/apt/lists/*
|
2026-07-04 03:03:36 +07:00
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Copy dependency manifests first for layer caching
|
|
|
|
|
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
|
|
|
|
|
COPY packages/shared/package.json ./packages/shared/package.json
|
|
|
|
|
COPY services/frontend/package.json ./services/frontend/package.json
|
|
|
|
|
COPY services/frontend/tsconfig.json ./services/frontend/tsconfig.json
|
2026-07-04 03:03:36 +07:00
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Copy patches (pnpm patchedDependencies)
|
|
|
|
|
COPY patches/ ./patches/
|
2026-07-04 03:03:36 +07:00
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Install dependencies (frontend + shared)
|
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm install --no-frozen-lockfile --filter './packages/shared' --filter './services/frontend'
|
|
|
|
|
|
|
|
|
|
# Copy source code
|
|
|
|
|
COPY packages/shared/ ./packages/shared/
|
|
|
|
|
COPY services/frontend/ ./services/frontend/
|
|
|
|
|
|
|
|
|
|
# Pass API/WS URLs as build args
|
|
|
|
|
ARG VITE_BE_API_URL
|
|
|
|
|
ARG VITE_BE_WS_URL
|
|
|
|
|
ENV VITE_BE_API_URL=${VITE_BE_API_URL}
|
|
|
|
|
ENV VITE_BE_WS_URL=${VITE_BE_WS_URL}
|
|
|
|
|
|
|
|
|
|
# Build shared lib first, then frontend static export
|
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm --filter './packages/shared' run build
|
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm --filter frontend run build
|
|
|
|
|
|
|
|
|
|
# ---- Stage 2: Nginx ----
|
2026-06-02 08:36:34 +07:00
|
|
|
FROM nginx:alpine
|
|
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Nginx config (API/WS proxy + static file serving)
|
2026-06-02 09:26:47 +07:00
|
|
|
COPY infra/docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
2026-06-02 08:36:34 +07:00
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Static export from frontend builder
|
|
|
|
|
COPY --from=frontend-builder /app/services/frontend/out/ /usr/share/nginx/html/
|
2026-07-04 03:03:36 +07:00
|
|
|
|
2026-06-02 08:36:34 +07:00
|
|
|
EXPOSE 80
|
|
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
|
|
|
|
CMD wget -qO- http://localhost:80/ || exit 1
|
|
|
|
|
|
2026-06-02 08:36:34 +07:00
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|