Merge pull request 'Clean up Docker container when deleting an app (closes #2)' (#7) from clawbot/upaas:fix/issue-2 into main
Reviewed-on: #7
This commit is contained in:
commit
79a3165f90
@ -267,6 +267,29 @@ func (h *Handlers) HandleAppDelete() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop and remove the Docker container before deleting the DB record
|
||||||
|
containerInfo, containerErr := h.docker.FindContainerByAppID(request.Context(), appID)
|
||||||
|
if containerErr == nil && containerInfo != nil {
|
||||||
|
if containerInfo.Running {
|
||||||
|
stopErr := h.docker.StopContainer(request.Context(), containerInfo.ID)
|
||||||
|
if stopErr != nil {
|
||||||
|
h.log.Error("failed to stop container during app deletion",
|
||||||
|
"error", stopErr, "app", application.Name,
|
||||||
|
"container", containerInfo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeErr := h.docker.RemoveContainer(request.Context(), containerInfo.ID, true)
|
||||||
|
if removeErr != nil {
|
||||||
|
h.log.Error("failed to remove container during app deletion",
|
||||||
|
"error", removeErr, "app", application.Name,
|
||||||
|
"container", containerInfo.ID)
|
||||||
|
} else {
|
||||||
|
h.log.Info("removed container during app deletion",
|
||||||
|
"app", application.Name, "container", containerInfo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deleteErr := application.Delete(request.Context())
|
deleteErr := application.Delete(request.Context())
|
||||||
if deleteErr != nil {
|
if deleteErr != nil {
|
||||||
h.log.Error("failed to delete app", "error", deleteErr)
|
h.log.Error("failed to delete app", "error", deleteErr)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user