-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.backend
53 lines (35 loc) · 1.17 KB
/
Dockerfile.backend
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
# base node image
FROM node:20-bullseye-slim AS base
# set for base and all layer that inherit from it
ENV NODE_ENV=production
# Install pnpm
RUN npm install -g pnpm
# Install openssl for Prisma
RUN apt-get update && apt-get install -y openssl
# Install all node_modules, including dev dependencies
FROM base AS deps
WORKDIR /myapp
ADD package.json pnpm-lock.yaml .npmrc ./
RUN pnpm install --frozen-lockfile --prod=false
# Setup production node_modules
FROM base AS production-deps
WORKDIR /myapp
COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD package.json pnpm-lock.yaml .npmrc .env ./
RUN pnpm prune --prod --config.ignore-scripts=true
# Build the app
FROM base AS build
WORKDIR /myapp
COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD prisma .
RUN npx prisma generate
ADD . .
RUN pnpm run build
# Finally, build the production image with minimal footprint
FROM base
WORKDIR /myapp
COPY --from=production-deps /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma
COPY --from=build /myapp/build/server /myapp/build/server
COPY --from=build /myapp/build/client /myapp/build/client
ADD . .