Skip to content

Commit bb9af18

Browse files
perf(docker): cache image builds through cache mounts and GHA cache (#4020)
* perf(docker): cache image builds through cache mounts and GHA cache * tweak(ci/docker): switch to inline registry cache
1 parent d4516d3 commit bb9af18

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

.github/workflows/daedalus-docker.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- name: Checkout
25-
uses: actions/checkout@v2
25+
uses: actions/checkout@v4
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v2
2628
- name: Fetch docker metadata
2729
id: docker_meta
28-
uses: docker/metadata-action@v3
30+
uses: docker/metadata-action@v5
2931
with:
3032
images: ghcr.io/modrinth/daedalus
3133
- name: Login to GitHub Images
32-
uses: docker/login-action@v1
34+
uses: docker/login-action@v3
3335
with:
3436
registry: ghcr.io
3537
username: ${{ github.actor }}
3638
password: ${{ secrets.GITHUB_TOKEN }}
3739
- name: Build and push
38-
id: docker_build
39-
uses: docker/build-push-action@v2
40+
uses: docker/build-push-action@v6
4041
with:
4142
file: ./apps/daedalus_client/Dockerfile
4243
push: ${{ github.event_name != 'pull_request' }}
4344
tags: ${{ steps.docker_meta.outputs.tags }}
4445
labels: ${{ steps.docker_meta.outputs.labels }}
46+
cache-from: type=registry,ref=ghcr.io/modrinth/daedalus:main
47+
cache-to: type=inline

.github/workflows/labrinth-docker.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v4
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v2
2426
- name: Fetch docker metadata
2527
id: docker_meta
26-
uses: docker/metadata-action@v3
28+
uses: docker/metadata-action@v5
2729
with:
2830
images: ghcr.io/modrinth/labrinth
2931
- name: Login to GitHub Images
30-
uses: docker/login-action@v1
32+
uses: docker/login-action@v3
3133
with:
3234
registry: ghcr.io
3335
username: ${{ github.actor }}
3436
password: ${{ secrets.GITHUB_TOKEN }}
3537
- name: Build and push
36-
id: docker_build
37-
uses: docker/build-push-action@v2
38+
uses: docker/build-push-action@v6
3839
with:
3940
file: ./apps/labrinth/Dockerfile
4041
push: ${{ github.event_name != 'pull_request' }}
4142
tags: ${{ steps.docker_meta.outputs.tags }}
4243
labels: ${{ steps.docker_meta.outputs.labels }}
44+
cache-from: type=registry,ref=ghcr.io/modrinth/labrinth:main
45+
cache-to: type=inline

apps/daedalus_client/Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
# syntax=docker/dockerfile:1
2+
13
FROM rust:1.88.0 AS build
24

35
WORKDIR /usr/src/daedalus
46
COPY . .
5-
RUN cargo build --release --package daedalus_client
7+
RUN --mount=type=cache,target=/usr/src/daedalus/target \
8+
--mount=type=cache,target=/usr/local/cargo/git/db \
9+
--mount=type=cache,target=/usr/local/cargo/registry \
10+
cargo build --release --package daedalus_client
11+
12+
FROM build AS artifacts
613

14+
RUN --mount=type=cache,target=/usr/src/daedalus/target \
15+
mkdir /daedalus \
16+
&& cp /usr/src/daedalus/target/release/daedalus_client /daedalus/daedalus_client
717

818
FROM debian:bookworm-slim
919

1020
RUN apt-get update \
1121
&& apt-get install -y --no-install-recommends ca-certificates openssl \
1222
&& rm -rf /var/lib/apt/lists/*
1323

14-
COPY --from=build /usr/src/daedalus/target/release/daedalus_client /daedalus/daedalus_client
15-
WORKDIR /daedalus_client
24+
COPY --from=artifacts /daedalus /daedalus
1625

17-
CMD /daedalus/daedalus_client
26+
WORKDIR /daedalus_client
27+
CMD ["/daedalus/daedalus_client"]

apps/labrinth/Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
# syntax=docker/dockerfile:1
2+
13
FROM rust:1.88.0 AS build
24

35
WORKDIR /usr/src/labrinth
46
COPY . .
5-
RUN SQLX_OFFLINE=true cargo build --release --package labrinth
7+
RUN --mount=type=cache,target=/usr/src/labrinth/target \
8+
--mount=type=cache,target=/usr/local/cargo/git/db \
9+
--mount=type=cache,target=/usr/local/cargo/registry \
10+
SQLX_OFFLINE=true cargo build --release --package labrinth
11+
12+
FROM build AS artifacts
13+
14+
RUN --mount=type=cache,target=/usr/src/labrinth/target \
15+
mkdir /labrinth \
16+
&& cp /usr/src/labrinth/target/release/labrinth /labrinth/labrinth \
17+
&& cp -r /usr/src/labrinth/apps/labrinth/migrations /labrinth \
18+
&& cp -r /usr/src/labrinth/apps/labrinth/assets /labrinth
619

720
FROM debian:bookworm-slim
821

@@ -14,10 +27,8 @@ RUN apt-get update \
1427
&& apt-get install -y --no-install-recommends ca-certificates dumb-init curl \
1528
&& rm -rf /var/lib/apt/lists/*
1629

17-
COPY --from=build /usr/src/labrinth/target/release/labrinth /labrinth/labrinth
18-
COPY --from=build /usr/src/labrinth/apps/labrinth/migrations/* /labrinth/migrations/
19-
COPY --from=build /usr/src/labrinth/apps/labrinth/assets /labrinth/assets
20-
WORKDIR /labrinth
30+
COPY --from=artifacts /labrinth /labrinth
2131

32+
WORKDIR /labrinth
2233
ENTRYPOINT ["dumb-init", "--"]
2334
CMD ["/labrinth/labrinth"]

0 commit comments

Comments
 (0)