Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] test code build runner #133912

Draft
wants to merge 69 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d0835dc
[experiment] test code build runner
marcoieni Dec 5, 2024
efb9f71
fix python script
marcoieni Dec 5, 2024
9eaf00c
fix python
marcoieni Dec 5, 2024
ee92da1
install docker
marcoieni Dec 5, 2024
48f9d4f
fix apt
marcoieni Dec 5, 2024
c1c40b5
fix apt
marcoieni Dec 5, 2024
7ade7c4
debug
marcoieni Dec 5, 2024
05a77ee
debug info
marcoieni Dec 5, 2024
f0fc184
no ipv6
marcoieni Dec 5, 2024
b818874
update codebuild project
marcoieni Dec 6, 2024
ba9a0c6
update to 8 core
marcoieni Dec 11, 2024
3f1e156
exclude problematic test
marcoieni Dec 11, 2024
b009d5c
add buildspec for troubleshooting
marcoieni Dec 12, 2024
c3ed253
don't run container as root
marcoieni Dec 12, 2024
3c70479
Revert "add buildspec for troubleshooting"
marcoieni Dec 12, 2024
6aab224
Revert "exclude problematic test"
marcoieni Dec 12, 2024
8bdc25e
don't install docker
marcoieni Dec 12, 2024
a595285
fix syntax
marcoieni Dec 12, 2024
2550cc3
debug
marcoieni Dec 13, 2024
b1e8433
debug
marcoieni Dec 13, 2024
8f92115
add debug info
marcoieni Dec 13, 2024
bd5ad7a
debug
marcoieni Dec 16, 2024
0c4f7c1
debug
marcoieni Dec 16, 2024
1559d9d
debug
marcoieni Dec 17, 2024
1200473
change user in docker-in-docker
marcoieni Dec 18, 2024
6b9ed61
run whoami before switching user
marcoieni Dec 20, 2024
b3ca0a1
Merge remote-tracking branch 'origin' into test-codebuild-runner
marcoieni Dec 20, 2024
8ac61b0
print home
marcoieni Dec 20, 2024
a9b8ea4
debug
marcoieni Dec 20, 2024
5e3e5b9
fix
marcoieni Dec 20, 2024
0954244
fix
marcoieni Dec 20, 2024
0b2fb0a
try fix issue
marcoieni Dec 20, 2024
05c2661
Merge remote-tracking branch 'origin' into test-codebuild-runner
marcoieni Jan 8, 2025
dbee4e0
remove codebuild script
marcoieni Jan 8, 2025
156ea59
debug prints
marcoieni Jan 8, 2025
f249d32
debug
marcoieni Jan 8, 2025
031c531
fmt
marcoieni Jan 8, 2025
ad17cb7
fix
marcoieni Jan 8, 2025
30c1600
fix
marcoieni Jan 8, 2025
c3673ca
fix
marcoieni Jan 8, 2025
710231a
fix
marcoieni Jan 8, 2025
62e76bd
fix
marcoieni Jan 8, 2025
53a03b0
print user id
marcoieni Jan 8, 2025
b580fac
wip
marcoieni Jan 8, 2025
396ea72
Merge remote-tracking branch 'origin' into test-codebuild-runner
marcoieni Jan 10, 2025
2decb25
fix pr job
marcoieni Jan 10, 2025
b7e4da5
revert unuseful change
marcoieni Jan 10, 2025
41a4104
fix pr
marcoieni Jan 10, 2025
f1735a5
fmt
marcoieni Jan 10, 2025
278c6f0
test fuchsia in codebuild
marcoieni Jan 10, 2025
55f8b2f
Merge remote-tracking branch 'origin' into test-codebuild-runner
marcoieni Jan 13, 2025
7a2b62f
free space on codebuild
marcoieni Jan 13, 2025
ddf43cf
use 36 core job
marcoieni Jan 13, 2025
1812e31
free more space and try 8 core again
marcoieni Jan 14, 2025
e6d94ad
fix
marcoieni Jan 14, 2025
bc3dd87
remove more packages
marcoieni Jan 14, 2025
8cbff9c
remove all gcc versions
marcoieni Jan 14, 2025
6888e90
fix regex
marcoieni Jan 14, 2025
1d9447f
fix
marcoieni Jan 14, 2025
ece4dbd
restore perl
marcoieni Jan 14, 2025
069414a
sudo fix
marcoieni Jan 15, 2025
3822ed8
print disk space info
marcoieni Jan 16, 2025
16a622a
fix SCRIPT
marcoieni Jan 16, 2025
b61aae8
use ghcr
marcoieni Jan 16, 2025
ffad575
use ghcr for buildkit
marcoieni Jan 16, 2025
7fc0a18
fix
marcoieni Jan 16, 2025
c0b29b8
more debug
marcoieni Jan 17, 2025
ac04358
print disk usage in background
marcoieni Jan 17, 2025
fb26043
Merge remote-tracking branch 'origin' into test-codebuild-runner
marcoieni Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ jobs:
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be
if: matrix.free_disk

