Skip to content

Commit 33c1bf4

Browse files
committed
CI: use alternative disks if available
cleaning up disk space takes a lot of time
1 parent a8664a1 commit 33c1bf4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/ci/docker/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ docker \
347347
--env DEPLOY \
348348
--env DEPLOY_ALT \
349349
--env CI \
350+
--env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
350351
--env GITHUB_ACTIONS \
351352
--env GITHUB_REF \
352353
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,58 @@ cleanSwap() {
247247
free -h
248248
}
249249

250+
# Try to find a different drive to put our data on so we don't need to run cleanup.
251+
# The availability of the disks we're probing isn't guaranteed,
252+
# so this is opportunistic.
253+
checkAlternative() {
254+
local gha_alt_disk="/mnt"
255+
256+
# we need ~50GB of space
257+
local space_target_kb=$((50 * 1024 * 1024))
258+
local available_space_kb=$(df -k "$gha_alt_disk" --output=avail | tail -n 1)
259+
260+
# ignore-tidy-linelength
261+
local mntopts="defaults,discard,journal_async_commit,barrier=0,noauto_da_alloc,lazytime,data=writeback"
262+
263+
# GHA has a 2nd disk mounted at /mnt that is almost empty.
264+
if mountpoint "$gha_alt_disk" && [ "$available_space_kb" -ge "$space_target_kb" ]; then
265+
local blkdev=$(df -k "$gha_alt_disk" --output=source | tail -n 1)
266+
echo "Sufficient space available on $blkdev mounted at $gha_alt_disk"
267+
sudo swapoff -a || true
268+
sudo umount "$gha_alt_disk"
269+
mkdir ./obj
270+
# remount with O_EATMYDATA while we're at it
271+
sudo mount $blkdev ./obj -o $mntopts || (sudo dmesg | tail -n 20 ; exit 1)
272+
sudo chown -R "$USER":"$USER" ./obj
273+
274+
exit 0
275+
fi
276+
277+
# ephemeral NVMe drives on AWS
278+
for dev in /dev/nvme*n1; do
279+
if [ -b "$dev" ] && [ "$(mount | grep "$dev" | wc -l)" -eq 0 ]; then
280+
echo "Found unused block device $dev, creating filesystem"
281+
sudo mkfs.ext4 -E lazy_itable_init=1,lazy_journal_init=1 "$dev"
282+
mkdir ./obj
283+
sudo mount "$dev" ./obj -o $mntopts
284+
sudo chown -R "$USER":"$USER" ./obj
285+
286+
exit 0
287+
fi
288+
done
289+
}
290+
291+
292+
250293
# Display initial disk space stats
251294

252295
AVAILABLE_INITIAL=$(getAvailableSpace)
253296

254297
printDF "BEFORE CLEAN-UP:"
255298
echo ""
299+
300+
checkAlternative
301+
256302
execAndMeasureSpaceChange cleanPackages "Unused packages"
257303
execAndMeasureSpaceChange cleanDocker "Docker images"
258304
execAndMeasureSpaceChange cleanSwap "Swap storage"

0 commit comments

Comments
 (0)