Skip to content

Commit dcf31bb

Browse files
authored
Unrolled build for rust-lang#124663
Rollup merge of rust-lang#124663 - Kobzol:docker-local-download, r=Mark-Simulacrum Enable reusing CI Docker cache when running CI images locally When running a CI image locally, e.g. using `DEPLOY=1 src/ci/docker/run.sh dist-x86_64-linux`, it can take a long time until the Docker image is built, which is annoying. Since we now use proper Docker caching on CI, it should be possible to just `docker pull` the prebuilt image to reuse the cache. We didn't want to do this on CI, since our caching key isn't perfect and it's possible that we can miss some changes, but I think that for local usage it is fine (we could introduce some env. var. to force disable the image download, if needed). r? `@Mark-Simulacrum`
2 parents d568423 + 02f4ef7 commit dcf31bb

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

Diff for: src/ci/docker/run.sh

+39-35
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,35 @@ fi
5050
CACHE_DOMAIN="${CACHE_DOMAIN:-ci-caches.rust-lang.org}"
5151

5252
if [ -f "$docker_dir/$image/Dockerfile" ]; then
53-
if isCI; then
54-
hash_key=/tmp/.docker-hash-key.txt
55-
rm -f "${hash_key}"
56-
echo $image >> $hash_key
57-
58-
cat "$docker_dir/$image/Dockerfile" >> $hash_key
59-
# Look for all source files involves in the COPY command
60-
copied_files=/tmp/.docker-copied-files.txt
61-
rm -f "$copied_files"
62-
for i in $(sed -n -e '/^COPY --from=/! s/^COPY \(.*\) .*$/\1/p' \
63-
"$docker_dir/$image/Dockerfile"); do
64-
# List the file names
65-
find "$script_dir/$i" -type f >> $copied_files
66-
done
67-
# Sort the file names and cat the content into the hash key
68-
sort $copied_files | xargs cat >> $hash_key
69-
70-
# Include the architecture in the hash key, since our Linux CI does not
71-
# only run in x86_64 machines.
72-
uname -m >> $hash_key
73-
74-
docker --version >> $hash_key
75-
76-
# Include cache version. Can be used to manually bust the Docker cache.
77-
echo "2" >> $hash_key
78-
79-
echo "Image input"
80-
cat $hash_key
81-
82-
cksum=$(sha512sum $hash_key | \
83-
awk '{print $1}')
84-
echo "Image input checksum ${cksum}"
85-
fi
53+
hash_key=/tmp/.docker-hash-key.txt
54+
rm -f "${hash_key}"
55+
echo $image >> $hash_key
56+
57+
cat "$docker_dir/$image/Dockerfile" >> $hash_key
58+
# Look for all source files involves in the COPY command
59+
copied_files=/tmp/.docker-copied-files.txt
60+
rm -f "$copied_files"
61+
for i in $(sed -n -e '/^COPY --from=/! s/^COPY \(.*\) .*$/\1/p' \
62+
"$docker_dir/$image/Dockerfile"); do
63+
# List the file names
64+
find "$script_dir/$i" -type f >> $copied_files
65+
done
66+
# Sort the file names and cat the content into the hash key
67+
sort $copied_files | xargs cat >> $hash_key
68+
69+
# Include the architecture in the hash key, since our Linux CI does not
70+
# only run in x86_64 machines.
71+
uname -m >> $hash_key
72+
73+
# Include cache version. Can be used to manually bust the Docker cache.
74+
echo "2" >> $hash_key
75+
76+
echo "Image input"
77+
cat $hash_key
78+
79+
cksum=$(sha512sum $hash_key | \
80+
awk '{print $1}')
81+
echo "Image input checksum ${cksum}"
8682

8783
dockerfile="$docker_dir/$image/Dockerfile"
8884
if [ -x /usr/bin/cygpath ]; then
@@ -105,10 +101,18 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
105101
# It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache
106102
CACHE_IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci-cache:${cksum}
107103

108-
# 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.
109107
if ! isCI;
110108
then
111-
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
112116
# On PR CI jobs, we don't have permissions to write to the registry cache,
113117
# but we can still read from it.
114118
elif [[ "$PR_CI_JOB" == "1" ]];

0 commit comments

Comments
 (0)