create get_app_image_repo() to define our app image pattern and use it

This commit is contained in:
Michael Hobbs committed 2015-09-03 17:21:22 -07:00
1 parent 433db65635
commit 9c37069a6a
3 files changed
+25 -16

No files matched your search

+3 -2
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x 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 [[ -n $APP ]] && rm -r "$DOKKU_ROOT/$APP" > /dev/null
@@ -8,4 +9,4 @@ APP="$1"
# shellcheck disable=SC2046 # shellcheck disable=SC2046
docker rm -f $(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) &>/dev/null || true docker rm -f $(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) &>/dev/null || true
# shellcheck disable=SC2046 # shellcheck disable=SC2046
docker rmi $(docker images -q $IMAGE | xargs) &>/dev/null || true docker rmi $(docker images -q $IMAGE_REPO | xargs) &>/dev/null || true
+12 -4
View File
@@ -130,15 +130,23 @@ verify_image() {
fi 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 # 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 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" verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found"
else else
IMAGE="dokku/$APP:latest" IMAGE="$IMAGE_REPO:latest"
fi fi
echo $IMAGE echo $IMAGE
} }
+10 -10
View File
@@ -6,17 +6,17 @@ source "$(dirname $0)/functions"
case "$1" in case "$1" in
tag:add) tag:add)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ -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" verify_app_name "$APP"
tag_image "$IMAGE:latest" "$IMAGE:$IMAGE_TAG" tag_image "$IMAGE_REPO:latest" "$IMAGE_REPO:$IMAGE_TAG"
dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE" dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE_REPO"
pluginhook tag-add $APP $IMAGE_TAG pluginhook tag-add $APP $IMAGE_TAG
;; ;;
tag:deploy) tag:deploy)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ -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" verify_app_name "$APP"
release_and_deploy $APP $IMAGE_TAG release_and_deploy $APP $IMAGE_TAG
@@ -24,25 +24,25 @@ case "$1" in
tag:list) tag:list)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ -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" verify_app_name "$APP"
dokku_log_info2_quiet "Image tags for $IMAGE" dokku_log_info2_quiet "Image tags for IMAGE_REPO"
docker images "$IMAGE" docker images "IMAGE_REPO"
;; ;;
tag:rm) tag:rm)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ -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" verify_app_name "$2"
case "$IMAGE_TAG" in case "$IMAGE_TAG" in
latest) 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 esac
pluginhook tag-remove $APP $IMAGE_TAG pluginhook tag-remove $APP $IMAGE_TAG