Repository navigation
Stop leaking warm snapshots; sweep the self-hosted Macs' disks #182
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: runner disk | ||
|
|
||
| # Sweeps what hluk and this repo's jobs keep on the self-hosted Macs, the | ||
| # only arm64 hosts that keep their disk between jobs (the Linux and | ||
| # Windows ones are fresh machines each time): each runner is a user of | ||
| # its own, with its own hluk cache and build directories, and a Mac's | ||
| # runners share its disk with hyperlight's jobs. One job per runner, each | ||
| # holding its runner a while so the jobs spread over all of them; the last | ||
| # job lists the runners none reached, to run this again for. Other repos' | ||
| # files are shown, never removed. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| paths: | ||
| - .github/workflows/runner-disk.yml | ||
| - dev/ci-disk.sh | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read | ||
|
|
||
| jobs: | ||
| sweep: | ||
| name: sweep (${{ matrix.slot }}) | ||
| runs-on: [self-hosted, macos, arm64, hvf] | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| slot: [1, 2, 3, 4, 5, 6, 7, 8] | ||
| steps: | ||
| # Fetched, not checked out: a full disk has no room for a checkout. | ||
| - name: Sweep | ||
| # bash -eo pipefail: a failed download fails the job, which then | ||
| # does not count as a runner swept. | ||
| shell: bash | ||
| env: | ||
| SWEEP: "1" | ||
| SCRIPT: https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.pull_request.head.sha || github.sha }}/dev/ci-disk.sh | ||
| run: | | ||
| echo "runner: $RUNNER_NAME ($(whoami))" | ||
| curl -fsSL --retry 3 "$SCRIPT" | bash | ||
|
|
||
| # Held, so this runner takes no other sweep job and they all spread. | ||
| - name: Hold the runner | ||
| run: sleep 300 | ||
|
|
||
| coverage: | ||
| needs: sweep | ||
| if: always() | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RUNNERS: >- | ||
| Simons-Mac-mini-runner-1 Simons-Mac-mini-runner-2 | ||
| Simons-Mac-mini-runner-3 Simons-Mac-mini-runner-4 | ||
| azures-Mac-mini-runner-1 azures-Mac-mini-runner-2 | ||
| azures-Mac-mini-runner-3 azures-Mac-mini-runner-4 | ||
| steps: | ||
| - name: Runners swept | ||
| run: | | ||
| swept=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs?per_page=100" \ | ||
| --jq '.jobs[] | select(.name | startswith("sweep")) | select(.conclusion == "success") | .runner_name' | sort -u) | ||
| echo "Swept:"; echo "$swept" | sed 's/^/ /' | ||
| missed="" | ||
| for r in $RUNNERS; do | ||
| echo "$swept" | grep -qx "$r" || missed="$missed $r" | ||
| done | ||
| if [ -n "$missed" ]; then | ||
| echo "::warning::Not swept, run this again:$missed" | ||
| else | ||
| echo "Every runner swept." | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env bash | ||
| # Shows what fills a self-hosted runner's disk, and removes what hluk and | ||
| # its tests leave there: these runners keep their disk between jobs. | ||
| # .github/actions/arm64-host runs it before anything else, so it needs no | ||
| # free space itself. It only touches the runner user's own files. | ||
| # MIN_FREE_GB below this much free space after the cleanup, also remove | ||
| # this checkout's target/ and cargo's download cache | ||
| # (default 20) | ||
| # SWEEP=1 remove all that hluk and this repo's jobs keep: the whole | ||
| # hluk cache, every hluk-* temp directory, and this repo's | ||
| # target/ directories (.github/workflows/runner-disk.yml) | ||
| set -uo pipefail | ||
|
|
||
| min_free_kb=$((${MIN_FREE_GB:-20} * 1024 * 1024)) | ||
| cache="${HLUK_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/hluk}" | ||
| tmp="${TMPDIR:-/tmp}" | ||
| tmp="${tmp%/}" | ||
|
|
||
| free_kb() { df -Pk "$HOME" | awk 'NR == 2 { print $4 }'; } | ||
|
|
||
| # The paths given, largest first, in GB. | ||
| sizes() { | ||
| for p in "$@"; do | ||
| [ -e "$p" ] && du -sk "$p" 2>/dev/null | ||
| done | sort -rn | awk '{ printf "%7.1f GB %s\n", $1 / 1048576, $2 }' | ||
| } | ||
|
|
||
| before=$(free_kb) | ||
| echo "== Disk" | ||
| df -h "$HOME" | ||
| echo "== Largest in $HOME" | ||
| sizes "$HOME"/* "$HOME"/.[!.]* | head -15 | ||
| if [ -n "${RUNNER_WORKSPACE:-}" ]; then | ||
| echo "== Runner work directories" | ||
| sizes "$RUNNER_WORKSPACE"/../* "$RUNNER_WORKSPACE"/*/target | head -15 | ||
| fi | ||
| echo "== hluk cache ($cache)" | ||
| sizes "$cache"/* "$cache"/snapshots/* | head -15 | ||
| echo "== Largest in $tmp" | ||
| sizes "$tmp"/* | head -10 | ||
|
|
||
| # Warm snapshots and pulled images nobody has saved or pulled for a few | ||
| # days: an earlier hluk's or kernel's, which no run restores any more, | ||
| # and the next run that wants one makes it again. | ||
| echo "== Cleanup" | ||
| if [ "${SWEEP:-}" = 1 ]; then | ||
| rm -rf "$cache" && echo "removed $cache" | ||
| find "$tmp" -mindepth 1 -maxdepth 1 -name 'hluk-*' -print -exec rm -rf {} + | ||
| if [ -n "${RUNNER_WORKSPACE:-}" ]; then | ||
| for t in "$RUNNER_WORKSPACE"/*/target; do | ||
| [ -d "$t" ] && rm -rf "$t" && echo "removed $t" | ||
| done | ||
| fi | ||
| fi | ||
| if [ -d "$cache/snapshots" ]; then | ||
| find "$cache/snapshots" -mindepth 1 -maxdepth 1 \( -name '*.part' -o -mtime +2 \) \ | ||
| -print -exec rm -rf {} + | ||
| fi | ||
| if [ -d "$cache/rootfs" ]; then | ||
| find "$cache/rootfs" -type f -mtime +7 -print -delete | ||
| fi | ||
| # Test directories a killed test left behind (they are removed on drop). | ||
| find "$tmp" -mindepth 1 -maxdepth 1 -name 'hluk-*' -mtime +0 -print -exec rm -rf {} + | ||
|
|
||
| if [ "$(free_kb)" -lt "$min_free_kb" ] && [ -n "${GITHUB_WORKSPACE:-}" ]; then | ||
| echo "Under ${MIN_FREE_GB:-20} GB free: removing $GITHUB_WORKSPACE/target and cargo's download cache" | ||
| rm -rf "$GITHUB_WORKSPACE/target" "${CARGO_HOME:-$HOME/.cargo}/registry/cache" | ||
| fi | ||
|
|
||
| after=$(free_kb) | ||
| awk -v b="$before" -v a="$after" 'BEGIN { printf "== Freed %.1f GB; %.1f GB free\n", (a - b) / 1048576, a / 1048576 }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in bf43566: the step runs with
shell: bash, which isbash -eo pipefail, so a failed download fails the job andcoveragedoes not count that runner as swept.