Skip to content

Commit 9f3c865

Browse files
tgross35Amanieu
authored andcommitted
Enable cache for Docker images
1 parent 9b066b6 commit 9f3c865

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.github/workflows/main.yml

+21
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ jobs:
108108
- uses: Swatinem/rust-cache@v2
109109
with:
110110
key: ${{ matrix.target }}
111+
- name: Cache Docker layers
112+
uses: actions/cache@v2
113+
if: matrix.os == 'ubuntu-latest'
114+
with:
115+
path: /tmp/.buildx-cache
116+
key: ${{ matrix.target }}-buildx-${{ github.sha }}
117+
restore-keys: ${{ matrix.target }}-buildx-
118+
111119
- name: Download compiler-rt reference sources
112120
run: |
113121
curl -L -o code.tar.gz https://github.com/rust-lang/llvm-project/archive/rustc/18.0-2024-02-13.tar.gz
@@ -123,10 +131,23 @@ jobs:
123131
NO_STD: ${{ matrix.no_std }}
124132
TEST_VERBATIM: ${{ matrix.test_verbatim }}
125133

134+
# Configure buildx to use Docker layer caching
135+
- uses: docker/setup-buildx-action@v3
136+
if: matrix.os == 'ubuntu-latest'
137+
126138
# Otherwise we use our docker containers to run builds
127139
- run: cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
128140
if: matrix.os == 'ubuntu-latest'
129141

142+
# Workaround to keep Docker cache smaller
143+
# https://github.com/docker/build-push-action/issues/252
144+
# https://github.com/moby/buildkit/issues/1896
145+
- name: Move Docker cache
146+
if: matrix.os == 'ubuntu-latest'
147+
run: |
148+
rm -rf /tmp/.buildx-cache
149+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
150+
130151
rustfmt:
131152
name: Rustfmt
132153
runs-on: ubuntu-latest

ci/run-docker.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ run() {
4141
export RUST_COMPILER_RT_ROOT=./compiler-rt
4242
fi
4343

44-
docker build \
44+
if [ "$GITHUB_ACTIONS" = "true" ]; then
45+
# Enable Docker image caching on GHA
46+
47+
buildx="buildx"
48+
build_args=(
49+
"--cache-from" "type=local,src=/tmp/.buildx-cache"
50+
"--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
51+
"${build_args[@]:-}"
52+
"--load"
53+
)
54+
fi
55+
56+
docker "${buildx:-}" build \
4557
-t "builtins-$target" \
4658
${build_args[@]:-} \
4759
"ci/docker/$target"

0 commit comments

Comments
 (0)