Skip to content

Add docker cleanup script#492

Open
DGoel1602 wants to merge 1 commit into
mainfrom
docker-coolify-cleanup
Open

Add docker cleanup script#492
DGoel1602 wants to merge 1 commit into
mainfrom
docker-coolify-cleanup

Conversation

@DGoel1602

@DGoel1602 DGoel1602 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Why

I HATE PINGS

What

Add a bash script that safely cleans up stale images, networks, containers, old cache, but no volumes. Added docs on how to use it too.

PS: This is all codexed please actually review

Test Plan

Tested with running active forge containers, without them, with both, different amounts and types of images, and ensured expected output in all cases.

Checklist

  • Database: No schema changes, OR I ran pnpm db:generate and committed the generated files in packages/db/drizzle/
  • Environment Variables: No environment variables changed, OR I have contacted the Development Lead to modify them on Coolify BEFORE merging.

Summary by CodeRabbit

  • New Features

    • Added a host cleanup utility that removes stale Docker containers, images, networks, and build caches based on a configurable retention period.
    • Added safeguards to prevent overlapping cleanup runs and provides before-and-after disk usage reporting.
    • Docker volumes are preserved during cleanup.
  • Documentation

    • Added deployment guidance for scheduling cleanup on Coolify observer and worker hosts, including retention examples and operational responsibilities.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds ops/coolify-docker-cleanup.sh to prune aged Docker resources and caches with configurable retention and concurrency protection. Updates architecture documentation with scheduled Coolify host deployment guidance and clarifies that Docker volumes remain untouched.

Changes

Coolify Docker cleanup

Layer / File(s) Summary
Cleanup configuration and guarded entrypoint
ops/coolify-docker-cleanup.sh
Defines cleanup defaults and overrides, CLI help and parsing, Docker availability validation, logging, and non-concurrent execution through flock.
Docker pruning and host scheduling guidance
ops/coolify-docker-cleanup.sh, docs/ARCHITECTURE.md
Reports disk usage, prunes aged containers, images, networks, classic builder cache, and optional Buildx cache, while documenting scheduled execution on Coolify observer and worker nodes and the exclusion of volumes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CoolifyHost
  participant CleanupScript as coolify-docker-cleanup.sh
  participant LockFile as flock lock
  participant DockerCLI
  CoolifyHost->>CleanupScript: Run with retention window
  CleanupScript->>LockFile: Acquire exclusive non-blocking lock
  CleanupScript->>DockerCLI: Report usage and prune aged resources
  DockerCLI-->>CleanupScript: Return cleanup results
  CleanupScript-->>CoolifyHost: Log completion without pruning volumes
Loading

Suggested labels: Documentation, Feature, Minor

🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes the change, but it does not start with the required issue number in brackets. Prefix the title with an issue key like "[#123]" and keep the description concise, e.g. "[#123] Add docker cleanup script".
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No Hardcoded Secrets ✅ Passed Scanned the touched docs and new shell script; no hardcoded API keys, passwords, tokens, or secrets appear in literals or the patch.
Validated Env Access ✅ Passed No raw process.env usage appears in the PR diff; only docs and a Bash script were added, so the env-access rule is not violated.
No Typescript Escape Hatches ✅ Passed No TypeScript files were changed, and the touched files contain no 'any', ts-ignore, ts-expect-error, or non-null assertions.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docker-coolify-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
ops/coolify-docker-cleanup.sh (1)

3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an ERR trap for better observability.

With set -e, the script exits immediately on the first failing command, but no cleanup-specific log message is emitted. For a scheduled job, adding an ERR trap makes failures easy to grep in logs and alerts.

♻️ Suggested ERR trap
 set -euo pipefail
+
+trap 'log "cleanup failed unexpectedly (exit code: $?)"' ERR
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ops/coolify-docker-cleanup.sh` at line 3, Add an ERR trap immediately after
the strict-shell settings in the cleanup script, logging a clear
cleanup-specific failure message when any command fails. Include the failing
command context and exit status in the log while preserving the existing set
-euo pipefail behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@ops/coolify-docker-cleanup.sh`:
- Line 3: Add an ERR trap immediately after the strict-shell settings in the
cleanup script, logging a clear cleanup-specific failure message when any
command fails. Include the failing command context and exit status in the log
while preserving the existing set -euo pipefail behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3de6c42c-32d3-48ed-9b7f-3357ca4e1a3b

📥 Commits

Reviewing files that changed from the base of the PR and between b424a23 and ad9a0c0.

📒 Files selected for processing (2)
  • docs/ARCHITECTURE.md
  • ops/coolify-docker-cleanup.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant