-
Notifications
You must be signed in to change notification settings - Fork 27
/
Dockerfile
55 lines (40 loc) · 1.63 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
# syntax=docker/dockerfile:1
#----------------------------------------#
# dev/test
FROM node:lts-alpine AS deps
RUN apk add --no-cache --virtual .gyp python3 make g++ libc6-compat && \
npm i -g npm
ENV NPM_CONFIG_PREFER_OFFLINE=true
ENV PATH="node_modules/.bin:$PATH"
USER node
WORKDIR /home/node
# "Cache" node_modules first so that changes in the source code doesn't trigger a rebuild
COPY --chown=node:node [ "package*.json", ".npmrc", "./" ]
RUN npm ci
COPY --chown=node:node . .
#----------------------------------------#
# We have a separate build container to persist build artifacts & production npm deps
FROM node:lts-alpine AS build
RUN apk add --no-cache --virtual .gyp python3 make g++ libc6-compat && \
npm i -g npm
ENV NPM_CONFIG_PREFER_OFFLINE=true
USER node
WORKDIR /home/node
# idk if this *actually* caches node_modules from the deps image or not so that the first COPY is only run when package.json changes
COPY --chown=node:node --from=deps /home/node/node_modules ./node_modules
COPY --chown=node:node . ./
RUN npm run build && \
npm prune --production && \
rm -rf .cache .npm
#----------------------------------------#
FROM node:lts-alpine AS runner
RUN apk add --no-cache tini
USER node
WORKDIR /home/node
COPY --from=build /home/node ./
ENV NODE_ENV production
# While we already handle SIGINT/SIGTERM directly, there is no way for us to be 100% SURE that none of our dependencies won't spawn a zombie process.
ENTRYPOINT ["tini", "--"]
CMD ["node", "bin/www"]
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1