Free Docker and swap disk space (#838)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user