@@ -105,6 +105,23 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
105105 # It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache
106106 CACHE_IMAGE_TAG=${REGISTRY} /${REGISTRY_USERNAME} /rust-ci-cache:${cksum}
107107
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+
108125 # On non-CI jobs, we try to download a pre-built image from the rust-lang-ci
109126 # ghcr.io registry. If it is not possible, we fall back to building the image
110127 # locally.
@@ -115,7 +132,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
115132 docker tag " ${IMAGE_TAG} " rust-ci
116133 else
117134 echo " Building local Docker image"
118- retry docker build --rm -t rust-ci -f " $dockerfile " " $context "
135+ retry docker " ${build_args[@]} "
119136 fi
120137 # On PR CI jobs, we don't have permissions to write to the registry cache,
121138 # but we can still read from it.
@@ -127,13 +144,9 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
127144 # Build the image using registry caching backend
128145 retry docker \
129146 buildx \
130- build \
131- --rm \
132- -t rust-ci \
133- -f " $dockerfile " \
147+ " ${build_args[@]} " \
134148 --cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
135- --output=type=docker \
136- " $context "
149+ --output=type=docker
137150 # On auto/try builds, we can also write to the cache.
138151 else
139152 # 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
147160 # Build the image using registry caching backend
148161 retry docker \
149162 buildx \
150- build \
151- --rm \
152- -t rust-ci \
153- -f " $dockerfile " \
163+ " ${build_args[@]} " \
154164 --cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
155165 --cache-to type=registry,ref=${CACHE_IMAGE_TAG} ,compression=zstd \
156- --output=type=docker \
157- " $context "
166+ --output=type=docker
158167
159168 # Print images for debugging purposes
160169 docker images
0 commit comments