-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
86 lines (56 loc) · 1.57 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Global variables
ARG COMMIT=""
ARG APP_USER=lyric
ARG WORKDIR=/usr/src/app
######################
# Configure base image
######################
FROM node:20.12.2-alpine AS base
ARG APP_USER
ARG WORKDIR
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
# install pnpm as root user, before updating node ownership
RUN npm i -g pnpm
# create our own user to run node, don't run node in production as root
ENV APP_UID=9999
ENV APP_GID=9999
RUN addgroup -S -g $APP_GID $APP_USER \
&& adduser -S -u $APP_UID -g $APP_GID $APP_USER \
&& mkdir -p ${WORKDIR}
WORKDIR ${WORKDIR}
RUN chown -R ${APP_USER}:${APP_USER} ${WORKDIR}
USER ${APP_USER}:${APP_USER}
######################
# Configure build image
######################
FROM base as build
ARG APP_USER
ARG WORKDIR
COPY --chown=lyric:lyric . ./
RUN pnpm install --ignore-scripts
RUN pnpm build:all
######################
# Configure prod-deps image
######################
FROM build AS prod-deps
ARG APP_USER
ARG WORKDIR
WORKDIR ${WORKDIR}
USER ${APP_USER}:${APP_USER}
# pnpm will not install any package listed in devDependencies
RUN pnpm install --prod
######################
# Configure server image
######################
FROM base AS server
ARG APP_USER
ARG WORKDIR
USER ${APP_USER}
WORKDIR ${WORKDIR}
COPY --from=prod-deps ${WORKDIR} .
COPY --from=build ${WORKDIR}/apps/server/dist apps/server/dist
EXPOSE 3000
ENV COMMIT_SHA=${COMMIT}
ENV NODE_ENV=production
CMD [ "pnpm", "start:prod" ]