Skip to content

fix(ci): nuke all docker state on self-hosted runners - #6049

Merged
renecannao merged 1 commit into
GH-Actionsfrom
fix/ci-nuke-all-docker-state
Aug 13, 2026
Merged

fix(ci): nuke all docker state on self-hosted runners#6049
renecannao merged 1 commit into
GH-Actionsfrom
fix/ci-nuke-all-docker-state

Conversation

@renecannao

@renecannao renecannao commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Self-hosted runners reuse the working directory serially across CI-builds matrix legs. A cancelled dockerized build leaks its Compose stack, which keeps writing root-owned files into the bind-mounted checkout (./:/opt/proxysql) while the next job starts.

The existing cleanup ("Stop stale Docker Compose project") was a no-op:

  • It iterated CI_BUILD_COMPOSE_PROJECTS: 'debian12 ubuntu22 ubuntu24', filtering on label com.docker.compose.project=<bare-dist-name>.
  • But the Makefile names each project <BLD_NAME>-<GITVERSION> (e.g. ubuntu22-tap-3.0.11-502-gd8bdd5a) — see Makefile:519. The bare distribution name is the IMG_NAME, not the Compose project name.

So the leaked writer container was never matched, chown -R succeeded but the live container re-created root-owned files ~1.6s later, and the contamination guard aborted the job. This produced the recurring "workspace still contains files not owned by the runner" failures.

Change

Nuke all docker state on self-hosted runners at both cleanup points:

  • Preflight ("Nuke all docker state (self-hosted)") — before checkout.
  • Post-job ("Nuke all docker state (leave runner clean)") — always().

Both steps now remove all containers (docker rm -f on everything running), all volumes (docker volume prune -af), and all networks (docker network prune -af). No name guessing, no filter — nothing dockerized survives into the next job.

Also removed the now-dead CI_BUILD_COMPOSE_PROJECTS env var.

Notes

  • Workspace ownership reclaim and the Makefile bind-mount are intentionally untouched.
  • Follow-up (out of scope): stop bind-mounting the checkout into build containers entirely, so root-owned files never touch the host workspace and the contamination guard becomes unnecessary.

Summary by cubic

Wipes all Docker state on self-hosted runners before checkout and after each job to stop root-owned file contamination from leaked Compose stacks. Old behavior: filtered cleanup by bare distribution name and missed projects named <BLD_NAME>-; containers survived into the next job. New behavior: unconditional removal of all containers, volumes, and networks on trusted self-hosted runners.

  • Runs in two places: preflight (before checkout) and post-job (always()), gated by trusted and self-hosted runner checks.
  • Removes all containers (docker rm -f $(docker ps -aq)), prunes all volumes and networks; images are not pruned.
  • Deletes now-dead env var CI_BUILD_COMPOSE_PROJECTS.
  • Leaves workspace ownership repair and the Makefile bind-mount unchanged.
  • Required: Do not rely on persistent Docker containers, volumes, or networks on self-hosted runners; any such state will be removed between jobs.

Written for commit 4408aae. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Chores
    • Improved automated build cleanup to remove leftover containers, volumes, and networks from trusted build environments.
    • Updated cleanup behavior to run reliably after build jobs and when cached dependencies are unavailable.
    • Removed an unused build configuration setting, helping simplify the continuous integration process.

The project-name-filtered cleanup was a no-op: the Makefile names each
Compose project <BLD_NAME>-<GITVERSION> (e.g. ubuntu22-tap-3.0.11-502-gd8bdd5a),
not the bare distribution names in CI_BUILD_COMPOSE_PROJECTS, so leaked build
containers survived into the next job and kept writing root-owned files into
the bind-mounted checkout. Remove the dead env var and stop/take down ALL
containers, volumes and networks on self-hosted runners, both preflight and
post-job.
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d38203b4-57e6-46dc-889a-4d5cfdfc14eb

📥 Commits

Reviewing files that changed from the base of the PR and between 68c561b and 4408aae.

📒 Files selected for processing (1)
  • .github/workflows/ci-builds.yml
📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Gitar
🔇 Additional comments (1)
.github/workflows/ci-builds.yml (1)

156-178: LGTM!

Also applies to: 665-683


📝 Walkthrough

Walkthrough

The CI workflow removes project-specific Docker Compose cleanup. It now deletes all Docker containers, volumes, and networks before eligible self-hosted builds and after jobs. Post-job cleanup runs for every job outcome on trusted runners.

Changes

CI Docker cleanup

Layer / File(s) Summary
Pre-build Docker cleanup
.github/workflows/ci-builds.yml
The workflow removes CI_BUILD_COMPOSE_PROJECTS. After cache misses, it unconditionally removes all Docker containers, volumes, and networks before self-hosted builds.
Post-job Docker cleanup
.github/workflows/ci-builds.yml
The workflow unconditionally removes all Docker containers, volumes, and networks after jobs. Cleanup retains always() execution on trusted self-hosted runners.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Mergeability Score: ⚪ Minimal · up to 4408a

This is a localized CI workflow cleanup change with no actionable merge-blocking risk identified; it is merge-ready after normal checks.

Possibly related PRs

Poem

A rabbit hops through Docker’s den,
Clearing containers, networks, then.
Volumes vanish, clean and bright,
Before builds start and after night.
Trusted runners rest just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the Docker cleanup change on self-hosted CI runners.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ci-nuke-all-docker-state

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.

@gitar-bot

gitar-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Removes all Docker containers, volumes, and networks on self-hosted runners at preflight and post-job to prevent workspace contamination from leaked Compose stacks. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@renecannao
renecannao merged commit 6473e5c into GH-Actions Aug 13, 2026
2 of 3 checks passed

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4408aae64e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +171 to +173
containers="$(docker ps -aq)"
if [ -n "${containers}" ]; then
docker rm -f ${containers}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Limit cleanup to containers owned by this workflow

On any self-hosted VM whose Docker daemon contains a persistent service or state from another workflow, docker ps -aq selects those containers too and docker rm -f forcibly destroys them; the following volume/network prunes can then delete their unused state. This runs both before cache-miss builds and again under always(), despite the checked-in cleanup design explicitly requiring unrelated runner workloads to remain untouched and prohibiting broad Docker pruning (docs/superpowers/specs/2026-08-11-ci-compose-workspace-cleanup-design.md:15-17,27-36), so the cleanup needs to identify only this workflow's Compose resources.

Useful? React with 👍 / 👎.

@sonarqubecloud

Copy link
Copy Markdown

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