Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions image/ci-runner-idle-exit
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
# IDLE_GRACE_SECONDS (default 30, as docker stop gives an EC2 runner): the
# runner's helper and listener sit in their own process group, and a TERM
# alone doesn't end them.
#
# With CI_RUNNER_VCPUS (the task's vCPUs, set by the launcher), it first writes
# /home/runner/.cargo/config.toml with `[build] jobs = <n>`: nproc over-reports
# in a task, and a CARGO_BUILD_JOBS in the environment would change
# Swatinem/rust-cache's key (it hashes every CARGO*, CC*, CFLAGS*, CXX*, CMAKE*
# and RUST* variable), so a Fargate job would miss the cache an EC2 job saved.
# Cargo reads .cargo/config.toml in every ancestor of its working directory,
# so the file reaches every checkout under /home/runner/_work, whatever
# CARGO_HOME a job sets. A file already there is left alone.
set -u

idle=${IDLE_SECONDS:-900}
Expand All @@ -26,6 +35,21 @@ if [[ ! $grace =~ ^[0-9]+$ ]]; then
exit 2
fi

cargo_jobs() {
local n=${CI_RUNNER_VCPUS:-} dir=/home/runner/.cargo
[[ -n $n ]] || return 0
if [[ ! $n =~ ^[1-9][0-9]*$ ]]; then
echo "ci-runner: CI_RUNNER_VCPUS must be a positive integer, not '$n'; no cargo jobs set" >&2
elif [[ -e $dir/config.toml ]]; then
echo "ci-runner: $dir/config.toml exists, leaving it; cargo's jobs not set to $n" >&2
elif mkdir -p "$dir" && printf '[build]\njobs = %s\n' "$n" > "$dir/config.toml"; then
echo "ci-runner: cargo jobs = $n ($dir/config.toml)"
else
echo "ci-runner: couldn't write $dir/config.toml; cargo's jobs not set" >&2
fi
}
cargo_jobs

log=$(mktemp /tmp/ci-runner-idle-exit.XXXXXX)
# Its own session (its id is $pid), so a stop reaches run.sh, its helper and
# the listener, whatever their process groups.
Expand Down
20 changes: 20 additions & 0 deletions image/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,25 @@ expect idle-exit-keeps "3 finished" "$rc $(grep -x finished <<<"$out")"
out=$(IDLE_SECONDS=0 timeout 10 "$idle" true 2>&1)
expect idle-exit-refuses "2" "$?"

echo "== cargo jobs"
# With CI_RUNNER_VCPUS the entrypoint caps cargo's jobs in a config file, not
# in a CARGO_* variable rust-cache would hash. cargo isn't in the image, so
# the file is checked, not a build.
cfg=/home/runner/.cargo/config.toml
rm -f "$cfg"
IDLE_SECONDS=2 timeout 10 "$idle" true >/dev/null 2>&1
expect cargo-none no "$([[ -e $cfg ]] && echo yes || echo no)"
out=$(CI_RUNNER_VCPUS=4 IDLE_SECONDS=2 timeout 10 "$idle" true 2>&1)
expect cargo-config '[build] jobs = 4' "$(paste -sd' ' "$cfg" 2>&1)"
expect cargo-owner runner "$(stat -c %U "$cfg" 2>&1)"
expect cargo-says yes "$(grep -q 'cargo jobs = 4' <<<"$out" && echo yes || echo no)"
printf '[net]\ngit-fetch-with-cli = true\n' > "$cfg"
out=$(CI_RUNNER_VCPUS=8 IDLE_SECONDS=2 timeout 10 "$idle" true 2>&1)
expect cargo-keeps '[net] git-fetch-with-cli = true' "$(paste -sd' ' "$cfg" 2>&1)"
expect cargo-keeps-says yes "$(grep -q 'exists, leaving it' <<<"$out" && echo yes || echo no)"
rm -f "$cfg"
out=$(CI_RUNNER_VCPUS=four IDLE_SECONDS=2 timeout 10 "$idle" true 2>&1)
expect cargo-bad-value "0 no" "$? $([[ -e $cfg ]] && echo yes || echo no)"

if (( fail )); then echo "SMOKE FAILED"; exit 1; fi
echo "SMOKE PASSED"
Loading