Skip to content

Commit cf97627

Browse files
committed
Attempt to cache docker images in CI
Linux package servers have been particularly flaky today so I've re-investigated how to maybe cache everything. The idea here is that we use the "officially recommended" way of caching builds of docker images on github actions, notably using the github actions cache. The way this is configured is that some extra steps happen on github which populate the github actions cache and local docker daemon such that when the actual build happens, totally independently of these github actions steps, it just so happens to get cache hits. This is done to ensure that if we make a mistake here it doesn't result in stale builds, just slower builds. The overall hope here is that by using the github actions cache for docker images we can hit package installation less than we currently do. The hope is that all the images fit within the github actions cache. I think they do but it's pretty noisy and each build generates new entries so I'm not entirely sure what's happening. Local testing shows that reruns do indeed proceed faster and don't hit `apt-get` for example, though. This doesn't entirely insulate us from issues with `apt-get` because runs will still use `apt-get` externally from docker, such as just installing a few extra packages. I don't know how to make those more robust, but hopefully we can at least reduce some flakiness by caching some things.
1 parent d5f1b97 commit cf97627

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

.github/workflows/main.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,44 @@ jobs:
12971297
with:
12981298
submodules: true
12991299

1300+
# Attempt to speed up building of docker images for Linux-based binaries by
1301+
# using docker's recommended way of building/caching with github actions.
1302+
# Notably this caches layers to github actions which enables subsequent
1303+
# reuse in future runs. The goal here is to make this step faster while
1304+
# additionally reducing network flakiness since the github actions cache
1305+
# generally works better than upstream package servers, or at least in
1306+
# theory.
1307+
#
1308+
# The way that this is designed is to build the image with docker-related
1309+
# github actions here primarily. This populates the github actions cache
1310+
# but also the local docker daemon cache too. Subsequently when the actual
1311+
# build script runs it'll attempt to rebuild the image and it should get a
1312+
# bunch of cache hits from here. This way we can configure the caching here
1313+
# within github actions without impacting the functionality of the script
1314+
# itself and continue enabling it to run locally.
1315+
- name: Set up Docker Buildx
1316+
uses: docker/setup-buildx-action@v4
1317+
if: ${{ matrix.env.DOCKER_IMAGE }}
1318+
- name: Disable some docker things that are on-by-default
1319+
run: |
1320+
echo DOCKER_BUILD_CHECKS_ANNOTATIONS=false >> $GITHUB_ENV
1321+
echo DOCKER_BUILD_SUMMARY=false >> $GITHUB_ENV
1322+
echo DOCKER_BUILD_RECORD_UPLOAD=false >> $GITHUB_ENV
1323+
if: ${{ matrix.env.DOCKER_IMAGE }}
1324+
- name: Build docker image
1325+
if: ${{ matrix.env.DOCKER_IMAGE }}
1326+
uses: docker/build-push-action@v7
1327+
with:
1328+
context: ci/docker
1329+
file: ${{ matrix.env.DOCKER_IMAGE }}
1330+
tags: build-image
1331+
cache-from: type=gha
1332+
cache-to: type=gha,mode=max
1333+
outputs: type=docker
1334+
13001335
- uses: ./.github/actions/install-ninja
1336+
if: '${{ !matrix.env.DOCKER_IMAGE }}'
1337+
13011338
- uses: ./.github/actions/install-rust
13021339
with:
13031340
toolchain: ${{ matrix.rust }}

ci/build-release-artifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ wrapper=""
2020
# have precise glibc requirements for Linux platforms for example.
2121
if [ "$DOCKER_IMAGE" != "" ]; then
2222
if [ -f "$DOCKER_IMAGE" ]; then
23-
docker build --tag build-image --file $DOCKER_IMAGE ci/docker
23+
docker buildx build -o type=docker --tag build-image --file $DOCKER_IMAGE ci/docker
2424
DOCKER_IMAGE=build-image
2525
fi
2626

0 commit comments

Comments
 (0)