From b111064e13fe45b455da06fd2b330c7fcfc2cbc3 Mon Sep 17 00:00:00 2001 From: Michal Zakrzewski Date: Sat, 13 Jul 2024 11:07:14 +0200 Subject: [PATCH] fix: Dockerfile to use multi-stage build (#121) --- Dockerfile | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6ee5677..e302f63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,25 @@ ARG NODE_VERSION=20 - -FROM node:${NODE_VERSION} -LABEL org.opencontainers.image.source https://github.com/eddiehubcommunity/CreatorsRegistry +FROM node:${NODE_VERSION} as builder WORKDIR /usr/src/app -COPY . . +COPY package*.json ./ RUN npm ci +COPY . . + +RUN npx prisma generate +RUN npm run build + +# Production image, copy all the files and run next +FROM node:${NODE_VERSION} as production +LABEL org.opencontainers.image.source https://github.com/eddiehubcommunity/CreatorsRegistry + +WORKDIR /usr/src/app + +COPY --from=builder /usr/src/app . + EXPOSE 3000 -CMD npm run db:prod:migrate && npm run build && npm run start +CMD npm run db:prod:migrate && npm run start \ No newline at end of file