forked from raydak-labs/configarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
53 lines (37 loc) · 1.44 KB
/
Dockerfile
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
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md
# TODO because multiarch build has problems with QEMU and Node we cannot use alpine here: https://github.com/nodejs/docker-node/issues/1798
FROM node:22.11.0-slim AS base
WORKDIR /app
ENV PNPM_HOME="/opt/pnpm"
ENV COREPACK_HOME="/opt/corepack"
ENV PATH="$PNPM_HOME:$PATH"
RUN apt-get update && apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*
COPY package.json pnpm-lock.yaml ./
# Do it here to add the packageManager field to the package.json
RUN corepack enable \
&& corepack prepare pnpm@9 --activate \
&& corepack use pnpm@9
RUN pnpm config set store-dir ~/.pnpm-store
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile
FROM base AS builder
COPY src src/
COPY esbuild.ts ./
RUN pnpm run build
FROM base AS dev
ENV CONFIG_LOCATION=/app/config/config.yml
ENV SECRETS_LOCATION=/app/config/secrets.yml
# manually mount src etc
CMD [ "pnpm", "start" ]
# https://github.com/evanw/esbuild/issues/1921
FROM node:22.11.0-alpine AS prod
WORKDIR /app
RUN apk add --no-cache libstdc++ dumb-init git
# TODO maybe in future. Results in breaking change
#USER node
COPY --from=builder /app/bundle.cjs /app/index.js
ENV CONFIG_LOCATION=/app/config/config.yml
ENV SECRETS_LOCATION=/app/config/secrets.yml
# Run with dumb-init to not start node with PID=1, since Node.js was not designed to run as PID 1
CMD ["dumb-init", "node", "index.js"]