Skip to content

Commit a223f45

Browse files
committed
Auto merge of #133912 - MarcoIeni:test-codebuild-runner, r=<try>
[experiment] test code build runner try-job: x86_64-fuchsia
2 parents ebbe638 + 6c20ee4 commit a223f45

9 files changed

Lines changed: 142 additions & 16 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ jobs:
112112
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be
113113
if: matrix.free_disk
114114

115+
- name: free up more disk space
116+
if: matrix.free_disk
117+
run: |
118+
sudo apt purge -y --autoremove \
119+
'^java-*' \
120+
'groff' \
121+
'groff-base' \
122+
'^libllvm.*' \
123+
'^llvm.*' \
124+
'gcc' \
125+
'gcc-11' \
126+
'libicu-dev' \
127+
'^vim.*' \
128+
'python3-breezy' \
129+
&& sudo rm -rf /var/lib/apt/lists/*
130+
df -h /
131+
132+
- name: Show installed packages ordered by size
133+
run: dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr
134+
115135
# Rust Log Analyzer can't currently detect the PR number of a GitHub
116136
# Actions build on its own, so a hint in the log message is needed to
117137
# point it in the right direction.
@@ -174,6 +194,8 @@ jobs:
174194

175195
- name: enable ipv6 on Docker
176196
run: src/ci/scripts/enable-docker-ipv6.sh
197+
# Don't run on codebuild because systemctl is not available
198+
if: ${{ !contains(matrix.os, 'codebuild-ubuntu') }}
177199

178200
# Disable automatic line ending conversion (again). On Windows, when we're
179201
# installing dependencies, something switches the git configuration directory or

‎src/bootstrap/bootstrap.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,14 @@ def build_bootstrap(self):
10021002
env = os.environ.copy()
10031003
if "GITHUB_ACTIONS" in env:
10041004
print("::group::Building bootstrap")
1005+
print("Current home directory:", os.path.expanduser("~"))
1006+
print("Current working directory:", os.getcwd())
1007+
print("Current HOME:", env["HOME"])
10051008
else:
10061009
eprint("Building bootstrap")
10071010

10081011
args = self.build_bootstrap_cmd(env)
1012+
print("Running", args, "in", self.rust_root)
10091013
# Run this from the source directory so cargo finds .cargo/config
10101014
run(args, env=env, verbose=self.verbose, cwd=self.rust_root)
10111015

@@ -1015,6 +1019,7 @@ def build_bootstrap(self):
10151019
def build_bootstrap_cmd(self, env):
10161020
"""For tests."""
10171021
build_dir = os.path.join(self.build_dir, "bootstrap")
1022+
print("Building bootstrap in", build_dir)
10181023
if self.clean and os.path.exists(build_dir):
10191024
shutil.rmtree(build_dir)
10201025
# `CARGO_BUILD_TARGET` breaks bootstrap build.

‎src/ci/docker/host-x86_64/x86_64-fuchsia/Dockerfile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Fuchsia as an integration test of the toolchain. See the build-fuchsia.sh
33
# script in this directory for more details.
44

5-
FROM ubuntu:22.04
5+
FROM ghcr.io/marcoieni/ubuntu:22.04
66

77
ARG DEBIAN_FRONTEND=noninteractive
88
RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -75,5 +75,7 @@ ENV RUST_CONFIGURE_ARGS \
7575
--set target.x86_64-unknown-fuchsia.linker=/usr/local/bin/ld.lld
7676

7777
ENV SCRIPT \
78+
echo "x install" && df -h / && \
7879
python3 ../x.py install --target $TARGETS compiler/rustc library/std clippy && \
80+
echo "build fuchsia" && df -h / && \
7981
bash ../src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh

‎src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jiri=.jiri_root/bin/jiri
4343
set -x
4444

4545
if [ -z "$KEEP_CHECKOUT" ]; then
46+
echo "downloading jiri" && df -h /
4647
# This script will:
4748
# - create a directory named "fuchsia" if it does not exist
4849
# - download "jiri" to "fuchsia/.jiri_root/bin"
@@ -52,11 +53,13 @@ if [ -z "$KEEP_CHECKOUT" ]; then
5253

5354
cd $checkout
5455

56+
echo "running jiri init" && df -h /
5557
$jiri init \
5658
-partial=true \
5759
-analytics-opt=false \
5860
.
5961

62+
echo "running jiri import" && df -h /
6063
$jiri import \
6164
-name=integration \
6265
-revision=$INTEGRATION_SHA \
@@ -65,24 +68,41 @@ if [ -z "$KEEP_CHECKOUT" ]; then
6568
"https://fuchsia.googlesource.com/integration"
6669

6770
if [ -d ".git" ]; then
71+
echo "Wipe out any local changes" && df -h /
6872
# Wipe out any local changes if we're reusing a checkout.
6973
git checkout --force JIRI_HEAD
7074
fi
7175

76+
echo "running jiri update" && df -h /
7277
$jiri update -autoupdate=false
7378

7479
echo integration commit = $(git -C integration rev-parse HEAD)
7580

7681
for git_ref in "${PICK_REFS[@]}"; do
82+
echo "running git fetch" && df -h /
7783
git fetch https://fuchsia.googlesource.com/fuchsia $git_ref
84+
echo "running git cherry-pick" && df -h /
7885
git cherry-pick --no-commit FETCH_HEAD
7986
done
8087
else
81-
echo Reusing existing Fuchsia checkout
88+
echo Reusing existing Fuchsia checkout && df -h /
8289
cd $checkout
8390
fi
8491

8592
# Run the script inside the Fuchsia checkout responsible for building Fuchsia.
8693
# You can change arguments to the build by setting KEEP_CHECKOUT=1 above and
8794
# modifying them in build_fuchsia_from_rust_ci.sh.
95+
echo "running build_fuchsia_from_rust_ci.sh" && df -h /
96+
97+
# Start background monitoring of disk space
98+
(
99+
while true; do
100+
df -h /
101+
sleep 20
102+
done
103+
) &
104+
MONITOR_PID=$!
105+
88106
bash scripts/rust/build_fuchsia_from_rust_ci.sh
107+
108+
kill $MONITOR_PID

‎src/ci/docker/run.sh‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ root_dir="`dirname $src_dir`"
3939
source "$ci_dir/shared.sh"
4040

4141
if isCI; then
42+
echo "CI detected"
4243
objdir=$root_dir/obj
4344
else
4445
objdir=$root_dir/obj/$image
@@ -53,6 +54,7 @@ fi
5354
CACHE_DOMAIN="${CACHE_DOMAIN:-ci-caches.rust-lang.org}"
5455

5556
if [ -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
@@ -222,6 +230,7 @@ else
222230
exit 1
223231
fi
224232

233+
echo "Creating directories"
225234
mkdir -p $HOME/.cargo
226235
mkdir -p $objdir/tmp
227236
mkdir -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.
279288
if [ -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"
283293
else
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"
298315
fi
299316

300317
if [ "$dev" = "1" ]

‎src/ci/github-actions/ci.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ def format_run_type(run_type: WorkflowRunType) -> str:
195195
raise AssertionError()
196196

197197

198+
# Add new function before main:
199+
def substitute_github_vars(jobs: list) -> list:
200+
"""Replace GitHub context variables with environment variables in job configs."""
201+
for job in jobs:
202+
if "os" in job:
203+
job["os"] = (
204+
job["os"]
205+
.replace("${{ github.run_id }}", os.environ["GITHUB_RUN_ID"])
206+
.replace("${{ github.run_attempt }}", os.environ["GITHUB_RUN_ATTEMPT"])
207+
)
208+
return jobs
209+
210+
198211
def get_job_image(job: Job) -> str:
199212
"""
200213
By default, the Docker image of a job is based on its name.
@@ -265,6 +278,7 @@ def calculate_job_matrix(job_data: Dict[str, Any]):
265278
if run_type is not None:
266279
jobs = calculate_jobs(run_type, job_data)
267280
jobs = skip_jobs(jobs, channel)
281+
jobs = substitute_github_vars(jobs)
268282

269283
if not jobs:
270284
raise Exception("Scheduled job list is empty, this is an error")

‎src/ci/github-actions/jobs.yml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ runners:
5050
- &job-aarch64-linux
5151
os: ubuntu-22.04-arm
5252

53+
- &job-linux-8c-codebuild
54+
free_disk: true
55+
os: codebuild-ubuntu-22-8c-${{ github.run_id }}-${{ github.run_attempt }}
56+
<<: *base-job
57+
58+
- &job-linux-36c-codebuild
59+
free_disk: true
60+
os: codebuild-ubuntu-22-36c-${{ github.run_id }}-${{ github.run_attempt }}
61+
<<: *base-job
62+
5363
envs:
5464
env-x86_64-apple-tests: &env-x86_64-apple-tests
5565
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
@@ -260,15 +270,15 @@ auto:
260270
# nightly features to compile, and this job would fail if
261271
# executed on beta and stable.
262272
only_on_channel: nightly
263-
<<: *job-linux-8c
273+
<<: *job-linux-36c-codebuild
264274

265275
# Tests integration with Rust for Linux.
266276
# Builds stage 1 compiler and tries to compile a few RfL examples with it.
267277
- name: x86_64-rust-for-linux
268278
<<: *job-linux-4c
269279

270280
- name: x86_64-gnu
271-
<<: *job-linux-4c
281+
<<: *job-linux-8c-codebuild
272282

273283
# This job ensures commits landing on nightly still pass the full
274284
# test suite on the stable channel. There are some UI tests that

‎src/ci/run.sh‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,49 @@
22

33
set -e
44

5+
change_ownership_if_needed() {
6+
local path=$1
7+
local owner="user:user"
8+
local current_owner=$(stat -f "%Su:%Sg" "$path" 2>/dev/null)
9+
local test_file="$path/.write_test"
10+
11+
# Test if filesystem is writable by attempting to touch a temporary file
12+
if touch "$test_file" 2>/dev/null; then
13+
rm "$test_file"
14+
if [ "$current_owner" != "$owner" ]; then
15+
chown -R $owner "$path"
16+
fi
17+
else
18+
echo "$path is read-only, skipping ownership change"
19+
fi
20+
}
21+
22+
echo "Running inside src/ci/run.sh script"
23+
524
if [ -n "$CI_JOB_NAME" ]; then
625
echo "[CI_JOB_NAME=$CI_JOB_NAME]"
726
fi
827

28+
echo "whoami: $(whoami). id: $(id -u) Home: $HOME"
29+
echo "--- current directory ---"
30+
pwd
31+
ls -l
32+
echo "-------------------------"
33+
echo "NO_CHANGE_USER=$NO_CHANGE_USER. LOCAL_USER_ID=$LOCAL_USER_ID"
934
if [ "$NO_CHANGE_USER" = "" ]; then
35+
echo "can change user"
1036
if [ "$LOCAL_USER_ID" != "" ]; then
37+
echo "Starting with UID: $LOCAL_USER_ID"
1138
id -u user &>/dev/null || useradd --shell /bin/bash -u $LOCAL_USER_ID -o -c "" -m user
1239
export HOME=/home/user
1340
unset LOCAL_USER_ID
1441

42+
# Give ownership of necessary directories to the user
43+
change_ownership_if_needed .
44+
mkdir -p /cargo
45+
change_ownership_if_needed /cargo
46+
change_ownership_if_needed /checkout
47+
1548
# Ensure that runners are able to execute git commands in the worktree,
1649
# overriding the typical git protections. In our docker container we're running
1750
# as root, while the user owning the checkout is not root.
@@ -21,6 +54,7 @@ if [ "$NO_CHANGE_USER" = "" ]; then
2154
# For NO_CHANGE_USER done in the small number of Dockerfiles affected.
2255
echo -e '[safe]\n\tdirectory = *' > /home/user/.gitconfig
2356

57+
echo "Switching to user"
2458
exec su --preserve-environment -c "env PATH=$PATH \"$0\"" user
2559
fi
2660
fi

‎src/ci/scripts/run-build-from-ci.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ echo "::add-matcher::src/ci/github-actions/problem_matchers.json"
1717
# the environment
1818
rustup self uninstall -y || true
1919
if [ -z "${IMAGE+x}" ]; then
20+
echo "Running ci/run.sh"
2021
src/ci/run.sh
2122
else
23+
echo "Running docker/run.sh with image ${IMAGE}"
2224
src/ci/docker/run.sh "${IMAGE}"
2325
fi

0 commit comments

Comments
 (0)