Merge pull request #2822 from dokku/refactor-cleanup

refactor: allow skipping cleanup on a per-application basis
This commit is contained in:
Jose Diaz-Gonzalez
2017-07-02 21:22:54 -06:00
committed by GitHub
3 changed files with 17 additions and 8 deletions

View File

@@ -105,7 +105,7 @@ The following list config variables have special meaning and can be set in a var
| `DOKKU_NGINX_SSL_PORT` | automatically assigned | `dokku config:set` | |
| `DOKKU_PROXY_PORT_MAP` | automatically assigned | `dokku proxy:ports-add` <br /> `dokku proxy:ports-remove`, `dokku proxy:ports-clear` | |
| `DOKKU_SKIP_ALL_CHECKS` | none | `dokku config:set` | |
| `DOKKU_SKIP_CLEANUP` | | `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | |
| `DOKKU_SKIP_CLEANUP` | | `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | When a deploy is triggered, if this is set to a non-empty value, then old docker containers and images will not be removed. |
| `DOKKU_SKIP_DEFAULT_CHECKS` | | `dokku config:set` | |
| `DOKKU_SKIP_DEPLOY` | | `dokku config:set` | |
| `DOKKU_WAIT_TO_RETIRE` | `60` | `dokku config:set` | After a successful deploy, the grace period given to old containers before they are stopped/terminated. This is useful for ensuring completion of long-running http connections. |

View File

@@ -6,7 +6,7 @@ dokku_cleanup_cmd(){
declare desc="cleans up old deployment cruft"
local cmd="cleanup"
docker_cleanup
docker_cleanup "$APP" "true"
}

View File

@@ -746,12 +746,8 @@ dokku_receive() {
source "$PLUGIN_AVAILABLE_PATH/config/functions"
local APP="$1"; local IMAGE=$(get_app_image_name "$APP"); local IMAGE_SOURCE_TYPE="$2"; local TMP_WORK_DIR="$3"
if [[ -z "$DOKKU_SKIP_CLEANUP" ]]; then
dokku_log_info1 "Cleaning up..."
docker_cleanup
else
dokku_log_info1 "DOKKU_SKIP_CLEANUP set. Skipping dokku cleanup"
fi
local DOKKU_SKIP_CLEANUP="$(config_get "$APP" DOKKU_SKIP_CLEANUP || true)"
docker_cleanup "$APP"
dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..."
config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE" &> /dev/null
dokku_build "$APP" "$IMAGE_SOURCE_TYPE" "$TMP_WORK_DIR"
@@ -760,6 +756,19 @@ dokku_receive() {
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
if [[ "$FORCE_CLEANUP" != "true" ]]; then
[[ -z "$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..."
# delete all non-running containers
# shellcheck disable=SC2046
docker rm $(docker ps -a -f "status=exited" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true