Skip to content

Commit 7ba71d3

Browse files
authored
Rollup merge of #140148 - marcoieni:ci-aws-codebuild, r=Kobzol
CI: use aws codebuild for job dist-arm-linux try-job: dist-arm-linux
2 parents 610ed82 + 18c3370 commit 7ba71d3

File tree

6 files changed

+91
-13
lines changed

6 files changed

+91
-13
lines changed

.github/workflows/ci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ jobs:
9191
# Check the `calculate_matrix` job to see how is the matrix defined.
9292
include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}
9393
steps:
94+
- name: Install cargo in AWS CodeBuild
95+
if: matrix.codebuild
96+
run: |
97+
# Check if cargo is installed
98+
if ! command -v cargo &> /dev/null; then
99+
echo "Cargo not found, installing Rust..."
100+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
101+
# Make cargo available in PATH
102+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
103+
fi
104+
94105
- name: disable git crlf conversion
95106
run: git config --global core.autocrlf false
96107

@@ -165,6 +176,8 @@ jobs:
165176
run: src/ci/scripts/install-ninja.sh
166177

167178
- name: enable ipv6 on Docker
179+
# Don't run on codebuild because systemctl is not available
180+
if: ${{ !matrix.codebuild }}
168181
run: src/ci/scripts/enable-docker-ipv6.sh
169182

170183
# Disable automatic line ending conversion (again). On Windows, when we're

src/ci/citool/src/jobs.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ 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)]
14+
#[serde(deny_unknown_fields)]
1215
pub struct Job {
1316
/// Name of the job, e.g. mingw-check
1417
pub name: String,
@@ -26,6 +29,8 @@ pub struct Job {
2629
pub free_disk: Option<bool>,
2730
/// Documentation link to a resource that could help people debug this CI job.
2831
pub doc_url: Option<String>,
32+
/// Whether the job is executed on AWS CodeBuild.
33+
pub codebuild: Option<bool>,
2934
}
3035

3136
impl Job {
@@ -80,7 +85,7 @@ impl JobDatabase {
8085
}
8186

8287
pub fn load_job_db(db: &str) -> anyhow::Result<JobDatabase> {
83-
let mut db: Value = serde_yaml::from_str(&db)?;
88+
let mut db: Value = serde_yaml::from_str(db)?;
8489

8590
// We need to expand merge keys (<<), because serde_yaml can't deal with them
8691
// `apply_merge` only applies the merge once, so do it a few times to unwrap nested merges.
@@ -107,6 +112,29 @@ struct GithubActionsJob {
107112
free_disk: Option<bool>,
108113
#[serde(skip_serializing_if = "Option::is_none")]
109114
doc_url: Option<String>,
115+
#[serde(skip_serializing_if = "Option::is_none")]
116+
codebuild: Option<bool>,
117+
}
118+
119+
/// Replace GitHub context variables with environment variables in job configs.
120+
/// Used for codebuild jobs like
121+
/// `codebuild-ubuntu-22-8c-$github.run_id-$github.run_attempt`
122+
fn substitute_github_vars(jobs: Vec<Job>) -> anyhow::Result<Vec<Job>> {
123+
let run_id = load_env_var("GITHUB_RUN_ID")?;
124+
let run_attempt = load_env_var("GITHUB_RUN_ATTEMPT")?;
125+
126+
let jobs = jobs
127+
.into_iter()
128+
.map(|mut job| {
129+
job.os = job
130+
.os
131+
.replace("$github.run_id", &run_id)
132+
.replace("$github.run_attempt", &run_attempt);
133+
job
134+
})
135+
.collect();
136+
137+
Ok(jobs)
110138
}
111139

112140
/// Skip CI jobs that are not supposed to be executed on the given `channel`.
@@ -177,6 +205,8 @@ fn calculate_jobs(
177205
}
178206
RunType::AutoJob => (db.auto_jobs.clone(), "auto", &db.envs.auto_env),
179207
};
208+
let jobs = substitute_github_vars(jobs.clone())
209+
.context("Failed to substitute GitHub context variables in jobs")?;
180210
let jobs = skip_jobs(jobs, channel);
181211
let jobs = jobs
182212
.into_iter()
@@ -207,6 +237,7 @@ fn calculate_jobs(
207237
continue_on_error: job.continue_on_error,
208238
free_disk: job.free_disk,
209239
doc_url: job.doc_url,
240+
codebuild: job.codebuild,
210241
}
211242
})
212243
.collect();

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

