@@ -39,6 +39,7 @@ root_dir="`dirname $src_dir`"
3939source " $ci_dir /shared.sh"
4040
4141if isCI; then
42+ echo " CI detected"
4243 objdir=$root_dir /obj
4344else
4445 objdir=$root_dir /obj/$image
5354CACHE_DOMAIN=" ${CACHE_DOMAIN:- ci-caches.rust-lang.org} "
5455
5556if [ -f " $docker_dir /$image /Dockerfile" ]; then
57+ echo " Dockerfile found for $image "
5658 hash_key=/tmp/.docker-hash-key.txt
5759 rm -f " ${hash_key} "
5860 echo $image >> $hash_key
@@ -140,7 +142,8 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
140142 elif [[ " $PR_CI_JOB " == " 1" ]];
141143 then
142144 # Enable a new Docker driver so that --cache-from works with a registry backend
143- docker buildx create --use --driver docker-container
145+ docker buildx create --use --driver docker-container \
146+ --driver-opt image=ghcr.io/marcoieni/buildkit:buildx-stable-1
144147
145148 # Build the image using registry caching backend
146149 retry docker \
@@ -150,14 +153,17 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
150153 --output=type=docker
151154 # On auto/try builds, we can also write to the cache.
152155 else
156+ echo " Logging into the Docker registry"
153157 # Log into the Docker registry, so that we can read/write cache and the final image
154158 echo ${DOCKER_TOKEN} | docker login ${REGISTRY} \
155159 --username ${REGISTRY_USERNAME} \
156160 --password-stdin
157161
158162 # Enable a new Docker driver so that --cache-from/to works with a registry backend
159- docker buildx create --use --driver docker-container
163+ docker buildx create --use --driver docker-container \
164+ --driver-opt image=ghcr.io/marcoieni/buildkit:buildx-stable-1
160165
166+ echo " Building Docker image with cache"
161167 # Build the image using registry caching backend
162168 retry docker \
163169 buildx \
@@ -166,11 +172,13 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
166172 --cache-to type=registry,ref=${CACHE_IMAGE_TAG} ,compression=zstd \
167173 --output=type=docker
168174
175+ echo " Docker image built"
169176 # Print images for debugging purposes
170177 docker images
171178
172179 # Tag the built image and push it to the registry
173180 docker tag rust-ci " ${IMAGE_TAG} "
181+ echo " Pushing Docker image to the registry"
174182 docker push " ${IMAGE_TAG} "
175183
176184 # Record the container registry tag/url for reuse, e.g. by rustup.rs builds
222230 exit 1
223231fi
224232
233+ echo " Creating directories"
225234mkdir -p $HOME /.cargo
226235mkdir -p $objdir /tmp
227236mkdir -p $objdir /cores
@@ -277,24 +286,32 @@ args="$args --privileged"
277286# `LOCAL_USER_ID` (recognized in `src/ci/run.sh`) to ensure that files are all
278287# read/written as the same user as the bare-metal user.
279288if [ -f /.dockerenv ]; then
280- docker create -v /checkout --name checkout alpine:3.4 /bin/true
289+ echo " Dockerenv detected. We are in docker-in-docker scenario."
290+ docker create -v /checkout --name checkout ghcr.io/marcoieni/alpine:3.4 /bin/true
281291 docker cp . checkout:/checkout
282292 args=" $args --volumes-from checkout"
283293else
284294 args=" $args --volume $root_dir :/checkout$SRC_MOUNT_OPTION "
285295 args=" $args --volume $objdir :/checkout/obj"
286296 args=" $args --volume $HOME /.cargo:/cargo"
287297 args=" $args --volume /tmp/toolstate:/tmp/toolstate"
298+ fi
288299
289- id=$( id -u)
290- if [[ " $id " != 0 && " $( docker version) " =~ Podman ]]; then
291- # Rootless podman creates a separate user namespace, where an inner
292- # LOCAL_USER_ID will map to a different subuid range on the host.
293- # The "keep-id" mode maps the current UID directly into the container.
294- args=" $args --env NO_CHANGE_USER=1 --userns=keep-id"
295- else
296- args=" $args --env LOCAL_USER_ID=$id "
297- fi
300+ id=$( id -u)
301+ if [[ " $id " != 0 && " $( docker version) " =~ Podman ]]; then
302+ # Rootless podman creates a separate user namespace, where an inner
303+ # LOCAL_USER_ID will map to a different subuid range on the host.
304+ # The "keep-id" mode maps the current UID directly into the container.
305+ echo " Running in rootless podman"
306+ args=" $args --env NO_CHANGE_USER=1 --userns=keep-id"
307+ elif [[ " $id " != 0 ]]; then
308+ echo " Running in docker as non-root"
309+ args=" $args --env LOCAL_USER_ID=$id "
310+ else
311+ echo " Running in docker as root. Using id 1001."
312+ # If we're running as root, we don't want to run the container as root,
313+ # so we set id `1001` instead of `0`.
314+ args=" $args --env LOCAL_USER_ID=1001"
298315fi
299316
300317if [ " $dev " = " 1" ]
0 commit comments