@@ -105,6 +105,23 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
105
105
# It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache
106
106
CACHE_IMAGE_TAG=${REGISTRY} /${REGISTRY_USERNAME} /rust-ci-cache:${cksum}
107
107
108
+ # Docker build arguments.
109
+ build_args=(
110
+ " build"
111
+ " --rm"
112
+ " -t" " rust-ci"
113
+ " -f" " $dockerfile "
114
+ " $context "
115
+ )
116
+
117
+ # If the environment variable DOCKER_SCRIPT is defined,
118
+ # set the build argument SCRIPT_ARG to DOCKER_SCRIPT.
119
+ # In this way, we run the script defined in CI,
120
+ # instead of the one defined in the Dockerfile.
121
+ if [ -n " ${DOCKER_SCRIPT+x} " ]; then
122
+ build_args+=(" --build-arg" " SCRIPT_ARG=${DOCKER_SCRIPT} " )
123
+ fi
124
+
108
125
# On non-CI jobs, we try to download a pre-built image from the rust-lang-ci
109
126
# ghcr.io registry. If it is not possible, we fall back to building the image
110
127
# locally.
@@ -115,7 +132,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
115
132
docker tag " ${IMAGE_TAG} " rust-ci
116
133
else
117
134
echo " Building local Docker image"
118
- retry docker build --rm -t rust-ci -f " $dockerfile " " $context "
135
+ retry docker " ${build_args[@]} "
119
136
fi
120
137
# On PR CI jobs, we don't have permissions to write to the registry cache,
121
138
# but we can still read from it.
@@ -127,13 +144,9 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
127
144
# Build the image using registry caching backend
128
145
retry docker \
129
146
buildx \
130
- build \
131
- --rm \
132
- -t rust-ci \
133
- -f " $dockerfile " \
147
+ " ${build_args[@]} " \
134
148
--cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
135
- --output=type=docker \
136
- " $context "
149
+ --output=type=docker
137
150
# On auto/try builds, we can also write to the cache.
138
151
else
139
152
# Log into the Docker registry, so that we can read/write cache and the final image
@@ -147,14 +160,10 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
147
160
# Build the image using registry caching backend
148
161
retry docker \
149
162
buildx \
150
- build \
151
- --rm \
152
- -t rust-ci \
153
- -f " $dockerfile " \
163
+ " ${build_args[@]} " \
154
164
--cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
155
165
--cache-to type=registry,ref=${CACHE_IMAGE_TAG} ,compression=zstd \
156
- --output=type=docker \
157
- " $context "
166
+ --output=type=docker
158
167
159
168
# Print images for debugging purposes
160
169
docker images
0 commit comments