From 9a0454d9c137c09b1acf81c906f6b3a4870fd28b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 24 Jul 2026 16:52:46 +0200 Subject: [PATCH] Free Docker and swap disk space (#838) --- cleanup-disk/README.md | 8 ++++++-- cleanup-disk/action.yml | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cleanup-disk/README.md b/cleanup-disk/README.md index 723e2bf..70e630a 100644 --- a/cleanup-disk/README.md +++ b/cleanup-disk/README.md @@ -2,7 +2,7 @@ # ๐Ÿงน Disk Space Cleanup Action -Cleans up disk space on Ubuntu GitHub Actions runners by removing unnecessary tool caches and swap space. Frees up ~19GB total space. +Cleans up disk space on Ubuntu GitHub Actions runners by removing unnecessary tool caches, Docker images, and swap space. ## ๐Ÿš€ Usage @@ -10,6 +10,9 @@ Cleans up disk space on Ubuntu GitHub Actions runners by removing unnecessary to Add as early step in jobs requiring disk space: +> [!IMPORTANT] +> Run cleanup before pulling or building Docker images because it removes all images unused by containers. + ```yaml steps: - uses: ultralytics/actions/cleanup-disk@main @@ -57,7 +60,8 @@ steps: ## ๐Ÿ—‘๏ธ What Gets Cleaned - `/opt/hostedtoolcache` - Tool cache (~15GB) -- `/swapfile` - Swap space (~4GB) +- Unused Docker images +- `/swapfile` or `/mnt/swapfile` - Swap space (~4GB) ## ๐Ÿ’ก When to Use diff --git a/cleanup-disk/action.yml b/cleanup-disk/action.yml index e14592b..72c3012 100644 --- a/cleanup-disk/action.yml +++ b/cleanup-disk/action.yml @@ -2,7 +2,7 @@ name: "Disk Space Cleanup" author: "Ultralytics" -description: "Cleans up disk space by removing unnecessary tool caches and swap space" +description: "Cleans up disk space by removing unnecessary tool caches, Docker images, and swap space" runs: using: "composite" steps: @@ -13,21 +13,24 @@ runs: df -h / echo "::endgroup::" - echo "::group::Remove Tool Cache and Swap" + echo "::group::Remove Tool Cache, Docker Images, and Swap" toolcache_pid="" if [ -e /opt/hostedtoolcache ]; then # Remove tool cache to free up ~15GB of space per https://github.com/ultralytics/ultralytics/pull/15848 rm -rf /opt/hostedtoolcache & toolcache_pid=$! fi + docker image prune --all --force & + docker_pid=$! # Remove swap space to free up ~4GB - if [ -f /swapfile ]; then + if [ -f /swapfile ] || [ -f /mnt/swapfile ]; then sudo swapoff -a - sudo rm -f /swapfile + sudo rm -f /swapfile /mnt/swapfile fi if [ -n "$toolcache_pid" ]; then wait "$toolcache_pid" || true fi + wait "$docker_pid" || true echo "::endgroup::" echo "::group::Disk Space After Cleanup"