+1-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

src/ci/github-actions/jobs.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ runners:
5656
- &job-aarch64-linux-8c
5757
os: ubuntu-24.04-arm64-8core-32gb
5858
<<: *base-job
59+
60+
# Codebuild runners are provisioned in
61+
# https://github.com/rust-lang/simpleinfra/blob/b7ddd5e6bec8a93ec30510cdddec02c5666fefe9/terragrunt/accounts/ci-prod/ci-runners/terragrunt.hcl#L2
62+
- &job-linux-36c-codebuild
63+
free_disk: true
64+
codebuild: true
65+
os: codebuild-ubuntu-22-36c-$github.run_id-$github.run_attempt
66+
<<: *base-job
67+
5968
envs:
6069
env-x86_64-apple-tests: &env-x86_64-apple-tests
6170
SCRIPT: ./x.py check compiletest --set build.compiletest-use-stage0-libtest=true && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
@@ -151,7 +160,7 @@ auto:
151160
<<: *job-linux-4c
152161

153162
- name: dist-arm-linux
154-
<<: *job-linux-8c
163+
<<: *job-linux-36c-codebuild
155164

156165
- name: dist-armhf-linux
157166
<<: *job-linux-4c

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

+34-9
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+
# In aws codebuild, the variable RUNNER_ENVIRONMENT is "self-hosted".
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 0
23+
else
24+
return 1
25+
fi
26+
}
27+
1728
# print a line of the specified character
1829
printSeparationLine() {
1930
for ((i = 0; i < 80; i++)); do
@@ -32,7 +43,7 @@ getAvailableSpace() {
3243
# make Kb human readable (assume the input is Kb)
3344
# REF: https://unix.stackexchange.com/a/44087/60849
3445
formatByteCount() {
35-
numfmt --to=iec-i --suffix=B --padding=7 "$1"'000'
46+
numfmt --to=iec-i --suffix=B --padding=7 "${1}000"
3647
}
3748

3849
# macro to output saved space
@@ -45,6 +56,11 @@ printSavedSpace() {
4556
after=$(getAvailableSpace)
4657
local saved=$((after - before))
4758

59+
if [ "$saved" -lt 0 ]; then
60+
echo "::warning::Saved space is negative: $saved. Using '0' as saved space."
61+
saved=0
62+
fi
63+
4864
echo ""
4965
printSeparationLine "*"
5066
if [ -n "${title}" ]; then
@@ -118,10 +134,14 @@ removeUnusedFilesAndDirs() {
118134
# Azure
119135
"/opt/az"
120136
"/usr/share/az_"*
137+
)
121138

139+
if [ -n "${AGENT_TOOLSDIRECTORY:-}" ]; then
122140
# Environment variable set by GitHub Actions
123-
"$AGENT_TOOLSDIRECTORY"
124-
)
141+
to_remove+=(
142+
"${AGENT_TOOLSDIRECTORY}"
143+
)
144+
fi
125145

126146
for element in "${to_remove[@]}"; do
127147
if [ ! -e "$element" ]; then
@@ -155,20 +175,25 @@ cleanPackages() {
155175
'^dotnet-.*'
156176
'^llvm-.*'
157177
'^mongodb-.*'
158-
'azure-cli'
159178
'firefox'
160179
'libgl1-mesa-dri'
161180
'mono-devel'
162181
'php.*'
163182
)
164183

165-
if isX86; then
184+
if isGitHubRunner; then
166185
packages+=(
167-
'google-chrome-stable'
168-
'google-cloud-cli'
169-
'google-cloud-sdk'
170-
'powershell'
186+
azure-cli
171187
)
188+
189+
if isX86; then
190+
packages+=(
191+
'google-chrome-stable'
192+
'google-cloud-cli'
193+
'google-cloud-sdk'
194+
'powershell'
195+
)
196+
fi
172197
fi
173198

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

0 commit comments

Comments
 (0)