@@ -74,25 +74,6 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
74
74
75
75
cksum=$( sha512sum $hash_key | \
76
76
awk ' {print $1}' )
77
-
78
- url=" https://$CACHE_DOMAIN /docker/$cksum "
79
-
80
- echo " Attempting to download $url "
81
- rm -f /tmp/rustci_docker_cache
82
- set +e
83
- retry curl --max-time 600 -y 30 -Y 10 --connect-timeout 30 -f -L -C - \
84
- -o /tmp/rustci_docker_cache " $url "
85
-
86
- docker_archive_hash=$( sha512sum /tmp/rustci_docker_cache | awk ' {print $1}' )
87
- echo " Downloaded archive hash: ${docker_archive_hash} "
88
-
89
- echo " Loading images into docker"
90
- # docker load sometimes hangs in the CI, so time out after 10 minutes with TERM,
91
- # KILL after 12 minutes
92
- loaded_images=$( /usr/bin/timeout -k 720 600 docker load -i /tmp/rustci_docker_cache \
93
- | sed ' s/.* sha/sha/' )
94
- set -e
95
- printf " Downloaded containers:\n$loaded_images \n"
96
77
fi
97
78
98
79
dockerfile=" $docker_dir /$image /Dockerfile"
@@ -103,44 +84,48 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
103
84
context=" $script_dir "
104
85
fi
105
86
echo " ::group::Building docker image for $image "
106
-
107
- # As of August 2023, Github Actions have updated Docker to 23.X,
108
- # which uses the BuildKit by default. It currently throws aways all
109
- # intermediate layers, which breaks our usage of S3 layer caching.
110
- # Therefore we opt-in to the old build backend for now.
111
- export DOCKER_BUILDKIT=0
112
- retry docker \
113
- build \
114
- --rm \
115
- -t rust-ci \
116
- -f " $dockerfile " \
117
- " $context "
87
+ echo " Image checksum ${cksum} "
88
+
89
+ # On PR jobs, we don't have permissions to write to the cache, so we should not use
90
+ # `docker login` nor caching.
91
+ if [ " $PR_CI_JOB " -eq 1 ]
92
+ then
93
+ docker pull ghcr.io/rust-lang-ci/rust-ci:e933e07d88a3a99bf4260cfb60899ada91f8df72a6588179fcf65ebe7ce824675eb8f2c985515ca3c51f2d0f5c006cb1d9e2fa66af562cdc91537385af559d59
94
+ # docker buildx create --use --driver docker-container
95
+ # retry docker buildx build --rm -t rust-ci \
96
+ # --output=type=docker \
97
+ # --cache-from type=registry,ref=ghcr.io/rust-lang-ci/rust-ci:${cksum} \
98
+ # -f "$dockerfile" "$context"
99
+ else
100
+ docker pull ghcr.io/rust-lang-ci/rust-ci:e933e07d88a3a99bf4260cfb60899ada91f8df72a6588179fcf65ebe7ce824675eb8f2c985515ca3c51f2d0f5c006cb1d9e2fa66af562cdc91537385af559d59
101
+
102
+ docker buildx create --use --driver docker-container
103
+
104
+ # Login to Docker registry
105
+ echo ${DOCKER_TOKEN} | docker login ghcr.io --username rust-lang-ci --password-stdin
106
+
107
+ dest=" type=registry,ref=ghcr.io/rust-lang-ci/rust-ci:${cksum} ,compression=zstd,mode=max"
108
+
109
+ retry docker \
110
+ buildx \
111
+ build \
112
+ --rm \
113
+ -t rust-ci \
114
+ -f " $dockerfile " \
115
+ --cache-from type=registry,ref=ghcr.io/rust-lang-ci/rust-ci:${cksum} \
116
+ --cache-to ${dest} \
117
+ --output=type=docker \
118
+ " $context "
119
+ docker manifest inspect rust-ci
120
+ fi
118
121
echo " ::endgroup::"
119
122
120
123
if [ " $CI " != " " ]; then
121
- s3url=" s3://$SCCACHE_BUCKET /docker/$cksum "
122
- upload=" aws s3 cp - $s3url "
123
124
digest=$( docker inspect rust-ci --format ' {{.Id}}' )
124
- echo " Built container $digest "
125
- if ! grep -q " $digest " <( echo " $loaded_images " ) ; then
126
- echo " Uploading finished image $digest to $url "
127
- set +e
128
- # Print image history for easier debugging of layer SHAs
129
- docker history rust-ci
130
- docker history -q rust-ci | \
131
- grep -v missing | \
132
- xargs docker save | \
133
- gzip | \
134
- $upload
135
- set -e
136
- else
137
- echo " Looks like docker image is the same as before, not uploading"
138
- fi
139
125
# Record the container image for reuse, e.g. by rustup.rs builds
140
126
info=" $dist /image-$image .txt"
141
127
mkdir -p " $dist "
142
- echo " $url " > " $info "
143
- echo " $digest " >> " $info "
128
+ echo " ${cksum} " > " $info "
144
129
cat " $info "
145
130
fi
146
131
elif [ -f " $docker_dir /disabled/$image /Dockerfile" ]; then
0 commit comments