diff --git a/.github/workflows/binaries.yml b/.github/workflows/binaries.yml index 13da3729f3..459bbe0f79 100644 --- a/.github/workflows/binaries.yml +++ b/.github/workflows/binaries.yml @@ -194,7 +194,7 @@ jobs: EOF - name: Build and push multiplatform image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . push: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9e0e4b5637..f32b8ed1ee 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -68,9 +68,22 @@ jobs: driver-opts: | network=host - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.4 + - name: Cache sccache + uses: actions/cache@v4 + with: + path: sccache-cache + key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }} + + - name: Inject sccache-cache into Docker + uses: reproducible-containers/buildkit-cache-dance@v3 + with: + cache-map: | + { + "sccache-cache": "/var/cache/sccache" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Log into GitHub container registry uses: docker/login-action@v3 with: @@ -107,7 +120,7 @@ jobs: - name: Build${{inputs.uploadImageAsTarball != true && ' and push ' || ' '}}Docker image id: build - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: "docker/Dockerfile" @@ -119,13 +132,11 @@ jobs: network: host build-args: | CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }} - ACTIONS_CACHE_URL=http://127.0.0.1:49160/ - ACTIONS_RUNTIME_TOKEN - SCCACHE_GHA_ENABLED=true RESTATE_FEATURES=${{ inputs.features || '' }} - cache-from: type=gha,scope=${{ github.workflow }},url=http://127.0.0.1:49160/ - cache-to: type=gha,mode=max,scope=${{ github.workflow }},url=http://127.0.0.1:49160/ - + SCCACHE_DIR=~/.cache/sccache + cache-from: type=gha,url=http://127.0.0.1:49160/ + cache-to: type=gha,url=http://127.0.0.1:49160/,mode=max + - name: Save docker image as tar if: ${{ inputs.uploadImageAsTarball }} run: | @@ -144,7 +155,7 @@ jobs: # This won't actually build again, it'll just use cache - name: Push Docker image if: ${{ inputs.uploadImageAsTarball && github.ref == 'refs/heads/main' }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: "docker/Dockerfile" @@ -157,9 +168,8 @@ jobs: network: host build-args: | CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }} - ACTIONS_CACHE_URL=http://127.0.0.1:49160/ - ACTIONS_RUNTIME_TOKEN - SCCACHE_GHA_ENABLED=true RESTATE_FEATURES=${{ inputs.features || '' }} - cache-from: type=gha,scope=${{ github.workflow }},url=http://127.0.0.1:49160/ - cache-to: type=gha,mode=max,scope=${{ github.workflow }},url=http://127.0.0.1:49160/ + SCCACHE_DIR=/sccache-cache + cache-from: type=gha,url=http://127.0.0.1:49160/ + cache-to: type=gha,url=http://127.0.0.1:49160/,mode=max + \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 7d87584bcd..eacb0f5106 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -26,19 +26,23 @@ ARG SCCACHE_SERVER_PORT=4227 FROM base-$TARGETARCH AS builder ARG SCCACHE_SERVER_PORT ARG TARGETARCH -# https://github.com/mozilla/sccache/blob/main/docs/GHA.md -ARG ACTIONS_CACHE_URL='' -ARG ACTIONS_RUNTIME_TOKEN='' -ARG SCCACHE_GHA_ENABLED='' + +ENV RUSTC_WRAPPER=/usr/bin/sccache +ENV SCCACHE_DIR=/var/cache/sccache + # Overrides the behaviour of the release profile re including debug symbols, which in our repo is not to include them. # Should be set to 'false' or 'true'. See https://doc.rust-lang.org/cargo/reference/environment-variables.html ARG CARGO_PROFILE_RELEASE_DEBUG=false ARG RESTATE_FEATURES='' -# Caching layer if nothing has changed -# Only build restate binary to avoid compiling unneeded crates + RUN just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES chef-cook --release --bin restate-server + COPY . . -RUN just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES build --release --bin restate-server && \ +# Mount the sccache directory as a cache to leverage sccache during build +# Caching layer if nothing has changed +# Use sccache during the main build +RUN --mount=type=cache,target=/var/cache/sccache \ + just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES build --release --bin restate-server && \ just notice-file && \ mv target/$(just arch=$TARGETARCH libc=gnu print-target)/release/restate-server target/restate-server @@ -52,4 +56,4 @@ COPY --from=builder /etc/ssl /etc/ssl # useful for health checks RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* WORKDIR / -ENTRYPOINT ["/usr/local/bin/restate-server"] +ENTRYPOINT ["/usr/local/bin/restate-server"] \ No newline at end of file