Skip to content

Commit 02f4ef7

Browse files
committedMay 3, 2024··
Allow reusing CI Docker cache when running CI images locally
1 parent 0372065 commit 02f4ef7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎src/ci/docker/run.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,18 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
101101
# It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache
102102
CACHE_IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci-cache:${cksum}
103103

104-
# On non-CI jobs, we don't do any caching.
104+
# On non-CI jobs, we try to download a pre-built image from the rust-lang-ci
105+
# ghcr.io registry. If it is not possible, we fall back to building the image
106+
# locally.
105107
if ! isCI;
106108
then
107-
retry docker build --rm -t rust-ci -f "$dockerfile" "$context"
109+
if docker pull "${IMAGE_TAG}"; then
110+
echo "Downloaded Docker image from CI"
111+
docker tag "${IMAGE_TAG}" rust-ci
112+
else
113+
echo "Building local Docker image"
114+
retry docker build --rm -t rust-ci -f "$dockerfile" "$context"
115+
fi
108116
# On PR CI jobs, we don't have permissions to write to the registry cache,
109117
# but we can still read from it.
110118
elif [[ "$PR_CI_JOB" == "1" ]];

0 commit comments

Comments
 (0)
Please sign in to comment.