-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (47 loc) · 1.54 KB
/
Dockerfile
File metadata and controls
65 lines (47 loc) · 1.54 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
# multi-stage: base (build)
FROM node:20-alpine
# create directory where the application will be built
WORKDIR /app
# copy over the dependency manifests
COPY package.json yarn.lock ./
# install dependencies
RUN yarn install --frozen-lockfile
# copy over the prisma schema
COPY prisma/schema.prisma ./prisma/
# generate the prisma client based on the schema
RUN yarn prisma generate
# copy over the code base
COPY . .
# create the bundle of the application
RUN yarn build
# multi-stage: production (runtime)
FROM node:20-alpine AS production
# create arguments of build time variables
ARG user=nestjs
ARG group=${user}
ARG uid=1001
ARG gid=$uid
# [temporary] work around to be able to run prisma
RUN apt-get update -y && apt-get install -y openssl
# create directory where the application will be executed from
WORKDIR /app
# add the user and group
RUN groupadd --gid ${gid} ${group}
RUN useradd --uid ${uid} --gid ${gid} -m ${user}
# copy over the bundled code from the build stage
COPY --from=base /app/node_modules ./node_modules
COPY --from=base /app/package.json ./
COPY --from=base /app/yarn.lock ./
COPY --from=base /app/dist ./dist
COPY --from=base /app/prisma ./prisma
# change ownership of the workspace directory
RUN chown -R ${uid}:${gid} /app/
# install production dependencies only
RUN yarn install --production --frozen-lockfile
# set user to the created non-privileged user
USER ${user}
# expose the port the app runs on
ENV PORT=8000
EXPOSE ${PORT}
# start the server using the previously built application
CMD [ "node", "dist/main.js" ]