From 0be065389bcc676c2b02e3016334a8004195ad33 Mon Sep 17 00:00:00 2001 From: Claudemir Todo Bom Date: Tue, 30 Jul 2024 16:09:13 -0300 Subject: [PATCH] build backend image without sourcecode and sourcemap --- backend/Dockerfile | 24 ++++++++++++++++++------ backend/tsconfig.json | 1 - 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 0bb5e2d5..986a35a4 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,17 +1,29 @@ -FROM node:20 +# Stage 1: Build the application +FROM node:20 AS build WORKDIR /usr/src/app COPY . . +RUN npm install \ + && npm run build + +# Stage 2: Create the final image without source files +FROM node:20 + +WORKDIR /usr/src/app + +# Install dumb-init and dockerize ENV DOCKERIZE_VERSION v0.7.0 -RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_$(uname -m) \ +RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_$(uname -m) \ && chmod +x /usr/local/bin/dumb-init \ && wget -O /usr/local/bin/dockerize.tar.gz https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-$(dpkg --print-architecture)-${DOCKERIZE_VERSION}.tar.gz \ && tar -C /usr/local/bin -xzvf /usr/local/bin/dockerize.tar.gz \ - && rm /usr/local/bin/dockerize.tar.gz \ - && npm install \ - && echo -e "\n\nBulding...\n" \ - && npm run build + && rm /usr/local/bin/dockerize.tar.gz + +# Copy only the necessary build artifacts from the build stage +COPY --from=build /usr/src/app/dist ./dist +COPY --from=build /usr/src/app/node_modules ./node_modules +COPY --from=build /usr/src/app/package.json ./package.json ENV NODE_ENV=production ENV PORT=3000 diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 170c22fc..51094394 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -10,6 +10,5 @@ "emitDecoratorMetadata": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "sourceMap": true, } }