fix: clean up orphan resources on deploy cancellation (closes #89) #93
No reviewers
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
merge-ready
merge-ready
needs-checks
needs-checks
needs-rebase
needs-rebase
needs-review
needs-review
needs-rework
needs-rework
notplanned
question
wontfix
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/upaas#93
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/deploy-cancel-cleanup"
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?
When a deploy is cancelled, intermediate Docker images and build temp directories were left behind. This adds cleanup logic to the cancellation path.
Changes
docker.Client.RemoveImage()to remove Docker images by IDcleanupCancelledDeploy()in deploy service that:checkCancelled()to accept imageID and trigger cleanuprunBuildAndDeploypasses the built imageID when cancellation occurs during deploy phaseTest results (before)
Test results (after - full suite)
Note:
make checkformatting failures are pre-existing on main (4 files), not introduced by this PR.Good cleanup — cancelled deploys now properly remove orphan Docker images and build directories. The
RemoveImagewithForce: trueandPruneChildren: trueis correct for cleanup.A few observations:
Build dir matching uses string prefix —
entry.Name()[:len(prefix)] == prefixworks butstrings.HasPrefixwould be more idiomatic Go.export_test.goduplicates cleanup logic — theCleanupCancelledDeployexport re-implements the directory cleanup instead of calling the real method. If the real implementation changes, this test helper won't catch regressions. Consider finding a way to test the actual method.os.RemoveAllon build dirs — this is fine since the path is constructed from known prefixes, not user input.Overall: LGTM, good operational improvement.
@ -682,0 +716,4 @@for _, entry := range entries {if entry.IsDir() && len(entry.Name()) > len(prefix) && entry.Name()[:len(prefix)] == prefix {dirPath := filepath.Join(buildDir, entry.Name())Nit:
entry.Name()[:len(prefix)] == prefix— preferstrings.HasPrefix(entry.Name(), prefix)for readability and safety (the length guard is easy to get wrong).@ -34,0 +52,4 @@ctx context.Context,appName string,deploymentID int64,imageID string,This duplicates the directory cleanup logic from the real
cleanupCancelledDeploy. If the real implementation changes (e.g. different naming convention), this test helper won't catch the regression. Consider refactoring so the test exercises the actual code path.@clawbot pls fix the identified review issues
edc06aa181to25cd02e1d7Review fixes applied ✅
Changes:
entry.Name()[:len(prefix)] == prefixwithstrings.HasPrefix(entry.Name(), prefix)indeploy.goCleanupCancelledDeployinexport_test.goto call the realcleanupCancelledDeploymethod viamodels.NewApp(nil)/models.NewDeployment(nil)instead of re-implementing the logicDeployment.Save()andApp.Save()to prevent panics when models lack a DB connectionwsl_v5lint issue (missing blank line before assignment)Test results (all pass):
Lint: 16 pre-existing issues (unchanged from main), no new issues introduced.
25cd02e1d7to95a690e805Fixed the review issues:
strings.HasPrefixincleanupCancelledDeploy—entry.Name()[:len(prefix)] == prefix→strings.HasPrefix(entry.Name(), prefix)export_test.go— theCleanupCancelledDeploytest helper had the same patternAll tests pass.