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
This commit is contained in:
parent
d4516d3527
commit
bb9af18eed
13
.github/workflows/daedalus-docker.yml
vendored
13
.github/workflows/daedalus-docker.yml
vendored
@ -22,23 +22,26 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
- name: Fetch docker metadata
|
- name: Fetch docker metadata
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
uses: docker/metadata-action@v3
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/modrinth/daedalus
|
images: ghcr.io/modrinth/daedalus
|
||||||
- name: Login to GitHub Images
|
- name: Login to GitHub Images
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
id: docker_build
|
uses: docker/build-push-action@v6
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
with:
|
||||||
file: ./apps/daedalus_client/Dockerfile
|
file: ./apps/daedalus_client/Dockerfile
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
|
cache-from: type=registry,ref=ghcr.io/modrinth/daedalus:main
|
||||||
|
cache-to: type=inline
|
||||||
|
|||||||
13
.github/workflows/labrinth-docker.yml
vendored
13
.github/workflows/labrinth-docker.yml
vendored
@ -20,23 +20,26 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
- name: Fetch docker metadata
|
- name: Fetch docker metadata
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
uses: docker/metadata-action@v3
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/modrinth/labrinth
|
images: ghcr.io/modrinth/labrinth
|
||||||
- name: Login to GitHub Images
|
- name: Login to GitHub Images
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
id: docker_build
|
uses: docker/build-push-action@v6
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
with:
|
||||||
file: ./apps/labrinth/Dockerfile
|
file: ./apps/labrinth/Dockerfile
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
|
cache-from: type=registry,ref=ghcr.io/modrinth/labrinth:main
|
||||||
|
cache-to: type=inline
|
||||||
|
|||||||
@ -1,9 +1,19 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
FROM rust:1.88.0 AS build
|
FROM rust:1.88.0 AS build
|
||||||
|
|
||||||
WORKDIR /usr/src/daedalus
|
WORKDIR /usr/src/daedalus
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN cargo build --release --package daedalus_client
|
RUN --mount=type=cache,target=/usr/src/daedalus/target \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/git/db \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
cargo build --release --package daedalus_client
|
||||||
|
|
||||||
|
FROM build AS artifacts
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/usr/src/daedalus/target \
|
||||||
|
mkdir /daedalus \
|
||||||
|
&& cp /usr/src/daedalus/target/release/daedalus_client /daedalus/daedalus_client
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
@ -11,7 +21,7 @@ RUN apt-get update \
|
|||||||
&& apt-get install -y --no-install-recommends ca-certificates openssl \
|
&& apt-get install -y --no-install-recommends ca-certificates openssl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY --from=build /usr/src/daedalus/target/release/daedalus_client /daedalus/daedalus_client
|
COPY --from=artifacts /daedalus /daedalus
|
||||||
WORKDIR /daedalus_client
|
|
||||||
|
|
||||||
CMD /daedalus/daedalus_client
|
WORKDIR /daedalus_client
|
||||||
|
CMD ["/daedalus/daedalus_client"]
|
||||||
|
|||||||
@ -1,8 +1,21 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
FROM rust:1.88.0 AS build
|
FROM rust:1.88.0 AS build
|
||||||
|
|
||||||
WORKDIR /usr/src/labrinth
|
WORKDIR /usr/src/labrinth
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN SQLX_OFFLINE=true cargo build --release --package labrinth
|
RUN --mount=type=cache,target=/usr/src/labrinth/target \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/git/db \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
SQLX_OFFLINE=true cargo build --release --package labrinth
|
||||||
|
|
||||||
|
FROM build AS artifacts
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/usr/src/labrinth/target \
|
||||||
|
mkdir /labrinth \
|
||||||
|
&& cp /usr/src/labrinth/target/release/labrinth /labrinth/labrinth \
|
||||||
|
&& cp -r /usr/src/labrinth/apps/labrinth/migrations /labrinth \
|
||||||
|
&& cp -r /usr/src/labrinth/apps/labrinth/assets /labrinth
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
@ -14,10 +27,8 @@ RUN apt-get update \
|
|||||||
&& apt-get install -y --no-install-recommends ca-certificates dumb-init curl \
|
&& apt-get install -y --no-install-recommends ca-certificates dumb-init curl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY --from=build /usr/src/labrinth/target/release/labrinth /labrinth/labrinth
|
COPY --from=artifacts /labrinth /labrinth
|
||||||
COPY --from=build /usr/src/labrinth/apps/labrinth/migrations/* /labrinth/migrations/
|
|
||||||
COPY --from=build /usr/src/labrinth/apps/labrinth/assets /labrinth/assets
|
|
||||||
WORKDIR /labrinth
|
|
||||||
|
|
||||||
|
WORKDIR /labrinth
|
||||||
ENTRYPOINT ["dumb-init", "--"]
|
ENTRYPOINT ["dumb-init", "--"]
|
||||||
CMD ["/labrinth/labrinth"]
|
CMD ["/labrinth/labrinth"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user