Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (54 loc) · 2.11 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (54 loc) · 2.11 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
# syntax=docker/dockerfile:1.28
# ================ #
# Base Stage #
# ================ #
# Do NOT pin to $BUILDPLATFORM: the `runner` stage inherits from `base`, so pinning
# the base image to the builder's architecture bakes build-host binaries (dumb-init,
# node, …) into the runtime image. Under a QEMU-emulated multi-arch build the arm64
# manifest entry then contains amd64 binaries (and vice versa), so the container
# crashes on start with `/usr/bin/dumb-init: Exec format error`. Omitting --platform
# lets Docker build natively for $TARGETPLATFORM so every binary matches the run arch.
FROM node:24-alpine AS base
WORKDIR /usr/src/app
ENV CI="true"
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV LOG_LEVEL=info
ENV FORCE_COLOR=true
RUN apk add --no-cache dumb-init g++ make python3
RUN corepack enable
COPY --chown=node:node pnpm-lock.yaml .
COPY --chown=node:node pnpm-workspace.yaml .
COPY --chown=node:node package.json .
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
pnpm fetch
ENTRYPOINT ["dumb-init", "--"]
# ================ #
# Builder Stage #
# ================ #
FROM base AS builder
ENV NODE_ENV="development"
COPY --chown=node:node prisma/ prisma/
COPY --chown=node:node prisma.config.ts prisma.config.ts
COPY --chown=node:node scripts/ scripts/
COPY --chown=node:node src/ src/
COPY --chown=node:node tsconfig.base.json tsconfig.base.json
COPY --chown=node:node stars.config.ts stars.config.ts
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
pnpm install --frozen-lockfile \
&& pnpm run prisma:generate \
&& pnpm run build
# ================ #
# Runner Stage #
# ================ #
FROM base AS runner
ENV NODE_ENV="production"
ENV NODE_OPTIONS="--enable-source-maps --max_old_space_size=4096"
WORKDIR /usr/src/app
COPY --chown=node:node --from=builder /usr/src/app/dist dist
COPY --chown=node:node --from=builder /usr/src/app/src/.env src/.env
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
pnpm install --prod --frozen-lockfile
USER node
# Run the built application directly; pnpm 12 may auto-install at startup.
CMD [ "node", "dist/main.mjs" ]