- name: free up more disk space
if: matrix.free_disk
run: |
sudo apt purge -y --autoremove \
'^java-*' \
'groff' \
'groff-base' \
'^libllvm.*' \
'^llvm.*' \
'gcc' \
'gcc-11' \
'libicu-dev' \
'^vim.*' \
'python3-breezy' \
&& sudo rm -rf /var/lib/apt/lists/*
df -h /

- name: Show installed packages ordered by size
run: dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr

# Rust Log Analyzer can't currently detect the PR number of a GitHub
# Actions build on its own, so a hint in the log message is needed to
# point it in the right direction.
Expand Down Expand Up @@ -174,6 +194,8 @@ jobs:

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

# Disable automatic line ending conversion (again). On Windows, when we're
# installing dependencies, something switches the git configuration directory or
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,10 +1002,14 @@ def build_bootstrap(self):
env = os.environ.copy()
if "GITHUB_ACTIONS" in env:
print("::group::Building bootstrap")
print("Current home directory:", os.path.expanduser("~"))
print("Current working directory:", os.getcwd())
print("Current HOME:", env["HOME"])
else:
eprint("Building bootstrap")

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

Expand All @@ -1015,6 +1019,7 @@ def build_bootstrap(self):
def build_bootstrap_cmd(self, env):
"""For tests."""
build_dir = os.path.join(self.build_dir, "bootstrap")
print("Building bootstrap in", build_dir)
if self.clean and os.path.exists(build_dir):
shutil.rmtree(build_dir)
# `CARGO_BUILD_TARGET` breaks bootstrap build.
Expand Down
4 changes: 3 additions & 1 deletion src/ci/docker/host-x86_64/x86_64-fuchsia/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Fuchsia as an integration test of the toolchain. See the build-fuchsia.sh
# script in this directory for more details.

FROM ubuntu:22.04
FROM ghcr.io/marcoieni/ubuntu:22.04

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

ENV SCRIPT \
echo "x install" && df -h / && \
python3 ../x.py install --target $TARGETS compiler/rustc library/std clippy && \
echo "build fuchsia" && df -h / && \
bash ../src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh
22 changes: 21 additions & 1 deletion src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jiri=.jiri_root/bin/jiri
set -x

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

cd $checkout

echo "running jiri init" && df -h /
$jiri init \
-partial=true \
-analytics-opt=false \
.

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

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

echo "running jiri update" && df -h /
$jiri update -autoupdate=false

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

for git_ref in "${PICK_REFS[@]}"; do
echo "running git fetch" && df -h /
git fetch https://fuchsia.googlesource.com/fuchsia $git_ref
echo "running git cherry-pick" && df -h /
git cherry-pick --no-commit FETCH_HEAD
done
else
echo Reusing existing Fuchsia checkout
echo Reusing existing Fuchsia checkout && df -h /
cd $checkout
fi

# Run the script inside the Fuchsia checkout responsible for building Fuchsia.
# You can change arguments to the build by setting KEEP_CHECKOUT=1 above and
# modifying them in build_fuchsia_from_rust_ci.sh.
echo "running build_fuchsia_from_rust_ci.sh" && df -h /

# Start background monitoring of disk space
(
while true; do
df -h /
sleep 20
done
) &
MONITOR_PID=$!

bash scripts/rust/build_fuchsia_from_rust_ci.sh

kill $MONITOR_PID
41 changes: 29 additions & 12 deletions src/ci/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ root_dir="`dirname $src_dir`"
source "$ci_dir/shared.sh"

if isCI; then
echo "CI detected"
objdir=$root_dir/obj
else
objdir=$root_dir/obj/$image
Expand All @@ -53,6 +54,7 @@ fi
CACHE_DOMAIN="${CACHE_DOMAIN:-ci-caches.rust-lang.org}"

if [ -f "$docker_dir/$image/Dockerfile" ]; then
echo "Dockerfile found for $image"
hash_key=/tmp/.docker-hash-key.txt
rm -f "${hash_key}"
echo $image >> $hash_key
Expand Down Expand Up @@ -140,7 +142,8 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
elif [[ "$PR_CI_JOB" == "1" ]];
then
# Enable a new Docker driver so that --cache-from works with a registry backend
docker buildx create --use --driver docker-container
docker buildx create --use --driver docker-container \
--driver-opt image=ghcr.io/marcoieni/buildkit:buildx-stable-1

# Build the image using registry caching backend
retry docker \
Expand All @@ -150,14 +153,17 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
--output=type=docker
# On auto/try builds, we can also write to the cache.
else
echo "Logging into the Docker registry"
# Log into the Docker registry, so that we can read/write cache and the final image
echo ${DOCKER_TOKEN} | docker login ${REGISTRY} \
--username ${REGISTRY_USERNAME} \
--password-stdin

# Enable a new Docker driver so that --cache-from/to works with a registry backend
docker buildx create --use --driver docker-container
docker buildx create --use --driver docker-container \
--driver-opt image=ghcr.io/marcoieni/buildkit:buildx-stable-1

echo "Building Docker image with cache"
# Build the image using registry caching backend
retry docker \
buildx \
Expand All @@ -166,11 +172,13 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
--cache-to type=registry,ref=${CACHE_IMAGE_TAG},compression=zstd \
--output=type=docker

echo "Docker image built"
# Print images for debugging purposes
docker images

# Tag the built image and push it to the registry
docker tag rust-ci "${IMAGE_TAG}"
echo "Pushing Docker image to the registry"
docker push "${IMAGE_TAG}"

# Record the container registry tag/url for reuse, e.g. by rustup.rs builds
Expand Down Expand Up @@ -222,6 +230,7 @@ else
exit 1
fi

echo "Creating directories"
mkdir -p $HOME/.cargo
mkdir -p $objdir/tmp
mkdir -p $objdir/cores
Expand Down Expand Up @@ -277,24 +286,32 @@ args="$args --privileged"
# `LOCAL_USER_ID` (recognized in `src/ci/run.sh`) to ensure that files are all
# read/written as the same user as the bare-metal user.
if [ -f /.dockerenv ]; then
docker create -v /checkout --name checkout alpine:3.4 /bin/true
echo "Dockerenv detected. We are in docker-in-docker scenario."
docker create -v /checkout --name checkout ghcr.io/marcoieni/alpine:3.4 /bin/true
docker cp . checkout:/checkout
args="$args --volumes-from checkout"
else
args="$args --volume $root_dir:/checkout$SRC_MOUNT_OPTION"
args="$args --volume $objdir:/checkout/obj"
args="$args --volume $HOME/.cargo:/cargo"
args="$args --volume /tmp/toolstate:/tmp/toolstate"
fi

id=$(id -u)
if [[ "$id" != 0 && "$(docker version)" =~ Podman ]]; then
# Rootless podman creates a separate user namespace, where an inner
# LOCAL_USER_ID will map to a different subuid range on the host.
# The "keep-id" mode maps the current UID directly into the container.
args="$args --env NO_CHANGE_USER=1 --userns=keep-id"
else
args="$args --env LOCAL_USER_ID=$id"
fi
id=$(id -u)
if [[ "$id" != 0 && "$(docker version)" =~ Podman ]]; then
# Rootless podman creates a separate user namespace, where an inner
# LOCAL_USER_ID will map to a different subuid range on the host.
# The "keep-id" mode maps the current UID directly into the container.
echo "Running in rootless podman"
args="$args --env NO_CHANGE_USER=1 --userns=keep-id"
elif [[ "$id" != 0 ]]; then
echo "Running in docker as non-root"
args="$args --env LOCAL_USER_ID=$id"
else
echo "Running in docker as root. Using id 1001."
# If we're running as root, we don't want to run the container as root,
# so we set id `1001` instead of `0`.
args="$args --env LOCAL_USER_ID=1001"
fi

if [ "$dev" = "1" ]
Expand Down
14 changes: 14 additions & 0 deletions src/ci/github-actions/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ def format_run_type(run_type: WorkflowRunType) -> str:
raise AssertionError()


# Add new function before main:
def substitute_github_vars(jobs: list) -> list:
"""Replace GitHub context variables with environment variables in job configs."""
for job in jobs:
if "os" in job:
job["os"] = (
job["os"]
.replace("${{ github.run_id }}", os.environ["GITHUB_RUN_ID"])
.replace("${{ github.run_attempt }}", os.environ["GITHUB_RUN_ATTEMPT"])
)
return jobs


def get_job_image(job: Job) -> str:
"""
By default, the Docker image of a job is based on its name.
Expand Down Expand Up @@ -265,6 +278,7 @@ def calculate_job_matrix(job_data: Dict[str, Any]):
if run_type is not None:
jobs = calculate_jobs(run_type, job_data)
jobs = skip_jobs(jobs, channel)
jobs = substitute_github_vars(jobs)

if not jobs:
raise Exception("Scheduled job list is empty, this is an error")
Expand Down
14 changes: 12 additions & 2 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ runners:
- &job-aarch64-linux
os: ubuntu-22.04-arm

- &job-linux-8c-codebuild
free_disk: true
os: codebuild-ubuntu-22-8c-${{ github.run_id }}-${{ github.run_attempt }}
<<: *base-job

- &job-linux-36c-codebuild
free_disk: true
os: codebuild-ubuntu-22-36c-${{ github.run_id }}-${{ github.run_attempt }}
<<: *base-job

envs:
env-x86_64-apple-tests: &env-x86_64-apple-tests
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
Expand Down Expand Up @@ -256,15 +266,15 @@ auto:
# nightly features to compile, and this job would fail if
# executed on beta and stable.
only_on_channel: nightly
<<: *job-linux-8c
<<: *job-linux-8c-codebuild

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

- name: x86_64-gnu
<<: *job-linux-4c
<<: *job-linux-8c-codebuild

# This job ensures commits landing on nightly still pass the full
# test suite on the stable channel. There are some UI tests that
Expand Down
34 changes: 34 additions & 0 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@

set -e

change_ownership_if_needed() {
local path=$1
local owner="user:user"
local current_owner=$(stat -f "%Su:%Sg" "$path" 2>/dev/null)
local test_file="$path/.write_test"

# Test if filesystem is writable by attempting to touch a temporary file
if touch "$test_file" 2>/dev/null; then
rm "$test_file"
if [ "$current_owner" != "$owner" ]; then
chown -R $owner "$path"
fi
else
echo "$path is read-only, skipping ownership change"
fi
}

echo "Running inside src/ci/run.sh script"

if [ -n "$CI_JOB_NAME" ]; then
echo "[CI_JOB_NAME=$CI_JOB_NAME]"
fi

echo "whoami: $(whoami). id: $(id -u) Home: $HOME"
echo "--- current directory ---"
pwd
ls -l
echo "-------------------------"
echo "NO_CHANGE_USER=$NO_CHANGE_USER. LOCAL_USER_ID=$LOCAL_USER_ID"
if [ "$NO_CHANGE_USER" = "" ]; then
echo "can change user"
if [ "$LOCAL_USER_ID" != "" ]; then
echo "Starting with UID: $LOCAL_USER_ID"
id -u user &>/dev/null || useradd --shell /bin/bash -u $LOCAL_USER_ID -o -c "" -m user
export HOME=/home/user
unset LOCAL_USER_ID

# Give ownership of necessary directories to the user
change_ownership_if_needed .
mkdir -p /cargo
change_ownership_if_needed /cargo
change_ownership_if_needed /checkout

# Ensure that runners are able to execute git commands in the worktree,
# overriding the typical git protections. In our docker container we're running
# as root, while the user owning the checkout is not root.
Expand All @@ -21,6 +54,7 @@ if [ "$NO_CHANGE_USER" = "" ]; then
# For NO_CHANGE_USER done in the small number of Dockerfiles affected.
echo -e '[safe]\n\tdirectory = *' > /home/user/.gitconfig

echo "Switching to user"
exec su --preserve-environment -c "env PATH=$PATH \"$0\"" user
fi
fi
Expand Down
2 changes: 2 additions & 0 deletions src/ci/scripts/run-build-from-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ echo "::add-matcher::src/ci/github-actions/problem_matchers.json"
# the environment
rustup self uninstall -y || true
if [ -z "${IMAGE+x}" ]; then
echo "Running ci/run.sh"
src/ci/run.sh
else
echo "Running docker/run.sh with image ${IMAGE}"
src/ci/docker/run.sh "${IMAGE}"
fi
Loading