Skip to content
Open
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
1 change: 1 addition & 0 deletions src/ci/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ docker \
--env DEPLOY \
--env DEPLOY_ALT \
--env CI \
--env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
--env GITHUB_ACTIONS \
--env GITHUB_REF \
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \
Expand Down
62 changes: 62 additions & 0 deletions src/ci/scripts/free-disk-space-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ set -euo pipefail
# Free disk space on Linux GitHub action runners
# Script inspired by https://github.com/jlumbroso/free-disk-space


# we need ~50GB of space
space_target_kb=$((50 * 1024 * 1024))


isX86() {
local arch
arch=$(uname -m)
Expand Down Expand Up @@ -247,12 +252,69 @@ cleanSwap() {
free -h
}

sufficientSpaceEarlyExit() {
local available_space_kb=$(df -k . --output=avail | tail -n 1)

if [ "$available_space_kb" -ge "$space_target_kb" ]; then
echo "Sufficient disk space available (${available_space_kb}KB >= ${space_target_kb}KB). Skipping cleanup."
exit 0
fi
}

# Try to find a different drive to put our data on so we don't need to run cleanup.
# The availability of the disks we're probing isn't guaranteed,
# so this is opportunistic.
checkAlternative() {
local gha_alt_disk="/mnt"

local available_space_kb=$(df -k "$gha_alt_disk" --output=avail | tail -n 1)

# mount options that trade durability for performance
# ignore-tidy-linelength
local mntopts="defaults,discard,journal_async_commit,barrier=0,noauto_da_alloc,lazytime,data=writeback"

# GHA has a 2nd disk mounted at /mnt that is almost empty.
# Check if it's a valid mountpoint and it has enough available space.
if mountpoint "$gha_alt_disk" && [ "$available_space_kb" -ge "$space_target_kb" ]; then
local blkdev=$(df -k "$gha_alt_disk" --output=source | tail -n 1)
echo "Sufficient space available on $blkdev mounted at $gha_alt_disk"
# see cleanSwap(), swapfile may be mounted under /mnt
sudo swapoff -a || true

# unmount from original location
sudo umount "$gha_alt_disk"

# remount under the obj dir which is used by docker scripts to write most
# of our build output. And apply optimized mount options while we're at it.
mkdir ./obj
if ! sudo mount $blkdev ./obj -o $mntopts; then
sudo dmesg | tail -n 20 # kernel log should have more details for mount failures
echo "::warning::Failed to remount $blkdev to ./obj with options: $mntopts"
return
fi

# ensure current user can access everything.
# later scripts assume they have recursive access to obj
sudo chown -R "$USER":"$USER" ./obj

# Exit from this script to avoid wasting time removing disk space,
# as we already have enough disk space in the alternative drive.
exit 0
fi
}



# Display initial disk space stats

AVAILABLE_INITIAL=$(getAvailableSpace)

printDF "BEFORE CLEAN-UP:"
echo ""

sufficientSpaceEarlyExit
checkAlternative

execAndMeasureSpaceChange cleanPackages "Unused packages"
execAndMeasureSpaceChange cleanDocker "Docker images"
execAndMeasureSpaceChange cleanSwap "Swap storage"
Expand Down
Loading