Skip to content

Commit 605f8b1

Browse files
committed
Auto merge of rust-lang#140148 - marcoieni:ci-aws-codebuild, r=<try>
CI: use aws codebuild for job dist-arm-linux try-job: dist-arm-linux
2 parents 9bfa31f + 3e30d0f commit 605f8b1

File tree

6 files changed

+76
-11
lines changed

6 files changed

+76
-11
lines changed

.github/workflows/ci.yml

+12
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ 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: ${{ contains(matrix.os, 'codebuild-ubuntu') }}
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
101+
# Make cargo available in PATH
102+
. "$HOME/.cargo/env"
103+
fi
94104
- name: disable git crlf conversion
95105
run: git config --global core.autocrlf false
96106

@@ -168,6 +178,8 @@ jobs:
168178
run: src/ci/scripts/install-ninja.sh
169179

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

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

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

+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

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ 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/70a31d454d74b604c585be3743390e99cfb635ea/terragrunt/accounts/ci-prod/ci-runners/terragrunt.hcl#L2
62+
- &job-linux-36c-codebuild
63+
free_disk: true
64+
os: codebuild-ubuntu-22-36c-${{ github.run_id }}-${{ github.run_attempt }}
65+
<<: *base-job
66+
5967
envs:
6068
env-x86_64-apple-tests: &env-x86_64-apple-tests
6169
SCRIPT: ./x.py check compiletest --set build.compiletest-use-stage0-libtest=true && ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
@@ -153,7 +161,7 @@ auto:
153161
<<: *job-linux-4c
154162

155163
- name: dist-arm-linux
156-
<<: *job-linux-8c
164+
<<: *job-linux-36c-codebuild
157165

158166
- name: dist-armhf-linux
159167
<<: *job-linux-4c

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+
# 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
@@ -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 isGitHubRunner; 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)