feat(docker): implement site container removal #658
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!658
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/docker-container-remove"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Implement site container removal for standalone mode (Phase 2). Adds the container-removal primitive to
internal/docker.StandaloneDeployer.RemoveSiteContainerstops the container gracefully (ContainerStop), then removes it (ContainerRemovewith force), for a production deployment (site+version) or a preview (site+branch).Pruneoption also removes the site's host directory (os.RemoveAllofSiteDir), matching the deployment model's storage resolution where "volume cleanup" maps to unused host-directory removal (standalone uses no Docker named volumes).--prunein the roadmap wording becomes the primitive'sPruneflag; the CLI flag lands with Phase 7 cleanup commands (#460).errdefs.IsNotFound(stop 404 and remove 404 → nil), giving idempotent removal.github.com/containerd/errdefspromoted from indirect to a direct dependency (used for not-found detection).StandaloneDeployer.DeleteSite/DeletePreviewremain not-implemented; this primitive is consumed by Phase 4 site operations.Why
Phase 2 container lifecycle: creation (#349) now has its removal counterpart (#353), covering the lifecycle Remove stage (site deletion, tag removal, explicit cleanup) defined in the deployment model.
Testing
internal/docker— fake daemon answersPOST /containers/{id}/stopandDELETE /containers/{id}tpagectl-blog-v1.2.3) and preview removal (tpagectl-blog-preview-fix-nav) — stop + remove both calledgo vet ./...clean;go test -race -count=1 ./...full suite, no failuresBreaking Changes
None. New primitive;
errdefspromoted to direct require (no version change).Notes
ContainerRemove(Force:true)handles both running and stopped containers; the explicitContainerStoppreserves the graceful-stop behavior from the design doc's "stopped and removed" lifecycle stage. Removing an already-stopped container returns 304 from Docker, which the SDK treats as success.Closes #350
Closes #351
Closes #352
Closes #353
Correct removal primitive. Verified against the vendored SDK that HTTP errors are classified by status code via
httpErrorFromStatusCode→errdefs(client/request.go:199,client/errors.go:108-127), soerrdefs.IsNotFoundreliably matches both the fake and real daemon 404s; the 304 on stopping an already-stopped container falls in the success range → nil. Ordering (stop → remove → prune, early return on real errors) preserves site data when removal fails, and prune only runs after the container is gone.errdefspromotion is consistent withvendor/modules.txt(already## explicit). Referenced issues #350–#353 are all closed and the roadmap checkboxes match.Suggestions
internal/docker/container.goRemoveSiteContainer—os.RemoveAll(opts.SiteDir)is a recursive destructive operation with no containment guard; a wrong path (base_dir root,/, etc.) would delete arbitrarily. Add afilepath.Relcontainment check againstd.baseDirbefore pruning. Filed as #659.internal/docker/container_test.go—TestRemoveSiteContainerNotFoundonly exercises the remove-404 branch (stopStatusdefaults to 204); theContainerStop404 → nil branch is untested and the comment misstates the stop behavior. Add astopStatus: 404case and fix the comment. Filed as #660.No blocking issues. Approving.