From 7780886d80934a4420b343a10d5cc858387ea7cf Mon Sep 17 00:00:00 2001 From: Marco Comi Date: Wed, 31 Aug 2022 11:06:13 +0200 Subject: [PATCH 1/4] Create Dockerfile --- Dockerfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..78f40338 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +ARG NODE_VERSION=18.7.0 +# Step 1 - Compile code +FROM node:${NODE_VERSION}-alpine as build + +WORKDIR /app + +COPY --chown=node:node . /app +RUN npm ci && npm run generate && npm run compile + +# Step 2 - Prepare production image +FROM node:${NODE_VERSION}-alpine + +RUN npm install -g pm2@5.2.0 + +RUN mkdir -p /app +RUN chown -Rh node:node /app + +USER node +WORKDIR /app +COPY --chown=node:node --from=build /app/dist /app/package.json /app/package-lock.json /app/ + +ENV NODE_ENV=production +ENV LOG_LEVEL=info +ENV PORT=3000 +ENV HOSTNAME=0.0.0.0 + +# Install just the production dependencies and avoid to execute the prepare script (which invoke husky, a dev dependency) +RUN npm install --ignore-scripts && npm cache clean --force + +EXPOSE 3000 +CMD ["pm2-runtime", "/app/main.js"] From c936e453da7b998c901a6f58ac4192bff277c077 Mon Sep 17 00:00:00 2001 From: Marco Comi Date: Wed, 31 Aug 2022 11:06:22 +0200 Subject: [PATCH 2/4] Add dockerignore file --- .dockerignore | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ea2b6390 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.git/ +.github/ +.husky/ +**/node_modules/ +.adr-dir +.env.default +.eslintrc.json +.gitignore +.prettierrc +README.md +CODEOWNERS +LICENSE From 2916a49ca99c9b950d4c1f67873325c7d3c9ef87 Mon Sep 17 00:00:00 2001 From: Marco Comi Date: Wed, 31 Aug 2022 11:06:43 +0200 Subject: [PATCH 3/4] Add instruction to run with Docker in README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index abea2134..702b2716 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,17 @@ npm run generate npm run start ``` +## Run with Docker +The repository comes with a Dockerfile that you can use to run the application with Docker. +First, build the image: +``` sh +docker build -t pnvalidator . +``` +Then, run the application: +``` sh +docker run -p 3000:3000 pnvalidator +``` + ### Example ``` sh From e4326dc09de4b73946d18de36c7f8a7878802611 Mon Sep 17 00:00:00 2001 From: Marco Comi Date: Wed, 31 Aug 2022 14:11:22 +0200 Subject: [PATCH 4/4] Update README.md Co-authored-by: AF --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 702b2716..14ed7842 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,18 @@ npm run start ``` ## Run with Docker + The repository comes with a Dockerfile that you can use to run the application with Docker. First, build the image: + ``` sh -docker build -t pnvalidator . +docker build -t pnemulator . ``` + Then, run the application: + ``` sh -docker run -p 3000:3000 pnvalidator +docker run -p 3000:3000 pnemulator ``` ### Example