-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (51 loc) · 2.83 KB
/
Dockerfile
File metadata and controls
63 lines (51 loc) · 2.83 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
# ─────────────────────────────────────────────────────────────
# Devonz (devonz.diy) — Multi-stage Docker build
# Optimised for pnpm + React Router v7 on Node 20 LTS
# ─────────────────────────────────────────────────────────────
# ── Stage 1: base ─────────────────────────────────────────────
# Shared base with corepack-managed pnpm
FROM node:20-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack prepare pnpm@9.14.4 --activate
WORKDIR /app
# ── Stage 2: deps ─────────────────────────────────────────────
# Install ALL dependencies (dev + prod) for the build step
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile
# ── Stage 3: build ────────────────────────────────────────────
# Build the React Router application
FROM deps AS build
COPY . .
# Git info for pre-start.cjs (falls back to 'no-git-info' in Docker)
RUN node pre-start.cjs
RUN pnpm build
# ── Stage 4: prod-deps ───────────────────────────────────────
# Prune to production deps only (@react-router/serve is now a prod dep)
FROM build AS prod-deps
RUN pnpm prune --prod --ignore-scripts
# ── Stage 5: runtime ─────────────────────────────────────────
# Minimal final image — only build output + prod deps
FROM node:20-slim AS runtime
ENV NODE_ENV="production"
ENV PORT="5173"
WORKDIR /app
# git: needed by api.git-info.ts (execSync('git ...'))
# curl: needed for healthchecks on some container platforms
RUN apt-get update && apt-get install -y --no-install-recommends git curl \
&& rm -rf /var/lib/apt/lists/*
# Copy node_modules (includes @react-router/serve needed for runtime)
COPY --from=prod-deps /app/node_modules ./node_modules
# Copy build output
COPY --from=build /app/build ./build
# Copy package.json (needed by @react-router/serve)
COPY --from=build /app/package.json ./
# Non-root user for security
RUN groupadd --system --gid 1001 appgroup && \
useradd --system --uid 1001 --gid appgroup --create-home appuser && \
chown -R appuser:appgroup /app
USER appuser
EXPOSE 5173
CMD ["node", "node_modules/@react-router/serve/dist/cli.js", "./build/server/index.js"]