Mirrored from GitHub
github.com/roostorg/coop
1FROM node:24.14.1-bullseye-slim AS builder
2
3WORKDIR /app
4
5COPY package*.json .
6
7# Install dependencies
8RUN --mount=type=cache,target=/root/.npm npm ci
9
10COPY . .
11
12RUN npm run build
13
14RUN npm prune --omit=dev
15
16FROM node:24.14.1-bullseye-slim AS base
17
18WORKDIR /app
19
20# Keep output under ./build (not flattened) so the `db:*` scripts resolve
21# `build/index.js` both here and locally after `npm run build`.
22COPY --from=builder /app/build ./build
23COPY --from=builder /app/package.json ./package.json
24COPY --from=builder /app/node_modules ./node_modules
25
26# I create a separate stage for these steps because they are not needed for
27# development and chown can take a long time to run
28FROM base
29
30# -m creates a home dir for `coop` so `npm run` has a writable HOME for its
31# cache/logs (the container runs `npm run db:*` as this non-root user).
32RUN groupadd -r coop && useradd -r -g coop -u 1001 -m coop
33
34RUN chown -R coop:coop /app
35
36# kubernetes requires us to use a numeric id for the user
37USER 1001
38
39# One-shot migrations task; override the command at runtime, e.g.
40# npm run db:update -- --db api-server-pg --env prod
41CMD ["node", "build/index.js"]