@@ -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
@@ -153,6 +155,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
153155 --output=type=docker
154156 # On auto/try builds, we can also write to the cache.
155157 else
158+ echo " Logging into the Docker registry"
156159 # Log into the Docker registry, so that we can read/write cache and the final image
157160 echo ${DOCKER_TOKEN} | docker login ${REGISTRY} \
158161 --username ${REGISTRY_USERNAME} \
@@ -163,6 +166,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
163166 docker buildx create --use --driver docker-container \
164167 --driver-opt image=${GHCR_BUILDKIT_IMAGE}
165168
169+ echo " Building Docker image with cache"
166170 # Build the image using registry caching backend
167171 retry docker \
168172 buildx \
@@ -171,11 +175,13 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
171175 --cache-to type=registry,ref=${CACHE_IMAGE_TAG} ,compression=zstd \
172176 --output=type=docker
173177
178+ echo " Docker image built"
174179 # Print images for debugging purposes
175180 docker images
176181
177182 # Tag the built image and push it to the registry
178183 docker tag rust-ci " ${IMAGE_TAG} "
184+ echo " Pushing Docker image to the registry"
179185 docker push " ${IMAGE_TAG} "
180186
181187 # Record the container registry tag/url for reuse, e.g. by rustup.rs builds
227233 exit 1
228234fi
229235
236+ echo " Creating directories"
230237mkdir -p $HOME /.cargo
231238mkdir -p $objdir /tmp
232239mkdir -p $objdir /cores
@@ -282,24 +289,32 @@ args="$args --privileged"
282289# `LOCAL_USER_ID` (recognized in `src/ci/run.sh`) to ensure that files are all
283290# read/written as the same user as the bare-metal user.
284291if [ -f /.dockerenv ]; then
285- docker create -v /checkout --name checkout alpine:3.4 /bin/true
292+ echo " Dockerenv detected. We are in docker-in-docker scenario."
293+ docker create -v /checkout --name checkout ghcr.io/marcoieni/alpine:3.4 /bin/true
286294 docker cp . checkout:/checkout
287295 args=" $args --volumes-from checkout"
288296else
289297 args=" $args --volume $root_dir :/checkout$SRC_MOUNT_OPTION "
290298 args=" $args --volume $objdir :/checkout/obj"
291299 args=" $args --volume $HOME /.cargo:/cargo"
292300 args=" $args --volume /tmp/toolstate:/tmp/toolstate"
301+ fi
293302
294- id=$( id -u)
295- if [[ " $id " != 0 && " $( docker version) " =~ Podman ]]; then
296- # Rootless podman creates a separate user namespace, where an inner
297- # LOCAL_USER_ID will map to a different subuid range on the host.
298- # The "keep-id" mode maps the current UID directly into the container.
299- args=" $args --env NO_CHANGE_USER=1 --userns=keep-id"
300- else
301- args=" $args --env LOCAL_USER_ID=$id "
302- fi
303+ id=$( id -u)
304+ if [[ " $id " != 0 && " $( docker version) " =~ Podman ]]; then
305+ # Rootless podman creates a separate user namespace, where an inner
306+ # LOCAL_USER_ID will map to a different subuid range on the host.
307+ # The "keep-id" mode maps the current UID directly into the container.
308+ echo " Running in rootless podman"
309+ args=" $args --env NO_CHANGE_USER=1 --userns=keep-id"
310+ elif [[ " $id " != 0 ]]; then
311+ echo " Running in docker as non-root"
312+ args=" $args --env LOCAL_USER_ID=$id "
313+ else
314+ echo " Running in docker as root. Using id 1001."
315+ # If we're running as root, we don't want to run the container as root,
316+ # so we set id `1001` instead of `0`.
317+ args=" $args --env LOCAL_USER_ID=1001"
303318fi
304319
305320if [ " $dev " = " 1" ]
0 commit comments