Last active
February 3, 2020 23:57
-
-
Save gquittet/efa0ef21540deb870dbfe65c155704d8 to your computer and use it in GitHub Desktop.
Article Medium - Créer un bon Dockerfile NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.git | |
assets/readme | |
build | |
documentation | |
node_modules | |
.dockerignore | |
.env | |
.env.example | |
.gitignore | |
.gitlab-ci.yml | |
.prettierrc | |
deployment.yaml | |
docker-compose.yml | |
Dockerfile | |
jsconfig.json | |
README.md | |
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:12-slim AS base | |
ENV NODE_ENV=production | |
ENV TINI_VERSION=v0.18.0 | |
ENV PORT=3000 | |
EXPOSE 3000 | |
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini | |
RUN chmod +x /tini && \ | |
mkdir -p /node_app/app && \ | |
chown -R node:node /node_app | |
WORKDIR /node_app | |
USER node | |
COPY --chown=node:node package.json package-lock*.json ./ | |
RUN npm ci && \ | |
npm cache clean --force | |
WORKDIR /node_app/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM base AS source | |
COPY --chown=node:node . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM source AS dev | |
ENV NODE_ENV=development | |
ENV PATH=/node_app/node_modules/.bin:$PATH | |
RUN npm install --only=development --prefix /node_app | |
CMD ["nodemon", "--inspect=0.0.0.0:9229"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM source AS test | |
ENV NODE_ENV=test | |
ENV PATH=/node_app/node_modules/.bin:$PATH | |
COPY --from=dev /node_app/node_modules /node_app/node_modules | |
RUN eslint --ext js src/ && \ | |
jest | |
CMD ["jest"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM test AS audit | |
RUN npm audit --audit-level critical | |
USER root | |
RUN apt-get update && \ | |
apt-get -y install ca-certificates | |
ADD https://get.aquasec.com/microscanner / | |
RUN chmod +x /microscanner && \ | |
/microscanner $MICROSCANNER_TOKEN --continue-on-failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM source AS buildProd | |
ENV PATH=/node_app/node_modules/.bin:$PATH | |
COPY --from=dev /node_app/node_modules /node_app/node_modules | |
RUN npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM source AS prod | |
COPY --from=buildProd --chown=node:node /node_app/app/build ./build | |
ENTRYPOINT ["/tini", "--"] | |
CMD ["node", "./build/main.js"] | |
HEALTHCHECK --interval=10s CMD curl --fail http://127.0.0.1:$PORT/ping || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment