From e0ff72ce7c9f0990bc258dfbae02a61f3c707d78 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sat, 16 Jan 2021 01:28:35 +0200 Subject: [PATCH] Improve Dockerfiles --- .dockerignore | 18 +++++++++++++++--- Dockerfile | 20 ++++++++++++++------ Dockerfile.prod | 18 +++++++++++++----- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.dockerignore b/.dockerignore index f94630c..11c0c5e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,15 @@ -node_modules/ -dist/ -.env \ No newline at end of file +.next +.vscode +e2e-screenshots +node_modules +tests +.env* +.eslintrc.json +.gitattributes +.gitignore +.gitlab-ci.yml +.nvmrc +.stylelintrc +LICENSE +README* +stack-compose* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9ce5be2..1a0980b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,23 @@ FROM node:14-alpine as builder COPY package.json package-lock.json ./ RUN npm install -COPY . ./ -RUN NODE_ENV=development npm run build +COPY tsconfig.json next-env.d.ts .babelrc next.config.js ./ +COPY src src/ +COPY public public/ +COPY types types/ + +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_PUBLIC_API_URL=https://api.dev.sik.party/api +RUN npm run build FROM node:14-alpine as server WORKDIR /www -COPY package.json package-lock.json next.config.js ./ -RUN npm ci --only=production -COPY --from=builder .next .next -COPY --from=builder public public +COPY package.json package-lock.json ./ +COPY --from=builder .next .next +COPY --from=builder node_modules node_modules +COPY --from=builder public public + +RUN npm prune --production EXPOSE 3000 ENTRYPOINT ["npm", "run", "serve"] diff --git a/Dockerfile.prod b/Dockerfile.prod index f6f0909..3cd9f5e 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -3,15 +3,23 @@ FROM node:14-alpine as builder COPY package.json package-lock.json ./ RUN npm install -COPY . ./ +COPY tsconfig.json next-env.d.ts .babelrc next.config.js ./ +COPY src src/ +COPY public public/ +COPY types types/ + +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_PUBLIC_API_URL=https://api.sika.sik.party/api RUN npm run build FROM node:14-alpine as server WORKDIR /www -COPY package.json package-lock.json next.config.js ./ -RUN npm ci --only=production -COPY --from=builder .next .next -COPY --from=builder public public +COPY package.json package-lock.json ./ +COPY --from=builder .next .next +COPY --from=builder node_modules node_modules +COPY --from=builder public public + +RUN npm prune --production EXPOSE 3000 ENTRYPOINT ["npm", "run", "serve"]