Skip to content

Commit 0904aeb

Browse files
committed
Auto merge of #138745 - marcoieni:use-linux-codebuild-runners, r=<try>
CI: use aws codebuild for dist-arm-linux job try-job: dist-arm-linux
2 parents 4ac032f + d074896 commit 0904aeb

File tree

7 files changed

+111
-11
lines changed

7 files changed

+111
-11
lines changed

.github/workflows/ci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ jobs:
159159
run: src/ci/scripts/install-ninja.sh
160160

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

164166
# Disable automatic line ending conversion (again). On Windows, when we're
@@ -187,6 +189,13 @@ jobs:
187189
# Build it into the build directory, to avoid modifying sources
188190
- name: build citool
189191
run: |
192+
# Check if cargo is installed
193+
if ! command -v cargo &> /dev/null; then
194+
echo "Cargo not found, installing Rust..."
195+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
196+
# Make cargo available in PATH
197+
. "$HOME/.cargo/env"
198+
fi
190199
cd src/ci/citool
191200
CARGO_INCREMENTAL=0 CARGO_TARGET_DIR=../../../build/citool cargo build
192201

src/ci/citool/src/jobs.rs

+25
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ mod tests;
33

44
use std::collections::BTreeMap;
55

6+
use anyhow::Context as _;
67
use serde_yaml::Value;
78

89
use crate::GitHubContext;
10+
use crate::utils::load_env_var;
911

1012
/// Representation of a job loaded from the `src/ci/github-actions/jobs.yml` file.
1113
#[derive(serde::Deserialize, Debug, Clone)]
@@ -109,6 +111,27 @@ struct GithubActionsJob {
109111
doc_url: Option<String>,
110112
}
111113

114+
/// Replace GitHub context variables with environment variables in job configs.
115+
/// Useful for codebuild jobs like
116+
/// `codebuild-ubuntu-22-8c-${{ github.run_id }}-${{ github.run_attempt }}`
117+
fn substitute_github_vars(jobs: Vec<Job>) -> anyhow::Result<Vec<Job>> {
118+
let run_id = load_env_var("GITHUB_RUN_ID")?;
119+
let run_attempt = load_env_var("GITHUB_RUN_ATTEMPT")?;
120+
121+
let jobs = jobs
122+
.into_iter()
123+
.map(|mut job| {
124+
job.os = job
125+
.os
126+
.replace("${{ github.run_id }}", &run_id)
127+
.replace("${{ github.run_attempt }}", &run_attempt);
128+
job
129+
})
130+
.collect();
131+
132+
Ok(jobs)
133+
}
134+
112135
/// Skip CI jobs that are not supposed to be executed on the given `channel`.
113136
fn skip_jobs(jobs: Vec<Job>, channel: &str) -> Vec<Job> {
114137
jobs.into_iter()
@@ -177,6 +200,8 @@ fn calculate_jobs(
177200
}
178201
RunType::AutoJob => (db.auto_jobs.clone(), "auto", &db.envs.auto_env),
179202
};
203+
let jobs = substitute_github_vars(jobs.clone())
204+
.context("Failed to substitute GitHub context variables in jobs")?;
180205
let jobs = skip_jobs(jobs, channel);
181206
let jobs = jobs
182207
.into_iter()

src/ci/docker/host-x86_64/dist-arm-linux/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.04
1+
FROM ghcr.io/rust-lang/ubuntu:22.04
22

33
COPY scripts/cross-apt-packages.sh /scripts/
44
RUN sh /scripts/cross-apt-packages.sh

src/ci/docker/run.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ args="$args --privileged"
288288
# `LOCAL_USER_ID` (recognized in `src/ci/run.sh`) to ensure that files are all
289289
# read/written as the same user as the bare-metal user.
290290
if [ -f /.dockerenv ]; then
291-
docker create -v /checkout --name checkout alpine:3.4 /bin/true
291+
docker create -v /checkout --name checkout ghcr.io/rust-lang/alpine:3.4 /bin/true
292292
docker cp . checkout:/checkout
293293
args="$args --volumes-from checkout"
294294
else
@@ -308,6 +308,21 @@ else
308308
fi
309309
fi
310310

