Skip to content

Commit

Permalink
Use multi-stage build in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuxie committed Oct 4, 2024
1 parent 39eb298 commit ff0f96d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: CC0-1.0

.git
node_modules
config
lib
Expand Down
25 changes: 15 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
#
# SPDX-License-Identifier: Apache-2.0 AND AFL-3.0

# We can't use alpine anymore because crypto has rust deps.
FROM node:20-slim
FROM alpine/git:latest as git-stamp-stage
COPY . /tmp/src
RUN cd /tmp/src && git describe > version.txt.tmp && mv version.txt.tmp version.txt

FROM node:20-slim as build-stage
COPY . /tmp/src
COPY --from=git-stamp-stage /tmp/src/version.txt version.txt
RUN cd /tmp/src \
&& yarn install --network-timeout 100000 \
&& yarn install --frozen-lockfile --network-timeout 100000 \
&& yarn build \
&& mv lib/ /mjolnir/ \
&& mv node_modules / \
&& mv mjolnir-entrypoint.sh / \
&& mv package.json / \
&& mv version.txt / \
&& cd / \
&& rm -rf /tmp/*
&& yarn install --frozen-lockfile --production --network-timeout 100000

FROM node:20-slim as final-stage
COPY --from=git-stamp-stage /tmp/src/version.txt version.txt
COPY --from=build-stage /tmp/src/lib/ /mjolnir/
COPY --from=build-stage /tmp/src/node_modules /node_modules
COPY --from=build-stage /tmp/src/mjolnir-entrypoint.sh /
COPY --from=build-stage /tmp/src/package.json /

ENV NODE_ENV=production
ENV NODE_CONFIG_DIR=/data/config
Expand Down

0 comments on commit ff0f96d

Please sign in to comment.