diff --git a/plugins/apps/post-delete b/plugins/apps/post-delete index 66b4f40f8..5c71e01a2 100755 --- a/plugins/apps/post-delete +++ b/plugins/apps/post-delete @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -APP="$1" +source "$PLUGIN_PATH/common/functions" +APP="$1"; IMAGE_REPO=$(get_app_image_repo $APP) [[ -n $APP ]] && rm -r "$DOKKU_ROOT/$APP" > /dev/null @@ -8,4 +9,4 @@ APP="$1" # shellcheck disable=SC2046 docker rm -f $(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) &>/dev/null || true # shellcheck disable=SC2046 -docker rmi $(docker images -q $IMAGE | xargs) &>/dev/null || true +docker rmi $(docker images -q $IMAGE_REPO | xargs) &>/dev/null || true diff --git a/plugins/common/functions b/plugins/common/functions index b3df13581..1b6000c01 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -130,15 +130,23 @@ verify_image() { fi } -get_app_image_name(){ +get_app_image_repo() { + # central definition of our image repo pattern + local APP="$1"; IMAGE_REPO="dokku/$APP" + [[ -z "$APP" ]] && dokku_log_fail "(get_app_image_repo) APP must not be null" + echo $IMAGE_REPO +} + +get_app_image_name() { # return image identifier for a given app, tag tuple. validate if tag is presented - local APP="$1"; local IMAGE_TAG="$2" + local APP="$1"; local IMAGE_TAG="$2"; local IMAGE_REPO=$(get_app_image_repo $APP) + [[ -z "$APP" ]] && dokku_log_fail "(get_app_image_name) APP must not be null" if [[ -n "$IMAGE_TAG" ]]; then - IMAGE="dokku/$APP:$IMAGE_TAG" + IMAGE="$IMAGE_REPO:$IMAGE_TAG" verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found" else - IMAGE="dokku/$APP:latest" + IMAGE="$IMAGE_REPO:latest" fi echo $IMAGE } diff --git a/plugins/tag/commands b/plugins/tag/commands index 7e982c730..35816ce4f 100755 --- a/plugins/tag/commands +++ b/plugins/tag/commands @@ -6,17 +6,17 @@ source "$(dirname $0)/functions" case "$1" in tag:add) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE_TAG="$3"; IMAGE="dokku/$APP" + APP="$2"; IMAGE_TAG="$3"; IMAGE_REPO=$(get_app_image_repo $APP) verify_app_name "$APP" - tag_image "$IMAGE:latest" "$IMAGE:$IMAGE_TAG" - dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE" + tag_image "$IMAGE_REPO:latest" "$IMAGE_REPO:$IMAGE_TAG" + dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE_REPO" pluginhook tag-add $APP $IMAGE_TAG ;; tag:deploy) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE_TAG="$3"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + APP="$2"; IMAGE_TAG="$3" verify_app_name "$APP" release_and_deploy $APP $IMAGE_TAG @@ -24,25 +24,25 @@ case "$1" in tag:list) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE="dokku/$APP" + APP="$2"; IMAGE_REPO=$(get_app_image_repo $APP) verify_app_name "$APP" - dokku_log_info2_quiet "Image tags for $IMAGE" - docker images "$IMAGE" + dokku_log_info2_quiet "Image tags for IMAGE_REPO" + docker images "IMAGE_REPO" ;; tag:rm) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE_TAG="$3"; IMAGE="dokku/$APP" + APP="$2"; IMAGE_TAG="$3"; IMAGE_REPO=$(get_app_image_repo $APP) verify_app_name "$2" case "$IMAGE_TAG" in latest) - dokku_log_fail "You can't remove internal dokku tag ($IMAGE_TAG) for $IMAGE" + dokku_log_fail "You can't remove internal dokku tag ($IMAGE_TAG) for $IMAGE_REPO" ;; *) - docker rmi "$IMAGE:$IMAGE_TAG" + docker rmi "$IMAGE_REPO:$IMAGE_TAG" ;; esac pluginhook tag-remove $APP $IMAGE_TAG