311+
# id=$(id -u)
312+
# if [[ "$id" != 0 && "$(docker version)" =~ Podman ]]; then
313+
# # Rootless podman creates a separate user namespace, where an inner
314+
# # LOCAL_USER_ID will map to a different subuid range on the host.
315+
# # The "keep-id" mode maps the current UID directly into the container.
316+
# args="$args --env NO_CHANGE_USER=1 --userns=keep-id"
317+
# elif [[ "$id" != 0 ]]; then
318+
# # We are running in docker as non-root
319+
# args="$args --env LOCAL_USER_ID=$id"
320+
# else
321+
# # We are running as root. Since we don't want to run the container as root,
322+
# # we set id `1001` instead of `0`.
323+
# args="$args --env LOCAL_USER_ID=1001"
324+
# fi
325+
311326
if [ "$dev" = "1" ]
312327
then
313328
# Interactive + TTY

src/ci/github-actions/jobs.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ runners:
5656
- &job-aarch64-linux-8c
5757
os: ubuntu-24.04-arm64-8core-32gb
5858
<<: *base-job
59+
60+
- &job-linux-8c-codebuild
61+
free_disk: true
62+
os: codebuild-ubuntu-22-8c-${{ github.run_id }}-${{ github.run_attempt }}
63+
<<: *base-job
64+
5965
envs:
6066
env-x86_64-apple-tests: &env-x86_64-apple-tests
6167
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
@@ -153,7 +159,7 @@ auto:
153159
<<: *job-linux-4c
154160

155161
- name: dist-arm-linux
156-
<<: *job-linux-8c
162+
<<: *job-linux-8c-codebuild
157163

158164
- name: dist-armhf-linux
159165
<<: *job-linux-4c

src/ci/run.sh

+25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
set -e
44

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

38+
# # Give ownership of necessary directories to the user
39+
# change_ownership_if_needed .
40+
# mkdir -p /cargo
41+
# change_ownership_if_needed /cargo
42+
# change_ownership_if_needed /checkout
43+
1944
# Ensure that runners are able to execute git commands in the worktree,
2045
# overriding the typical git protections. In our docker container we're running
2146
# as root, while the user owning the checkout is not root.

src/ci/scripts/free-disk-space.sh

+28-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ isX86() {
1414
fi
1515
}
1616

17+
# Check if we're on a GitHub hosted runner.
18+
# Otherwise, we are running in aws codebuild.
19+
isGitHubRunner() {
20+
# `:-` means "use the value of RUNNER_ENVIRONMENT if it exists, otherwise use an empty string".
21+
if [[ "${RUNNER_ENVIRONMENT:-}" == "github-hosted" ]]; then
22+
return 1
23+
else
24+
return 0
25+
fi
26+
}
27+
1728
# print a line of the specified character
1829
printSeparationLine() {
1930
for ((i = 0; i < 80; i++)); do
@@ -118,10 +129,14 @@ removeUnusedFilesAndDirs() {
118129
# Azure
119130
"/opt/az"
120131
"/usr/share/az_"*
132+
)
121133

134+
if [ -n "${AGENT_TOOLSDIRECTORY:-}" ]; then
122135
# Environment variable set by GitHub Actions
123-
"$AGENT_TOOLSDIRECTORY"
124-
)
136+
to_remove+=(
137+
"${AGENT_TOOLSDIRECTORY}"
138+
)
139+
fi
125140

126141
for element in "${to_remove[@]}"; do
127142
if [ ! -e "$element" ]; then
@@ -155,20 +170,25 @@ cleanPackages() {
155170
'^dotnet-.*'
156171
'^llvm-.*'
157172
'^mongodb-.*'
158-
'azure-cli'
159173
'firefox'
160174
'libgl1-mesa-dri'
161175
'mono-devel'
162176
'php.*'
163177
)
164178

165-
if isX86; then
179+
if isGithubHosted; then
166180
packages+=(
167-
'google-chrome-stable'
168-
'google-cloud-cli'
169-
'google-cloud-sdk'
170-
'powershell'
181+
azure-cli
171182
)
183+
184+
if isX86; then
185+
packages+=(
186+
'google-chrome-stable'
187+
'google-cloud-cli'
188+
'google-cloud-sdk'
189+
'powershell'
190+
)
191+
fi
172192
fi
173193

174194
sudo apt-get -qq remove -y --fix-missing "${packages[@]}"

0 commit comments

Comments
 (0)