|
1 | | -# Stage 1: builder |
| 1 | + |
| 2 | +# Builder Stage |
2 | 3 | FROM node:22-alpine AS builder |
3 | 4 |
|
4 | 5 | WORKDIR /app |
5 | 6 |
|
6 | | -# install pnpm & git |
7 | | -RUN npm install -g pnpm |
8 | | -RUN apk update && \ |
9 | | - apk upgrade && \ |
10 | | - apk add --no-cache git |
11 | | - |
12 | | -RUN git init |
| 7 | +# install tools |
| 8 | +RUN npm install -g pnpm && \ |
| 9 | + apk add --no-cache git && \ |
| 10 | + git init |
13 | 11 |
|
14 | | - |
15 | | -# copy lock, package files and configs |
| 12 | +# copy files needed for installing dependencies |
16 | 13 | COPY package.json pnpm-lock.yaml ./ |
17 | | -COPY run-jiti.js ./ |
18 | | -COPY src/features/build-info/script-to-generate-json.ts src/features/build-info/build-info.gen.json ./src/features/build-info/ |
19 | 14 | COPY prisma/schema.prisma ./prisma/ |
| 15 | +COPY run-jiti.js ./ |
| 16 | +COPY src/features/build-info/script-to-generate-json.ts ./src/features/build-info/ |
20 | 17 |
|
| 18 | +# install dependencies |
21 | 19 | RUN pnpm install --frozen-lockfile |
22 | 20 |
|
23 | | -# copy source |
| 21 | +# copy source code |
24 | 22 | COPY . . |
25 | 23 |
|
| 24 | +# build the application |
26 | 25 | ENV NODE_OPTIONS=--max-old-space-size=4096 |
27 | | - |
28 | | -# build app |
29 | 26 | RUN pnpm build |
30 | 27 |
|
31 | 28 |
|
32 | | -# Stage 2: runtime |
33 | | -FROM node:22-alpine AS runtime |
34 | | - |
| 29 | +# Runtime Stage |
| 30 | +FROM node:22-alpine |
35 | 31 |
|
36 | 32 | WORKDIR /app |
37 | 33 |
|
38 | | -# ENV |
39 | | -ENV NODE_ENV=production |
40 | | -ENV HOST=0.0.0.0 |
41 | | -ENV PORT=3000 |
| 34 | +# Environnement variables |
| 35 | +ENV NODE_ENV=production \ |
| 36 | + HOST=0.0.0.0 \ |
| 37 | + PORT=3000 |
42 | 38 |
|
43 | | -# install pnpm |
44 | | -RUN npm install -g pnpm npm-run-all |
| 39 | +# install tools |
| 40 | +RUN npm install -g pnpm npm-run-all && \ |
| 41 | + apk add --no-cache git && \ |
| 42 | + git init |
45 | 43 |
|
46 | | -COPY .env ./ |
| 44 | +# copy files needed for installing dependencies |
47 | 45 |
|
48 | 46 |
|
| 47 | +COPY --from=builder /app/package.json ./ |
| 48 | +COPY --from=builder /app/pnpm-lock.yaml ./ |
| 49 | +COPY --from=builder /app/run-jiti.js ./ |
| 50 | +COPY --from=builder /app/prisma ./prisma |
| 51 | +COPY --from=builder /app/src/features/build-info ./src/features/build-info |
49 | 52 |
|
50 | | -## copy output build and package.json from builder |
51 | | -COPY --from=builder /app/.output ./.output |
52 | | -COPY --from=builder /app/package.json ./package.json |
53 | | -COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml |
| 53 | +# copy environment configuration |
| 54 | +# TODO: Replace with environment variables or secrets in production |
| 55 | +COPY .env ./ |
| 56 | + |
| 57 | +# install production dependencies (this will run prisma generate) |
54 | 58 | RUN pnpm install --frozen-lockfile |
55 | 59 |
|
| 60 | +# copy build artifacts after installation |
| 61 | +COPY --from=builder /app/.output ./.output |
| 62 | + |
56 | 63 | EXPOSE 3000 |
57 | 64 |
|
58 | | -# start |
| 65 | +# start the application |
59 | 66 | CMD ["pnpm", "start"] |
0 commit comments