Skip to content

Commit

Permalink
build backend image without sourcecode and sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jul 30, 2024
1 parent 87072aa commit 0be0653
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 18 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
}
}

0 comments on commit 0be0653

Please sign in to comment.