forked from ducktors/turborepo-remote-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
60 lines (41 loc) · 1.59 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
FROM --platform=${TARGETPLATFORM} node:18.15.0-alpine3.17@sha256:ffc770cdc09c9e83cccd99d663bb6ed56cfaa1bab94baf1b12b626aebeca9c10 as build
# set app basepath
ENV HOME=/home/app
# add app dependencies
COPY package.json $HOME/node/
COPY pnpm-lock.yaml $HOME/node/
# change workgin dir and install deps in quiet mode
WORKDIR $HOME/node
# enable pnpm and install deps
RUN corepack enable
RUN pnpm --ignore-scripts --frozen-lockfile install
# copy all app files
COPY . $HOME/node/
# compile typescript and build all production stuff
RUN pnpm build
# remove dev dependencies and files that are not needed in production
RUN rm -rf node_modules
RUN pnpm install --prod --frozen-lockfile --ignore-scripts
RUN rm -rf $PROJECT_WORKDIR/.pnpm-store
# start new image for lower size
FROM --platform=${TARGETPLATFORM} node:18.15.0-alpine3.17@sha256:ffc770cdc09c9e83cccd99d663bb6ed56cfaa1bab94baf1b12b626aebeca9c10
RUN apk update
# dumb-init registers signal handlers for every signal that can be caught
RUN apk add --no-cache dumb-init
# Add git to the image for git-repository storage
RUN apk add --no-cache git
# Add curl to the image for healthcheck
RUN apk add --no-cache curl
# create use with no permissions
RUN addgroup -g 101 -S app && adduser -u 100 -S -G app -s /bin/false app
# set app basepath
ENV HOME=/home/app
# copy production complied node app to the new image
COPY --chown=app:app --from=build $HOME/node/ $HOME/node/
# run app with low permissions level user
USER app
WORKDIR $HOME/node
EXPOSE 3000
ENV NODE_ENV=production
ENTRYPOINT ["dumb-init"]
CMD ["node", "--enable-source-maps", "build/index.js"]