diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b1ca05b..ba0297f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -32,6 +32,28 @@ jobs: with: driver: docker-container + # PR builds use linux/amd64 (ubuntu-latest default), so cache scope is hardcoded + - name: Cache tblib and cargo builds + uses: actions/cache@v4 + id: cache + with: + path: cache-mount + key: buildkit-cache-linux/amd64-${{ hashFiles('Dockerfile') }} + restore-keys: | + buildkit-cache-linux/amd64- + + - name: Inject tblib cache into Docker + uses: reproducible-containers/buildkit-cache-dance@v3.2.0 + with: + cache-dir: cache-mount + cache-map: | + { + "tblib-build": "/src/build", + "cargo-cache": "/src/target" + } + # Always skip extraction to prevent PRs from overwriting the main cache + skip-extraction: true + - name: Build and Upload id: docker_build uses: docker/build-push-action@v6 @@ -41,5 +63,5 @@ jobs: tags: ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.version }} labels: runnumber=${{ github.run_id }} provenance: false - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=tblib-linux/amd64 + cache-to: type=gha,mode=max,scope=tblib-linux/amd64 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e3d6fb..1c48c07 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,6 +65,26 @@ jobs: with: driver: docker-container + - name: Cache tblib and cargo builds + uses: actions/cache@v4 + id: cache + with: + path: cache-mount + key: buildkit-cache-${{ steps.meta.outputs.platform }}-${{ hashFiles('Dockerfile') }} + restore-keys: | + buildkit-cache-${{ steps.meta.outputs.platform }}- + + - name: Inject tblib cache into Docker + uses: reproducible-containers/buildkit-cache-dance@v3.2.0 + with: + cache-dir: cache-mount + cache-map: | + { + "tblib-build": "/src/build", + "cargo-cache": "/src/target" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Build and Upload id: docker_build uses: docker/build-push-action@v6 @@ -75,5 +95,5 @@ jobs: labels: runnumber=${{ github.run_id }} provenance: false platforms: ${{ steps.meta.outputs.platform }} - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=tblib-${{ steps.meta.outputs.platform }} + cache-to: type=gha,mode=max,scope=tblib-${{ steps.meta.outputs.platform }} diff --git a/Dockerfile b/Dockerfile index 9025393..c1a21d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN apk add --no-cache libressl-dev zlib-static zlib-dev RUN git clone --depth 1 --shallow-submodules --single-branch --recursive https://github.com/tdlib/telegram-bot-api.git src RUN cd src && git submodule update --init --recursive -RUN --mount=type=cache,target=/src/build cd src/build && \ +RUN --mount=type=cache,id=tblib-build,target=/src/build cd src/build && \ cmake -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=OFF \ -DOPENSSL_USE_STATIC_LIBS=ON \ @@ -23,7 +23,7 @@ RUN apk add --no-cache musl-dev libressl-dev WORKDIR /src COPY . . -RUN --mount=type=cache,target=/src/target \ +RUN --mount=type=cache,id=cargo-cache,target=/src/target \ cargo build --release && \ cp target/release/tg-bot-full-api /tg-bot-full-api