From b888a75d1cd988b94f9cecb798f37333e808ea73 Mon Sep 17 00:00:00 2001 From: Ivan Piankov Date: Thu, 17 Jun 2021 16:44:03 +0300 Subject: [PATCH] task-8 --- .dockerignore | 17 +++++++++++++++++ Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e4d68061b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +# Top folder by size +node_modules/ +# We don't need dist from the host, because we build it in docker. +dist +# We don't need test folder for production either +test + +# Other +.dockerignore +.elasticbeanstalk/* +.eslintrc.js +.git +.gitignore +.prettierrc +Dockerfile* +README.md + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..04cd90367 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# build essential node_modules +FROM node:lts-alpine AS production-modules +WORKDIR /app +COPY ./package*.json ./ +RUN npm install --only=production && npm prune --production + +# make build +FROM node:lts-alpine AS build +WORKDIR /app +# Copy package*.json files, install dependencies +COPY ./package*.json ./ +COPY . . +# build application +RUN npm install && npm run build + +# Release with Alpine +FROM node:lts-alpine AS release +WORKDIR /app +# Install app and dependencies +COPY --from=build /app/package.json ./ +COPY --from=build /app/dist ./dist +COPY --from=production-modules /app/node_modules ./node_modules +USER node +EXPOSE 4000 +ENTRYPOINT ["node", "dist/main.js"] \ No newline at end of file