Skip to content

Commit

Permalink
clean up after gha worked and try warp build cache
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Nov 11, 2024
1 parent c3ef292 commit 0eedb44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
35 changes: 7 additions & 28 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,19 @@ jobs:
# https://docs.warpbuild.com/cache/docker-layer-caching#step-1-set-up-docker-buildx-action
driver-opts: |
network=host
# this will be used to generate cache key,
# so if dev-tools dockerfile or docker/Dockerfile in restate repo or cargo.lock change
# old cache will be invalidated and new cache will be created
- name: Download dev-tools Dockerfile
run: curl -L -o external.Dockerfile https://github.com/restatedev/dev-tools/raw/main/docker/Dockerfile

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile', '**/Cargo.lock', 'external.Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Cache sccache
uses: actions/cache@v4
with:
path: ~/.cache/sccache
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: |
{
"~/.cache/sccache": "~/.cache/sccache"
"sccache-cache": "/var/cache/sccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

Expand Down Expand Up @@ -147,8 +134,8 @@ jobs:
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
RESTATE_FEATURES=${{ inputs.features || '' }}
SCCACHE_DIR=~/.cache/sccache
cache-from: type=gha
cache-to: type=gha,mode=max
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 }}
Expand Down Expand Up @@ -183,14 +170,6 @@ jobs:
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
RESTATE_FEATURES=${{ inputs.features || '' }}
SCCACHE_DIR=/sccache-cache
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- # Temp fix for growing cache size
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-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

12 changes: 6 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ ARG SCCACHE_SERVER_PORT
ARG TARGETARCH

ENV RUSTC_WRAPPER=/usr/bin/sccache
ENV SCCACHE_DIR=~/.cache/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=''
# Mount the sccache directory as a cache to leverage sccache during build
# Caching layer if nothing has changed
RUN --mount=type=cache,target=~/.cache/sccache \
just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES chef-cook --release --bin restate-server

RUN just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES chef-cook --release --bin restate-server

COPY . .
# 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=~/.cache/sccache \
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
Expand Down

0 comments on commit 0eedb44

Please sign in to comment.