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
2021-08-08 01:56:43 -04:00
parent 9f326b3f28
commit e1f1531d42
2 changed files with 5 additions and 46 deletions

View File

@@ -728,53 +728,8 @@ docker_cleanup() {
declare desc="cleans up all exited/dead containers and removes all dangling images"
declare APP="$1" FORCE_CLEANUP="$2"
local DOKKU_APP_SKIP_CLEANUP
source "$PLUGIN_AVAILABLE_PATH/config/functions"
if [[ "$FORCE_CLEANUP" != "true" ]]; then
[[ -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
"$PLUGIN_CORE_AVAILABLE_PATH/common/common" --quiet docker-cleanup "$APP"
}
get_available_port() {

View File

@@ -19,6 +19,10 @@ func main() {
var err error
switch cmd {
case "docker-cleanup":
appName := flag.Arg(1)
force := common.ToBool(flag.Arg(2))
err = common.DockerCleanup(appName, force)
case "is-deployed":
appName := flag.Arg(1)
if !common.IsDeployed(appName) {