Skip to content

Commit b13b615

Browse files
authored
Use multi-stage build in Dockerfile (#595)
* Use multi-stage build in Dockerfile #300. * Move git describe and build into one stage. Probably won't be a good idea to download an alpine image just to install git. * Remove git describe step from CI. * whoopsie, copy version from the build stage not the deleted stamp.
1 parent 54dd85d commit b13b615

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: CC0-1.0
44

5-
.git
65
node_modules
76
config
87
lib

.github/workflows/docker-hub-develop.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ jobs:
3030
uses: actions/checkout@v4
3131
- name: Unshallow for git describe so we can create version.txt
3232
run: git fetch --prune --unshallow --tags --all --force
33-
- name: Prepare version file
34-
run: git describe > version.txt
3533

3634
# Needed for multi platform builds
3735
- name: Set up QEMU

.github/workflows/docker-hub-latest.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
3131
- name: Unshallow for git describe so we can create version.txt
3232
run: git fetch --prune --unshallow --tags --all --force
33-
- name: Prepare version file
34-
run: git describe > version.txt
35-
3633
# Needed for multi platform builds
3734
- name: Set up QEMU
3835
uses: docker/setup-qemu-action@v3

.github/workflows/docker-hub-release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ jobs:
3030
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
3131
- name: Unshallow for git describe so we can create version.txt
3232
run: git fetch --prune --unshallow --tags --all --force
33-
- name: Prepare version file
34-
run: git describe > version.txt
3533

3634
# Needed for multi platform builds
3735
- name: Set up QEMU

Dockerfile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0 AND AFL-3.0
55

6-
# We can't use alpine anymore because crypto has rust deps.
7-
FROM node:20-slim
6+
FROM node:20-slim as build-stage
7+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
88
COPY . /tmp/src
9+
# describe the version.
10+
RUN cd /tmp/src && git describe > version.txt.tmp && mv version.txt.tmp version.txt
11+
# build and install
912
RUN cd /tmp/src \
10-
&& yarn install --network-timeout 100000 \
13+
&& yarn install --frozen-lockfile --network-timeout 100000 \
1114
&& yarn build \
12-
&& mv lib/ /draupnir/ \
13-
&& mv node_modules / \
14-
&& mv draupnir-entrypoint.sh / \
15-
&& mv package.json / \
16-
&& mv version.txt / \
17-
&& cd / \
18-
&& rm -rf /tmp/*
15+
&& yarn install --frozen-lockfile --production --network-timeout 100000
16+
17+
FROM node:20-slim as final-stage
18+
COPY --from=build-stage /tmp/src/version.txt version.txt
19+
COPY --from=build-stage /tmp/src/lib/ /draupnir/
20+
COPY --from=build-stage /tmp/src/node_modules /node_modules
21+
COPY --from=build-stage /tmp/src/draupnir-entrypoint.sh /
22+
COPY --from=build-stage /tmp/src/package.json /
1923

2024
ENV NODE_ENV=production
2125
ENV NODE_CONFIG_DIR=/data/config

0 commit comments

Comments
 (0)