-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
40 lines (36 loc) · 1.2 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
FROM node:16.17 AS base
MAINTAINER J. Scott Smith <[email protected]>
# Following Best Practices and guidelines at:
# https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md
RUN groupmod -g 2000 node \
&& usermod -u 2000 -g 2000 node
WORKDIR /home/node/app
# Install dependencies
COPY package.json /home/node/app
COPY package-lock.json /home/node/app
# Best practice: run with NODE_ENV set to production
ENV NODE_ENV production
RUN npm install
# Linting layer, won't make it into production
FROM base AS linter
ENV NODE_ENV development
RUN npm install
COPY . /home/node/app
RUN npm run lint
# Testing layer, won't make it into production
FROM linter AS tester
RUN npm run test
RUN date > .buildtime
#
# Build stage skipped for node image, since it would require dev dependencies
#
FROM base AS prod
# Best practice: run as user 'node'
USER node
EXPOSE 3040
# Copy source files; relies on .dockerignore
COPY --from=tester /home/node/app/.buildtime .buildtime
COPY . /home/node/app
# Best practice: bypass the package.json's start
CMD [ "node", "./node_modules/moleculer/bin/moleculer-runner.js", "./src/services/**/*.service.js" ]