Skip to content

Commit 85c97ed

Browse files
authored
CI enhancement: docker workflow speedup (#2232)
* bump actions show sccache stats update cache from/to config try to optimize dockerfile fix dockerfile fix chef command try to use sccache directory of the gh runner enable debug logs for sccache use build context to mount runner sccache to container sccache fix typo update sccache dir update target destination test test test test test test debug revert dockerfile changes try to cache manually change cache dir Trigger pipeline: test caching remove sccache dir Trigger pipeline: test caching remove uneeded args remove mozilla-actions/sccache-action, it doesn't work anyway Trigger pipeline: test caching docker layers manually set a better cache invalidation policy use cargo.lock for cache key better than toml files Trigger pipeline: local cache should work fix growing cache size issue Trigger pipeline: test after fixing growing cache size try to inject sccache into docker builds change key for docker caching debug sccache add sccache just command debug sccache env vars update rust wrapper env var remove sccache debug logs Trigger pipeline: test latest state include dev-tools dockerfile in creating cache key use cache map Trigger pipeline: test latest state try gha cache after letting gha set env vars automatically Trigger pipeline: test gha cache clean up after gha worked and try warp build cache Trigger pipeline: test gha warpbuild cache * debug sccache * remove cache mount from dockerfile * clean up commented actions * restore sccache mounting * bump mozilla-actions/sccache-action * comply to the convention of dockerfile ending with a newline * remove excessive build arg
1 parent 73fa9df commit 85c97ed

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

.github/workflows/binaries.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
run: rustup target add aarch64-apple-darwin
7777

7878
- name: Run sccache-cache
79-
uses: mozilla-actions/[email protected].4
79+
uses: mozilla-actions/[email protected].6
8080

8181
- name: Cache Rust
8282
uses: Swatinem/rust-cache@v2
@@ -194,7 +194,7 @@ jobs:
194194
EOF
195195
196196
- name: Build and push multiplatform image
197-
uses: docker/build-push-action@v5
197+
uses: docker/build-push-action@v6
198198
with:
199199
context: .
200200
push: true

.github/workflows/docker.yml

+23-16
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,22 @@ jobs:
6767
# https://docs.warpbuild.com/cache/docker-layer-caching#step-1-set-up-docker-buildx-action
6868
driver-opts: |
6969
network=host
70+
71+
- name: Cache sccache
72+
uses: actions/cache@v4
73+
with:
74+
path: sccache-cache
75+
key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }}
7076

71-
- name: Run sccache-cache
72-
uses: mozilla-actions/[email protected]
73-
77+
- name: Inject sccache-cache into Docker
78+
uses: reproducible-containers/buildkit-cache-dance@v3
79+
with:
80+
cache-map: |
81+
{
82+
"sccache-cache": "/var/cache/sccache"
83+
}
84+
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
85+
7486
- name: Log into GitHub container registry
7587
uses: docker/login-action@v3
7688
with:
@@ -107,7 +119,7 @@ jobs:
107119
108120
- name: Build${{inputs.uploadImageAsTarball != true && ' and push ' || ' '}}Docker image
109121
id: build
110-
uses: docker/build-push-action@v5
122+
uses: docker/build-push-action@v6
111123
with:
112124
context: .
113125
file: "docker/Dockerfile"
@@ -119,13 +131,10 @@ jobs:
119131
network: host
120132
build-args: |
121133
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
122-
ACTIONS_CACHE_URL=http://127.0.0.1:49160/
123-
ACTIONS_RUNTIME_TOKEN
124-
SCCACHE_GHA_ENABLED=true
125134
RESTATE_FEATURES=${{ inputs.features || '' }}
126-
cache-from: type=gha,scope=${{ github.workflow }},url=http://127.0.0.1:49160/
127-
cache-to: type=gha,mode=max,scope=${{ github.workflow }},url=http://127.0.0.1:49160/
128-
135+
cache-from: type=gha,url=http://127.0.0.1:49160/
136+
cache-to: type=gha,url=http://127.0.0.1:49160/,mode=max
137+
129138
- name: Save docker image as tar
130139
if: ${{ inputs.uploadImageAsTarball }}
131140
run: |
@@ -144,7 +153,7 @@ jobs:
144153
# This won't actually build again, it'll just use cache
145154
- name: Push Docker image
146155
if: ${{ inputs.uploadImageAsTarball && github.ref == 'refs/heads/main' }}
147-
uses: docker/build-push-action@v5
156+
uses: docker/build-push-action@v6
148157
with:
149158
context: .
150159
file: "docker/Dockerfile"
@@ -157,9 +166,7 @@ jobs:
157166
network: host
158167
build-args: |
159168
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
160-
ACTIONS_CACHE_URL=http://127.0.0.1:49160/
161-
ACTIONS_RUNTIME_TOKEN
162-
SCCACHE_GHA_ENABLED=true
163169
RESTATE_FEATURES=${{ inputs.features || '' }}
164-
cache-from: type=gha,scope=${{ github.workflow }},url=http://127.0.0.1:49160/
165-
cache-to: type=gha,mode=max,scope=${{ github.workflow }},url=http://127.0.0.1:49160/
170+
cache-from: type=gha,url=http://127.0.0.1:49160/
171+
cache-to: type=gha,url=http://127.0.0.1:49160/,mode=max
172+

docker/Dockerfile

+12-7
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@ ARG SCCACHE_SERVER_PORT=4227
2626
FROM base-$TARGETARCH AS builder
2727
ARG SCCACHE_SERVER_PORT
2828
ARG TARGETARCH
29-
# https://github.com/mozilla/sccache/blob/main/docs/GHA.md
30-
ARG ACTIONS_CACHE_URL=''
31-
ARG ACTIONS_RUNTIME_TOKEN=''
32-
ARG SCCACHE_GHA_ENABLED=''
29+
30+
ENV RUSTC_WRAPPER=/usr/bin/sccache
31+
ENV SCCACHE_DIR=/var/cache/sccache
32+
3333
# Overrides the behaviour of the release profile re including debug symbols, which in our repo is not to include them.
3434
# Should be set to 'false' or 'true'. See https://doc.rust-lang.org/cargo/reference/environment-variables.html
3535
ARG CARGO_PROFILE_RELEASE_DEBUG=false
3636
ARG RESTATE_FEATURES=''
37-
# Caching layer if nothing has changed
38-
# Only build restate binary to avoid compiling unneeded crates
37+
3938
RUN just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES chef-cook --release --bin restate-server
39+
4040
COPY . .
41-
RUN just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES build --release --bin restate-server && \
41+
42+
# Mount the sccache directory as a cache to leverage sccache during build
43+
# Caching layer if nothing has changed
44+
# Use sccache during the main build
45+
RUN --mount=type=cache,target=/var/cache/sccache \
46+
just arch=$TARGETARCH libc=gnu features=$RESTATE_FEATURES build --release --bin restate-server && \
4247
just notice-file && \
4348
mv target/$(just arch=$TARGETARCH libc=gnu print-target)/release/restate-server target/restate-server
4449

0 commit comments

Comments
 (0)