refactor: call golang version of docker cleanup from shell

This ensures there is only a single implementation.
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-08-08 01:56:43 -04:00
1 parent 9f326b3f28
commit e1f1531d42
2 files changed
+5 -46

No files matched your search

+1 -46
View File
@@ -728,53 +728,8 @@ docker_cleanup() {
declare desc="cleans up all exited/dead containers and removes all dangling images" declare desc="cleans up all exited/dead containers and removes all dangling images"
declare APP="$1" FORCE_CLEANUP="$2" declare APP="$1" FORCE_CLEANUP="$2"
local DOKKU_APP_SKIP_CLEANUP local DOKKU_APP_SKIP_CLEANUP
source "$PLUGIN_AVAILABLE_PATH/config/functions"
if [[ "$FORCE_CLEANUP" != "true" ]]; then "$PLUGIN_CORE_AVAILABLE_PATH/common/common" --quiet docker-cleanup "$APP"
[[ -n "$APP" ]] && DOKKU_APP_SKIP_CLEANUP="$(config_get "$APP" DOKKU_SKIP_CLEANUP || true)"
if [[ -n "$DOKKU_SKIP_CLEANUP" ]] || [[ -n "$DOKKU_APP_SKIP_CLEANUP" ]]; then
dokku_log_info1 "DOKKU_SKIP_CLEANUP set. Skipping dokku cleanup"
return
fi
fi
dokku_log_info1 "Cleaning up..."
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
if [[ "$APP" == "--global" ]]; then
APP=""
fi
plugn trigger scheduler-docker-cleanup "$DOKKU_SCHEDULER" "$APP" "$FORCE_CLEANUP"
if [[ -n "$APP" ]]; then
# delete all non-running containers
# shellcheck disable=SC2046
"$DOCKER_BIN" container rm $("$DOCKER_BIN" container list --all --filter "status=exited" --filter "label=$DOKKU_CONTAINER_LABEL" --filter "label=com.dokku.app-name=$APP" --quiet) &>/dev/null || true
# delete all dead containers
# shellcheck disable=SC2046
"$DOCKER_BIN" container rm $("$DOCKER_BIN" container list --all --filter "status=dead" --filter "label=$DOKKU_CONTAINER_LABEL" --filter "label=com.dokku.app-name=$APP" --quiet) &>/dev/null || true
# delete danging images
# shellcheck disable=SC2046
"$DOCKER_BIN" image rm $("$DOCKER_BIN" image list --filter 'dangling=true' --filter "label=com.dokku.app-name=$APP" --quiet) &>/dev/null || true
# delete unused images
"$DOCKER_BIN" image prune --all --filter "label=com.dokku.app-name=$APP" --force &>/dev/null || true
else
# delete all non-running containers
# shellcheck disable=SC2046
"$DOCKER_BIN" container rm $("$DOCKER_BIN" container list --all --filter "status=exited" --filter "label=$DOKKU_CONTAINER_LABEL" --quiet) &>/dev/null || true
# delete all dead containers
# shellcheck disable=SC2046
"$DOCKER_BIN" container rm $("$DOCKER_BIN" container list --all --filter "status=dead" --filter "label=$DOKKU_CONTAINER_LABEL" --quiet) &>/dev/null || true
# delete danging images
# shellcheck disable=SC2046
"$DOCKER_BIN" image rm $("$DOCKER_BIN" image list --filter 'dangling=true' --quiet) &>/dev/null || true
fi
} }
get_available_port() { get_available_port() {
+4
View File
@@ -19,6 +19,10 @@ func main() {
var err error var err error
switch cmd { switch cmd {
case "docker-cleanup":
appName := flag.Arg(1)
force := common.ToBool(flag.Arg(2))
err = common.DockerCleanup(appName, force)
case "is-deployed": case "is-deployed":
appName := flag.Arg(1) appName := flag.Arg(1)
if !common.IsDeployed(appName) { if !common.IsDeployed(appName) {