From 115b93907141b964cd92e10a6769ac4c4e7489b2 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 29 Jul 2016 04:51:36 -0400 Subject: [PATCH 1/2] Cleanup deploying image name retrieval Rather than try to shim in the logic from the existing get_app_image_name method, simply duplicate it to make the method name more readable --- plugins/common/functions | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 459f7c236..9bda9e98b 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -168,27 +168,21 @@ get_app_image_repo() { } get_deploying_app_image_name() { - declare desc="return deployed image identifier for a given app, tag tuple. validate if tag is presented" - local APP="$1"; local IMAGE_TAG="$2"; - [[ -z "$APP" ]] && dokku_log_fail "(get_app_image_name) APP must not be null" + declare desc="return deploying image identifier for a given app, tag tuple. validate if tag is presented" + local APP="$1"; local IMAGE_TAG="$2"; IMAGE_REPO="$3" + [[ -z "$APP" ]] && dokku_log_fail "(get_deploying_app_image_name) APP must not be null" - local IMAGE_REPO="" local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP") local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP") local NEW_IMAGE_REPO=$(plugn trigger deployed-app-image-repo "$APP") - if [[ -n "$NEW_IMAGE_TAG" ]]; then - IMAGE_TAG="$NEW_IMAGE_TAG" - fi + [[ -n "$NEW_IMAGE_REPO" ]] && IMAGE_REPO="$NEW_IMAGE_REPO" + [[ -n "$NEW_IMAGE_TAG" ]] && IMAGE_TAG="$NEW_IMAGE_TAG" + [[ -z "$IMAGE_REPO" ]] && IMAGE_REPO=$(get_app_image_repo "$APP") + [[ -z "$IMAGE_TAG" ]] && IMAGE_TAG="latest" - if [[ -n "$NEW_IMAGE_REPO" ]]; then - IMAGE_REPO="$NEW_IMAGE_REPO" - fi - - local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG" "$IMAGE_REPO") - if [[ -n "$IMAGE_REMOTE_REPOSITORY" ]]; then - IMAGE="${IMAGE_REMOTE_REPOSITORY}${IMAGE}" - fi + local IMAGE="${IMAGE_REMOTE_REPOSITORY}${IMAGE_REPO}:${IMAGE_TAG}" + verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found" echo "$IMAGE" } @@ -385,7 +379,7 @@ is_deployed() { fi } -is_container_running () { +is_container_running() { declare desc="return 0 if given docker container id is in running state" local CID=$1 local CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true) @@ -397,7 +391,7 @@ is_container_running () { fi } -is_container_status () { +is_container_status() { declare desc="return 0 if given docker container id is in given state" local CID=$1 local TEMPLATE="{{.State.$2}}" From 2474c87bbd83286d628557e8bfed548b99bd5c56 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 29 Jul 2016 12:49:29 -0400 Subject: [PATCH 2/2] Pull the deploying app image name where necessary All of these commands should execute against the image that is in use versus the "latest" that dokku provides the system with. --- plugins/apps/pre-delete | 2 +- plugins/config/docker-args-deploy | 2 +- plugins/enter/subcommands/default | 2 +- plugins/nginx-vhosts/functions | 2 +- plugins/ps/functions | 4 ++-- plugins/repo/subcommands/purge-cache | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index 086f2714a..d1fc39ed5 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -5,7 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" apps_pre_delete() { declare desc="apps pre-delete plugin trigger" local trigger="apps_pre_delete" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG"); local CACHE_DIR="$DOKKU_ROOT/$APP/cache" + local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG"); local CACHE_DIR="$DOKKU_ROOT/$APP/cache" verify_app_name "$APP" if [[ -d $CACHE_DIR ]]; then diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 8d2ab297e..cd89cc14d 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -6,7 +6,7 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions" config_docker_args() { declare desc="config docker-args plugin trigger" local trigger="$0 config_docker_args" - local STDIN=$(cat); local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local STDIN=$(cat); local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE" verify_app_name "$APP" diff --git a/plugins/enter/subcommands/default b/plugins/enter/subcommands/default index 980bb2d33..9d2a23da1 100755 --- a/plugins/enter/subcommands/default +++ b/plugins/enter/subcommands/default @@ -5,7 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" enter_default_cmd() { declare desc="enters running app container of specified proc type" local cmd="enter" - local APP="$2"; local CONTAINER_TYPE="$3"; local IMAGE_TAG=$(get_running_image_tag "$APP"); local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local APP="$2"; local CONTAINER_TYPE="$3"; local IMAGE_TAG=$(get_running_image_tag "$APP"); local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") verify_app_name "$APP" local AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP")) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 11dba3d0a..7806d66c2 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -141,7 +141,7 @@ get_custom_nginx_template() { local APP="$1"; verify_app_name "$APP" local DESTINATION="$2" local IMAGE_TAG="$(get_running_image_tag "$APP")" - local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local NGINX_TEMPLATE_NAME="nginx.conf.sigil" copy_from_image "$IMAGE" "$NGINX_TEMPLATE_NAME" "$DESTINATION" 2>/dev/null || true diff --git a/plugins/ps/functions b/plugins/ps/functions index 5a9949431..cf21f5ac8 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -15,7 +15,7 @@ extract_procfile() { declare desc="extracts procfile from app image" local APP="$1" local IMAGE_TAG="$2" - local IMAGE="$(get_app_image_name "$APP" "$IMAGE_TAG")" + local IMAGE="$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")" local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" verify_app_name "$APP" @@ -38,7 +38,7 @@ remove_procfile() { generate_scale_file() { declare desc="generates DOKKU_SCALE file" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG"); local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG"); local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" verify_app_name "$APP" diff --git a/plugins/repo/subcommands/purge-cache b/plugins/repo/subcommands/purge-cache index 45e80feb4..4bebd43a0 100755 --- a/plugins/repo/subcommands/purge-cache +++ b/plugins/repo/subcommands/purge-cache @@ -9,7 +9,7 @@ repo_purge_cache() { local APP="$2"; verify_app_name "$APP" - local IMAGE=$(get_app_image_name "$APP"); local CACHE_DIR="$DOKKU_ROOT/$APP/cache" + local IMAGE=$(get_deploying_app_image_name "$APP"); local CACHE_DIR="$DOKKU_ROOT/$APP/cache" if [[ -d $CACHE_DIR ]]; then docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true