Skip to content

Commit df2a400

Browse files
committed
fix script
1 parent 0ae3897 commit df2a400

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/ci/docker/run.sh

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ 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="build --rm -t rust-ci -f \"$dockerfile\" \"$context\""
110+
111+
# If the environment variable SCRIPT is defined,
112+
# set the build argument SCRIPT_ARG to SCRIPT.
113+
# In this way, we run the SCRIPT defined in CI,
114+
# instead of the one defined in the Dockerfile.
115+
if [ -n "${SCRIPT+x}" ]; then
116+
build_args="${build_args} --build-arg SCRIPT_ARG=${SCRIPT}"
117+
fi
118+
108119
# On non-CI jobs, we try to download a pre-built image from the rust-lang-ci
109120
# ghcr.io registry. If it is not possible, we fall back to building the image
110121
# locally.
@@ -115,7 +126,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
115126
docker tag "${IMAGE_TAG}" rust-ci
116127
else
117128
echo "Building local Docker image"
118-
retry docker build --rm -t rust-ci -f "$dockerfile" "$context"
129+
retry docker ${build_args}
119130
fi
120131
# On PR CI jobs, we don't have permissions to write to the registry cache,
121132
# but we can still read from it.
@@ -127,13 +138,9 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
127138
# Build the image using registry caching backend
128139
retry docker \
129140
buildx \
130-
build \
131-
--rm \
132-
-t rust-ci \
133-
-f "$dockerfile" \
141+
"${build_args}" \
134142
--cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
135-
--output=type=docker \
136-
"$context"
143+
--output=type=docker
137144
# On auto/try builds, we can also write to the cache.
138145
else
139146
# Log into the Docker registry, so that we can read/write cache and the final image
@@ -147,14 +154,10 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
147154
# Build the image using registry caching backend
148155
retry docker \
149156
buildx \
150-
build \
151-
--rm \
152-
-t rust-ci \
153-
-f "$dockerfile" \
157+
"${build_args}" \
154158
--cache-from type=registry,ref=${CACHE_IMAGE_TAG} \
155159
--cache-to type=registry,ref=${CACHE_IMAGE_TAG},compression=zstd \
156-
--output=type=docker \
157-
"$context"
160+
--output=type=docker
158161

159162
# Print images for debugging purposes
160163
docker images
@@ -300,14 +303,6 @@ else
300303
command=(/checkout/src/ci/run.sh)
301304
fi
302305

303-
# If the environment variable SCRIPT is defined,
304-
# set the build argument SCRIPT_ARG to SCRIPT.
305-
# In this way, we run the SCRIPT defined in CI,
306-
# instead of the one defined in the Dockerfile.
307-
if [ -n "${SCRIPT+x}" ]; then
308-
args="$args --build-arg SCRIPT_ARG=${SCRIPT}"
309-
fi
310-
311306
if isCI; then
312307
# Get some needed information for $BASE_COMMIT
313308
#

0 commit comments

Comments
 (0)