-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile-pm2
47 lines (42 loc) · 1.49 KB
/
Dockerfile-pm2
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
# Base
FROM node:16-slim as base
RUN apt-get -qq update; apt-get -qq install wget gpg -y
ENV NODE_ENV=production
RUN npm i npm@latest -g
RUN apt-get -qq purge wget gpg -y; apt-get -qq autoremove -y; apt-get -qq autoclean; rm -rf /var/lib/{apt,dpkg,cache,log}/
# apt-get is unavailable after this point
EXPOSE 8080
RUN mkdir /app && chown -R node:node /app
WORKDIR /app
USER node
COPY --chown=node:node package*.json ./
RUN npm install pm2@latest
RUN npm install --no-optional --silent && npm cache clean --force > "/dev/null" 2>&1
# Development ENV
FROM base as dev
ENV NODE_ENV=development
ENV PATH=/app/node_modules/.bin:$PATH
RUN npm install --only=development --no-optional --silent && npm cache clean --force > "/dev/null" 2>&1
CMD ["nodemon", "server.js", "--inspect=0.0.0.0:9229"]
# Source
FROM base as source
COPY --chown=node:node . .
# Test ENV
FROM source as test
ENV NODE_ENV=development
ENV PATH=/app/node_modules/.bin:$PATH
COPY --from=dev /app/node_modules /app/node_modules
RUN eslint .
RUN npm test
# Audit ENV
FROM test as audit
USER root
RUN npm audit --audit-level critical
ARG MICROSCANNER_TOKEN
ADD https://get.aquasec.com/microscanner /
RUN chmod +x /microscanner
RUN /microscanner $MICROSCANNER_TOKEN --continue-on-failure
# Production ENV
FROM source as prod
#CMD ["./node_modules/pm2/bin/pm2-runtime", "start", "index.js"]
CMD ./node_modules/pm2/bin/pm2 --name docker-node-init -o /app/logs/pm2-out.log -e /app/logs/pm2-err.log --no-daemon --node-args="--max-old-space-size=10000" start index.js