File tree 1 file changed +26
-3
lines changed
1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,34 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
92
92
# Print docker version
93
93
docker --version
94
94
95
- # On non-CI or PR jobs, we don't have permissions to write to the registry cache, so we should
96
- # not use `docker login` nor caching.
97
- if [[ " $CI " == " " ]] || [[ " $PR_CI_JOB " == " 1" ]];
95
+ # On non-CI jobs, we don't do any caching.
96
+ if [[ " $CI " == " " ]];
98
97
then
99
98
retry docker build --rm -t rust-ci -f " $dockerfile " " $context "
99
+ # On PR CI jobs, we don't have permissions to write to the registry cache, but we can still read from it.
100
+ elif [[ " $PR_CI_JOB " == " 1" ]];
101
+ then
102
+ REGISTRY=ghcr.io
103
+ # Most probably rust-lang-ci, but in general the owner of the repository where CI runs
104
+ REGISTRY_USERNAME=rust-lang-ci
105
+ # Tag used to cache the Docker build
106
+ # It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache
107
+ CACHE_IMAGE_TAG=${REGISTRY} /${REGISTRY_USERNAME} /rust-ci-cache:${cksum}
108
+
109
+ # Enable a new Docker driver so that --cache-from/to works with a registry backend
110
+ docker buildx create --use --driver docker-container
111
+
112
+ # Build the image using registry caching backend
113
+ retry docker \
114
+ buildx \
115
+ build \
116
+ --rm \
117
+ -t rust-ci \
118
+ -f " $dockerfile " \
119
+ --cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
120
+ --output=type=docker \
121
+ " $context "
122
+ # On auto/try builds, we can also write to it
100
123
else
101
124
REGISTRY=ghcr.io
102
125
# Most probably rust-lang-ci, but in general the owner of the repository where CI runs
You can’t perform that action at this time.
0 commit comments