This utility installs a daily systemd timer on self-hosted GitLab CI/CD runners that automatically prunes accumulated Docker images, containers, volumes, and build cache, then runs fstrim to reclaim space on SSDs. Without periodic cleanup, cached Docker layers will slowly fill the runner's drive.
What It Does
- Runs
docker system prune -af --volumesdaily to remove all unused images, stopped containers, dangling build cache, and unused volumes. - Runs
fstrim -avafterwards to inform the SSD which blocks are free. - Logs all output to the systemd journal for easy auditing.
Automated Installation
To install, run the following command on your GitLab runner. This will download and execute the installation script with sudo privileges.
Using curl:
curl -sL https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/install.sh | sudo bash
Using wget:
wget -qO- https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/install.sh | sudo bash
Installation Script Content:
Automated Uninstallation
To remove the cleanup timer and script, run the corresponding command below.
Using curl:
curl -sL https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/uninstall.sh | sudo bash
Using wget:
wget -qO- https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/uninstall.sh | sudo bash
Uninstallation Script Content:
Monitoring and Verification
After installation, you can check the timer status and view cleanup logs.
Check Timer Status
sudo systemctl status gitlab-runner-cleanup.timer
View Logs
sudo journalctl -u gitlab-runner-cleanup.service -f
Run Cleanup Immediately
sudo systemctl start gitlab-runner-cleanup.service