From 87668209743a73446a4d32eceb4132cc71abcef4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 22 May 2021 15:37:17 -0400 Subject: [PATCH] fix: always retire deployment task containers Without this, the normal cleanup routine would not remove the containers, and removal would require a manual call to 'dokku cleanup'. --- plugins/app-json/functions.go | 11 ++++++++++- .../scheduler-docker-local/scheduler-register-retired | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/app-json/functions.go b/plugins/app-json/functions.go index 063185440..44175cc5a 100644 --- a/plugins/app-json/functions.go +++ b/plugins/app-json/functions.go @@ -154,6 +154,13 @@ func getDokkuAppShell(appName string) string { return shell } +func cleanupDeploymentContainer(appName string, containerID string, phase string) error { + if phase != "predeploy" { + os.Setenv("DOKKU_SKIP_IMAGE_RETIRE", "true") + } + return common.PlugnTrigger("scheduler-register-retired", []string{appName, containerID}...) +} + func executeScript(appName string, image string, imageTag string, phase string) error { phaseName := phase if phase == "heroku.postdeploy" { @@ -255,6 +262,8 @@ func executeScript(appName string, image string, imageTag string, phase string) return fmt.Errorf("Failed to create %s execution container: %s", phase, err.Error()) } + defer cleanupDeploymentContainer(appName, containerID, phase) + if !waitForExecution(containerID) { common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9])) common.LogVerboseQuietContainerLogs(containerID) @@ -302,7 +311,7 @@ func executeScript(appName string, image string, imageTag string, phase string) return fmt.Errorf("Commiting of '%s' to image failed: %s", phase, command) } - return common.PlugnTrigger("scheduler-register-retired", []string{appName, containerID}...) + return nil } func getEntrypointFromImage(image string) (string, error) { diff --git a/plugins/scheduler-docker-local/scheduler-register-retired b/plugins/scheduler-docker-local/scheduler-register-retired index 2cdb48da8..eb26b2951 100755 --- a/plugins/scheduler-docker-local/scheduler-register-retired +++ b/plugins/scheduler-docker-local/scheduler-register-retired @@ -9,7 +9,13 @@ trigger-scheduler-docker-local-scheduler-register-retired() { declare APP="$1" CONTAINER_ID="$2" WAIT="${3:-60}" local IMAGE_ID - IMAGE_ID="$("$DOCKER_BIN" container inspect "$CONTAINER_ID" --format "{{.Image}}" 2>/dev/null | cut -d: -f2 || true)" + if [[ -z "$CONTAINER_ID" ]]; then + return + fi + + if [[ "$DOKKU_SKIP_IMAGE_RETIRE" != "true" ]]; then + IMAGE_ID="$("$DOCKER_BIN" container inspect "$CONTAINER_ID" --format "{{.Image}}" 2>/dev/null | cut -d: -f2 || true)" + fi fn-scheduler-docker-local-register-retired "container" "$APP" "$CONTAINER_ID" "$WAIT" if [[ -n "$IMAGE_ID" ]]; then