-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
33 lines (30 loc) · 1.18 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
# Use a multi-stage build to handle the compiling, installing, etc.
# STAGE 1: Install node_modules on a stretch container
FROM node:14 as base
ARG APP_DIR=/node
ARG OPEN_PORT=3000
EXPOSE ${OPEN_PORT}
WORKDIR ${APP_DIR}
RUN chown node:node ${APP_DIR}
COPY --chown=node:node package*.json ./
RUN ["npm", "install", "--global", "npm"]
USER node
RUN ["npm", "ci", "--omit", "optional"]
COPY --chown=node:node . .
# STAGE 2: Extend the base image as a builder image
FROM base as builder
RUN npm run build:server && rm -rf node_modules && npm ci --omit optional --omit dev
# STAGE 3: Copy the 'build' directory from previous stage and run in alpine
# Since this does not extend the base image, we need to set workdir, user, etc. again.
FROM node:14-alpine
ARG APP_DIR=/node
ARG OPEN_PORT=3000
ARG BUILD_VERSION=""
EXPOSE ${OPEN_PORT}
WORKDIR ${APP_DIR}
COPY --from=builder --chown=node:node $APP_DIR/tsconfig.production.json ./tsconfig.json
COPY --from=builder --chown=node:node $APP_DIR/node_modules ./node_modules
COPY --from=builder --chown=node:node $APP_DIR/build ./
RUN echo $BUILD_VERSION > $APP_DIR/.dockerversion
USER node
CMD ["node", "--require", "tsconfig-paths/register", "./server/index.js"]