-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
55 lines (41 loc) · 1.61 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
# Docker file for data service.
# Follows multi-staged build where "dev" can be used for development
# and "prod" follows security best-practices and uses a trimmed down image.
FROM node:16.18.0 as dev
# Create app directory
WORKDIR /usr/src/app/data-serving/data-service
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY data-serving/data-service/package*.json ./
# Try to avoid cb not called error in CI
RUN npm cache clean --force
# RUN npm clean install
RUN npm ci
# Bundle app source
COPY data-serving/data-service/. .
# Bundle common files
COPY common/* ../../common/
# Build the app
RUN npm run build
# Expose service on port 3000.
EXPOSE 3000
# Expose v8 inspector on port 9229.
# If you start node with the --inspect option you'll be able to connnect by pointing Chromium to chrome://inspect
# EXPOSE 9229
# Specify a command for up to this step.
CMD [ "npm", "start" ]
# Multi-staged build, we don't need a full node image to run the app.
FROM node:16.18.0-alpine as prod
# No need to run as root.
USER node
# Run with node env set to production.
ENV NODE_ENV production
WORKDIR /usr/src/app/
# Copy compiled app from previous stage.
COPY --from=dev /usr/src/app/data-serving/data-service/node_modules ./node_modules
COPY --from=dev /usr/src/app/data-serving/data-service/api ./api
COPY --from=dev /usr/src/app/data-serving/data-service/dist ./dist
# Start service, do not use npm start instead invoke node directly
# to avoid wrapping the process uselessly and correctly catch SIGTERM and SIGINT.
CMD [ "node", "dist/server.js" ]