8000 fix(sandbox): release old images after any replacement, never a named one by ID by geminixiang · Pull Request #177 · geminixiang/mikan · GitHub
[go: up one dir, main page]

Skip to content

fix(sandbox): release old images after any replacement, never a named one by ID - #177

Merged
geminixiang merged 1 commit into
mainfrom
fix/sandbox-image-cleanup
Oct 11, 2026
Merged

geminixiang merged 1 commit into
mainfrom
fix/sandbox-image-cleanup

Conversation

@geminixiang
Copy link
Copy Markdown
Owner

為什麼要改

#175 上線後,在 prod(1.4.0-beta.0)的 log 裡發現兩個問題:

  1. 舊 image 不會被清掉:prod 前兩個換新的 office,log 記錄的原因是 network 和 binds,不是 image;而 33 個用 :latest 的 container,網路 label 全部是舊格式。原本只有原因是 image 時才會清理舊 image,所以這些舊 image 永遠不會被清掉。
  2. 會誤刪使用者自己的 image:在 Docker 上,用 image ID 執行 rmi 時,只要那個 image 只剩一個名稱,Docker 就會直接刪除,不會拒絕。feat(sandbox): keep offices on the sandbox image of the running mikan #175 的說明和測試以為「只要還有名稱,引擎就會拒絕」,這個假設是錯的。所以使用者自己 build、只有一個 tag 的 image(例如 acme/sandbox:dev),在最後一個 office 換掉之後就會被刪除。

改了什麼

情況 之前 之後
container 因為 network、binds 等原因被換掉,而且舊 image 和現在設定的不同 不清理 清理
舊 image 和現在設定的相同 不清理 不清理
舊 container 用的是官方 image(mikan-sandbox:<舊版>) 用名稱 rmi 不變
其他情況 直接用 ID 執行 rmi 先確認這個 image 已經沒有任何名稱才用 ID 刪除;還有名稱就不動

驗證

真實 Docker 引擎 eval(.workspace/image-cleanup/docker.eval.ts):

案例 main 這個 PR
D1 使用者自己的 image(只有一個名稱),最後一個 office 換掉後 ❌ 被刪除 ✅ 保留
D2 舊的官方 image,最後一個 office 換掉後 刪除 刪除

單元測試(先寫測試,修改前會失敗):

  • 因網路設定不同而換掉的 office,也會清理舊的官方 image。
  • 還有名稱的 image,不會用 ID 刪除。

本機 gate:全部通過,共 2,110 個測試。

另外會觸發 slack-e2e.yml,因為這個 PR 改到 daemon 建立 container 的路徑。

研究文件、ADR 0023 和 sandbox README 都已經更正。

… one by ID

Production replaced its first offices for network and binds drift, and
every container on the previous :latest carries an older network label,
so removal, which ran only for image drift, would never have released
those images. A replacement now removes the old image whenever it
differs from the configured one.

Docker deletes an image by ID even while one name still points to it, so
an operator's own image left behind by an office was deleted. An image
is now removed by ID only when no name points to it.
@geminixiang
geminixiang merged commit 3d421eb into main Oct 11, 2026
6 checks passed
@geminixiang
geminixiang deleted the fix/sandbox-image-cleanup branch October 11, 2026 14:30
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

0