From 3b1d43d72c6b4a1ad85a44b1ea59410d9f80c761 Mon Sep 17 00:00:00 2001 From: temarusanov Date: Mon, 9 Oct 2023 21:43:46 +0700 Subject: [PATCH] fix: update dockerfile to npm i instead of copy deps --- apps/api/Dockerfile | 13 ++++++------- apps/gateway/Dockerfile | 14 +++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index 7ec6b4d..7349218 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -1,12 +1,9 @@ # Install dependencies only when needed -FROM docker.io/node:lts-alpine as deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine -# to understand why libc6-compat might be needed. +FROM docker.io/node:16-alpine as deps RUN apk add --no-cache libc6-compat WORKDIR /usr/src/app -COPY ./node_modules ./node_modules - -# Production image, copy all the files and run nest +COPY package*.json ./ +RUN npm install --only=production --ignore-scripts FROM docker.io/node:lts-alpine as runner RUN apk add --no-cache dumb-init @@ -14,6 +11,8 @@ ENV NODE_ENV production ENV PORT 3000 WORKDIR /usr/src/app COPY --from=deps /usr/src/app/node_modules ./node_modules +COPY ./node_modules/@prisma ./node_modules/@prisma COPY dist/apps/api . +RUN chown -R node:node . EXPOSE 3000 -CMD ["dumb-init", "node", "main.js"] +CMD ["dumb-init", "node", "main.js"] \ No newline at end of file diff --git a/apps/gateway/Dockerfile b/apps/gateway/Dockerfile index a6f2b85..cef7f71 100644 --- a/apps/gateway/Dockerfile +++ b/apps/gateway/Dockerfile @@ -1,18 +1,18 @@ # Install dependencies only when needed -FROM docker.io/node:lts-alpine as deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine -# to understand why libc6-compat might be needed. +FROM docker.io/node:16-alpine as deps RUN apk add --no-cache libc6-compat WORKDIR /usr/src/app -COPY ./node_modules ./node_modules - -# Production image, copy all the files and run nest +COPY package*.json ./ +RUN npm install --only=production --ignore-scripts FROM docker.io/node:lts-alpine as runner RUN apk add --no-cache dumb-init +ENV NODE_ENV production ENV PORT 3000 WORKDIR /usr/src/app COPY --from=deps /usr/src/app/node_modules ./node_modules +COPY ./node_modules/@prisma ./node_modules/@prisma COPY dist/apps/gateway . +RUN chown -R node:node . EXPOSE 3000 -CMD ["dumb-init", "node", "main.js"] +CMD ["dumb-init", "node", "main.js"] \ No newline at end of file