From 04a4da7fc51d272f5a25c57ea855851b3cdac3bf Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 10 Jun 2015 14:21:47 -0700 Subject: [PATCH 01/16] allow tagging and deployment of tagged app images --- docs/development/plugin-creation.md | 4 +- docs/development/pluginhooks.md | 43 +++++++++++++------- docs/process-management.md | 54 +++++++++++++++++++++++++ dokku | 17 +++----- plugins/00_dokku-standard/commands | 39 +++++++++--------- plugins/apps/commands | 7 +--- plugins/apps/post-delete | 9 ++++- plugins/apps/pre-delete | 5 ++- plugins/build-env/pre-build | 3 +- plugins/common/functions | 43 ++++++++++++++++++-- plugins/config/docker-args-deploy | 3 +- plugins/ps/commands | 33 ++++++--------- plugins/ps/functions | 25 +----------- plugins/tag/commands | 63 +++++++++++++++++++++++++++++ plugins/tag/functions | 7 ++++ tests/unit/tag.bats | 47 +++++++++++++++++++++ 16 files changed, 300 insertions(+), 102 deletions(-) create mode 100755 plugins/tag/commands create mode 100755 plugins/tag/functions create mode 100644 tests/unit/tag.bats diff --git a/docs/development/plugin-creation.md b/docs/development/plugin-creation.md index 55098a826..b5dd86fb6 100644 --- a/docs/development/plugin-creation.md +++ b/docs/development/plugin-creation.md @@ -20,8 +20,8 @@ source "$PLUGIN_PATH/common/functions" case "$1" in hello) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - APP="$2"; + APP="$2"; TAG=$(get_running_image_tag $APP) + verify_app_name "$2" "$TAG" echo "Hello $APP" ;; diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index 130332d96..202328e28 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -244,7 +244,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using buildpacks. - Invoked by: `dokku release` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell @@ -252,8 +252,9 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # Installs the graphicsmagick package into the container set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - source "$PLUGIN_PATH/common/functions" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" dokku_log_info1" Installing GraphicsMagick..." @@ -270,7 +271,7 @@ docker commit $ID $IMAGE > /dev/null - Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using buildpacks. - Invoked by: `dokku release` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell @@ -278,8 +279,9 @@ docker commit $ID $IMAGE > /dev/null # Installs a package specified by the `CONTAINER_PACKAGE` env var set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - source "$PLUGIN_PATH/common/functions" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" dokku_log_info1" Installing $CONTAINER_PACKAGE..." @@ -296,13 +298,16 @@ docker commit $ID $IMAGE > /dev/null - Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile. - Invoked by: `dokku release` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" # TODO ``` @@ -311,13 +316,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile. - Invoked by: `dokku release` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" # TODO ``` @@ -352,7 +360,7 @@ fi - Description: Allows the running of code before the container's process is started. - Invoked by: `dokku deploy` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell @@ -360,11 +368,9 @@ fi # Runs gulp in our container set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - source "$PLUGIN_PATH/common/functions" - -APP="$1" -IMAGE="dokku/$APP" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" dokku_log_info1 "Running gulp" id=$(docker run -d $IMAGE /bin/bash -c "cd /app && gulp default") @@ -401,8 +407,11 @@ curl "http://httpstat.us/200" # Clears out the gulp asset build cache for applications set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" -APP="$1"; IMAGE="dokku/$APP"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp" +APP="$1"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp" +TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" if [[ -d $GULP_CACHE_DIR ]]; then docker run --rm -v "$GULP_CACHE_DIR:/gulp" "$IMAGE" find /gulp -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true @@ -447,13 +456,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - Description: - Invoked by: `dokku deploy` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" # TODO ``` @@ -462,13 +474,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - Description: - Invoked by: `dokku run` -- Arguments: `$APP` +- Arguments: `$APP $TAG` - Example: ```shell #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" +APP="$1"; TAG=$(get_running_image_tag $APP) +verify_app_name "$APP" "$TAG" # TODO ``` diff --git a/docs/process-management.md b/docs/process-management.md index f7c5e6b4c..64d88a4c1 100644 --- a/docs/process-management.md +++ b/docs/process-management.md @@ -42,3 +42,57 @@ dokku ps:scale app_name web=1 worker=2 ## The web proctype Like Heroku, we handle the `web` proctype differently from others. The `web` proctype is the only proctype that will invoke custom checks as defined by a CHECKS file. It is also the only proctype that will be launched in a container that is either proxied via nginx or bound to an external port. + +## Image tagging + +The dokku tag plugin allows you to add docker image tags to the currently deployed app image for versioning and subsequent deployment. + +``` +tag:add Add tag to latest running app image +tag:deploy Deploy tagged app image +tag:list List all app image tags +tag:rm Remove app image tag +``` + +Example: +``` +root@dokku:~# dokku tag:list node-js-app +=====> Image tags for dokku/node-js-app +REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE +dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB + +root@dokku:~# dokku tag:add node-js-app v0.9.0 +=====> Added v0.9.0 tag to dokku/node-js-app +root@dokku:~# dokku tag:list node-js-app +=====> Image tags for dokku/node-js-app +REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE +dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB +dokku/node-js-app v0.9.0 936a42f25901 About a minute ago 1.025 GB + +root@dokku:~# dokku tag:deploy node-js-app v0.9.0 +-----> Releasing node-js-app (dokku/node-js-app:v0.9.0)... +-----> Deploying node-js-app (dokku/node-js-app:v0.9.0)... +-----> Running pre-flight checks + For more efficient zero downtime deployments, create a file CHECKS. + See http://progrium.viewdocs.io/dokku/checks-examples.md for examples + CHECKS file not found in container: Running simple container check... +-----> Waiting for 10 seconds ... +-----> Default container check successful! +=====> node-js-app container output: + Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY) + Recommending WEB_CONCURRENCY=1 + > node-js-sample@0.1.0 start /app + > node index.js + Node app is running at localhost:5000 +=====> end node-js-app container output +-----> Running post-deploy +-----> Configuring node-js-app.dokku.me... +-----> Creating http nginx.conf +-----> Running nginx-pre-reload + Reloading nginx +-----> Shutting down old containers in 60 seconds +=====> 025eec3fa3b442fded90933d58d8ed8422901f0449f5ea0c23d00515af5d3137 +=====> Application deployed: + http://node-js-app.dokku.me + +``` diff --git a/dokku b/dokku index f1adf488e..7881fcf26 100755 --- a/dokku +++ b/dokku @@ -51,15 +51,12 @@ fi case "$1" in receive) - APP="$2"; IMAGE="dokku/$APP"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" + APP="$2"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" dokku_log_info1 "Cleaning up..." dokku cleanup dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..." dokku build "$APP" "$IMAGE_SOURCE_TYPE" "$TMP_WORK_DIR" - dokku_log_info1 "Releasing $APP..." - dokku release "$APP" "$IMAGE_SOURCE_TYPE" - dokku_log_info1 "Deploying $APP..." - dokku deploy "$APP" + release_and_deploy "$APP" dokku_log_info2 "Application deployed:" dokku urls "$APP" | sed "s/^/ /" echo @@ -67,10 +64,8 @@ case "$1" in deploy) [[ -z $2 ]] && dokku_log_fail "Please specify an app to deploy" - APP="$2"; IMAGE="dokku/$APP" - verify_app_name "$APP" - - pluginhook pre-deploy $APP + APP="$2"; TAG="$3"; verify_app_name "$APP" "$TAG" + pluginhook pre-deploy $APP $TAG is_image_herokuish_based "$IMAGE" && DOKKU_HEROKUISH=true DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" @@ -90,10 +85,10 @@ case "$1" in DOKKU_PORT_FILE="$DOKKU_ROOT/$APP/PORT.$PROC_TYPE.$CONTAINER_INDEX" # start the app - DOCKER_ARGS=$(: | pluginhook docker-args $APP deploy) + DOCKER_ARGS=$(: | pluginhook docker-args $APP deploy $TAG) DOCKER_ARGS+=" -e DYNO=$PROC_TYPE " DOCKER_ARGS+=" -e DYNO_TYPE_NUMBER='$PROC_TYPE.$CONTAINER_INDEX' " - DOCKER_ARGS+=$(: | pluginhook docker-args-deploy $APP) + DOCKER_ARGS+=$(: | pluginhook docker-args-deploy $APP $TAG) BIND_EXTERNAL=$(pluginhook bind-external-ip $APP) [[ -n "$DOKKU_HEROKUISH" ]] && START_CMD="/start $PROC_TYPE" diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 2a450c864..fc0a42a3c 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -5,7 +5,9 @@ source "$PLUGIN_PATH/config/functions" case "$1" in build) - APP="$2"; IMAGE="dokku/$APP"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" + APP="$2"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" + verify_app_name "$APP" + CACHE_DIR="$DOKKU_ROOT/$APP/cache" eval "$(config_export app $APP)" @@ -58,14 +60,16 @@ case "$1" in ;; release) - APP="$2"; IMAGE="dokku/$APP"; IMAGE_SOURCE_TYPE="$3" + APP="$2"; IMAGE_SOURCE_TYPE="$3"; TAG="$4" + verify_app_name "$APP" "$TAG" + case "$IMAGE_SOURCE_TYPE" in herokuish) # *DEPRECATED* in v0.3.15: `pluginhook pre-release` will be removed in future releases - pluginhook pre-release "$APP" + pluginhook pre-release "$APP" "$TAG" # *DEPRECATED* in v0.3.22: `pluginhook pre-release-buildstep` will be removed in future releases - pluginhook pre-release-buildstep "$APP" - pluginhook pre-release-buildpack "$APP" + pluginhook pre-release-buildstep "$APP" "$TAG" + pluginhook pre-release-buildpack "$APP" "$TAG" if [[ -n $(config_export global) ]]; then id=$(config_export global | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh") test "$(docker wait $id)" -eq 0 @@ -77,15 +81,15 @@ case "$1" in docker commit $id $IMAGE > /dev/null fi # *DEPRECATED* in v0.3.15: `pluginhook post-release` will be removed in future releases - pluginhook post-release "$APP" + pluginhook post-release "$APP" "$TAG" # *DEPRECATED* in v0.3.22: `pluginhook post-release-buildstep` will be removed in future releases - pluginhook post-release-buildstep "$APP" - pluginhook post-release-buildpack "$APP" + pluginhook post-release-buildstep "$APP" "$TAG" + pluginhook post-release-buildpack "$APP" "$TAG" ;; dockerfile) - pluginhook pre-release-dockerfile "$APP" - pluginhook post-release-dockerfile "$APP" + pluginhook pre-release-dockerfile "$APP" "$TAG" + pluginhook post-release-dockerfile "$APP" "$TAG" ;; *) @@ -140,8 +144,7 @@ case "$1" in logs) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - APP="$2"; + APP="$2"; verify_app_name "$2" if (is_deployed $APP); then CONTAINER_IDS=( $(get_app_container_ids $APP) ) @@ -167,13 +170,13 @@ case "$1" in run) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - APP="$2"; IMAGE="dokku/$APP" + APP="$2"; TAG=$(get_running_image_tag $APP) + verify_app_name "$APP" "$TAG" shift 2 - DOCKER_ARGS=$(: | pluginhook docker-args $APP run) - DOCKER_ARGS+=$(: | pluginhook docker-args-run $APP) + DOCKER_ARGS=$(: | pluginhook docker-args $APP run $TAG) + DOCKER_ARGS+=$(: | pluginhook docker-args-run $APP $TAG) [[ $DOKKU_RM_CONTAINER ]] && DOKKU_RUN_OPTS="--rm" has_tty && DOKKU_RUN_OPTS+=" -i -t" is_image_herokuish_based "$IMAGE" && EXEC_CMD="/exec" @@ -183,9 +186,7 @@ case "$1" in url | urls) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - APP="$2"; - + APP="$2"; verify_app_name "$2" eval "$(config_export app $APP)" if [[ -s "$DOKKU_ROOT/$APP/URLS" ]]; then diff --git a/plugins/apps/commands b/plugins/apps/commands index 4e303e26d..4924fb13b 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -19,11 +19,10 @@ case "$1" in apps:destroy) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" [[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1 - APP="$2"; IMAGE="dokku/$APP" - [[ "$3" == "force" ]] && DOKKU_APPS_FORCE_DELETE=1 + APP="$2"; verify_app_name "$APP" + if [[ -z "$DOKKU_APPS_FORCE_DELETE" ]]; then dokku_log_warn "WARNING: Potentially Destructive Action" dokku_log_warn "This command will destroy $APP (including all add-ons)." @@ -48,8 +47,6 @@ case "$1" in done fi - docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null & - pluginhook post-delete $APP ;; diff --git a/plugins/apps/post-delete b/plugins/apps/post-delete index b164bb44b..66b4f40f8 100755 --- a/plugins/apps/post-delete +++ b/plugins/apps/post-delete @@ -1,4 +1,11 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +APP="$1" -[[ -n $1 ]] && rm -r "$DOKKU_ROOT/$1" > /dev/null +[[ -n $APP ]] && rm -r "$DOKKU_ROOT/$APP" > /dev/null + +# remove all application containers & images +# 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 diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index 55ca79e73..c6f563d2c 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -1,7 +1,10 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" + +APP="$1"; CACHE_DIR="$DOKKU_ROOT/$APP/cache" +verify_app_name "$APP" -APP="$1"; IMAGE="dokku/$APP"; CACHE_DIR="$DOKKU_ROOT/$APP/cache" if [[ -d $CACHE_DIR ]]; then docker run --rm -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true fi diff --git a/plugins/build-env/pre-build b/plugins/build-env/pre-build index 74e11f861..900ee800f 100755 --- a/plugins/build-env/pre-build +++ b/plugins/build-env/pre-build @@ -3,7 +3,8 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" source "$PLUGIN_PATH/config/functions" -APP="$1"; IMAGE="dokku/$APP"; BUILD_ENV="" +APP="$1"; BUILD_ENV="" +verify_app_name "$APP" [[ -f "$DOKKU_ROOT/BUILD_ENV" ]] && cat "$DOKKU_ROOT/BUILD_ENV" >> "$DOKKU_ROOT/ENV" && { dokku_log_info2 "Using a global BUILD_ENV file is deprecated as of 0.3.26" diff --git a/plugins/common/functions b/plugins/common/functions index a55ea466d..7b0111c45 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -114,23 +114,38 @@ dokku_container_log_verbose_quiet() { } verify_app_name() { - local APP="$1" + local APP="$1"; local TAG="$2" [[ ! -n "$APP" ]] && dokku_log_fail "(verify_app_name) APP must not be null" [[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist" - IMAGE="dokku/$APP" + + if [[ -n "$TAG" ]]; then + IMAGE="dokku/$APP:$TAG" + else + IMAGE="dokku/$APP" + fi + export IMAGE return 0 } verify_image() { local IMAGE="$1" - DOKKU_APP_IMAGES=$(docker images -q $IMAGE) - if [[ -n "$DOKKU_APP_IMAGES" ]]; then + if (docker inspect "$IMAGE" &>/dev/null); then return 0 else return 1 fi } +get_running_image_tag() { + local APP="$1" + [[ ! -n "$APP" ]] && dokku_log_fail "(get_running_image_tag) APP must not be null" + verify_app_name "$APP" + + CIDS=( $(get_container_ids $APP) ) + RUNNING_IMAGE_TAG=$(docker ps -a --no-trunc | egrep ${CIDS[0]} 2>/dev/null | awk '{ print $2 }' | awk -F: '{ print $2 }' || echo '') + echo $RUNNING_IMAGE_TAG +} + is_image_herokuish_based() { # circleci can't support --rm as they run lxc in lxc [[ ! -f "/home/ubuntu/.circlerc" ]] && local DOCKER_ARGS="--rm" @@ -267,3 +282,23 @@ is_app_running() { return 1 fi } + +release_and_deploy() { + local APP="$1"; local TAG="$2"; verify_app_name "$APP" "$TAG" + + if verify_image "$IMAGE"; then + if is_image_herokuish_based "$IMAGE"; then + IMAGE_SOURCE_TYPE="herokuish" + else + IMAGE_SOURCE_TYPE="dockerfile" + fi + + dokku_log_info1 "Releasing $APP ($IMAGE)..." + dokku release "$APP" "$IMAGE_SOURCE_TYPE" "$TAG" + dokku_log_info1 "Deploying $APP ($IMAGE)..." + dokku deploy "$APP" "$TAG" + dokku_log_info2 "Application deployed:" + dokku urls $APP | sed "s/^/ /" + echo + fi +} diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 14263ef96..9fee5b7c6 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -3,8 +3,9 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" source "$PLUGIN_PATH/config/functions" -STDIN=$(cat); APP="$1"; IMAGE="dokku/$APP" +STDIN=$(cat); APP="$1"; TAG="$2" DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE" +verify_app_name "$APP" "$TAG" if ! is_image_herokuish_based "$IMAGE"; then > "$DOCKERFILE_ENV_FILE" diff --git a/plugins/ps/commands b/plugins/ps/commands index bdebeaa3b..0cc80d937 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -6,24 +6,23 @@ source "$(dirname $0)/functions" case "$1" in ps) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - - APP="$2"; CONTAINER_IDS=$(get_app_container_ids $APP) + APP="$2"; verify_app_name "$APP"; local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - for CID in $CONTAINER_IDS; do + for CID in $DOKKU_APP_RUNNING_CONTAINER_IDS; do has_tty && DOKKU_RUN_OPTS="-i -t" + dokku_log_info1_quiet "running processes in container: $CID" docker exec $DOKKU_RUN_OPTS $CID /bin/sh -c "ps auxwww" done ;; ps:start) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2"; APP="$2" + APP="$2"; TAG=$(get_running_image_tag "$APP"); verify_app_name "$APP" "$TAG" ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 if ! (is_app_running $APP); then - release_and_deploy $APP + release_and_deploy "$APP" "$TAG" else echo "App $APP already running" fi @@ -31,12 +30,9 @@ case "$1" in ps:stop) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - - APP="$2"; CONTAINER_IDS=$(get_app_container_ids $APP) + APP="$2"; verify_app_name "$APP"; local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then echo "Stopping $APP ..." docker stop $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true @@ -47,8 +43,7 @@ case "$1" in ps:rebuild) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - APP="$2" + APP="$2"; verify_app_name "$APP" pluginhook -p receive-app $APP ;; @@ -65,12 +60,10 @@ case "$1" in ps:restart) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" - - APP="$2" + APP="$2"; TAG=$(get_running_image_tag $APP); verify_app_name "$APP" "$TAG" ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - release_and_deploy $APP + release_and_deploy "$APP" "$TAG" ;; ps:restartall) @@ -85,18 +78,18 @@ case "$1" in ps:scale) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - verify_app_name "$2" + APP="$2"; TAG=$(get_running_image_tag "$APP"); verify_app_name "$APP" "$TAG" - APP="$2"; DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" shift 2 - generate_scale_file "$APP" + generate_scale_file "$APP" "$TAG" if [[ -z "$@" ]];then dokku_log_info1 "Scaling for $APP" dokku_log_info2 "$(< $DOKKU_SCALE_FILE)" else set_scale "$APP" "$@" - release_and_deploy "$APP" + release_and_deploy "$APP" "$TAG" fi ;; diff --git a/plugins/ps/functions b/plugins/ps/functions index 6517d8259..f54f10101 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -2,27 +2,6 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -release_and_deploy() { - source "$PLUGIN_PATH/common/functions" - local APP="$1"; local IMAGE="dokku/$APP" - - if verify_image "$IMAGE"; then - if is_image_herokuish_based "$IMAGE"; then - IMAGE_SOURCE_TYPE="herokuish" - else - IMAGE_SOURCE_TYPE="dockerfile" - fi - - dokku_log_info1 "Releasing $APP ..." - dokku release "$APP" "$IMAGE_SOURCE_TYPE" - dokku_log_info1 "Deploying $APP ..." - dokku deploy "$APP" - dokku_log_info2 "Application deployed:" - dokku urls $APP | sed "s/^/ /" - echo - fi -} - print_dokku_scale_file(){ local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" while read line || [ -n "$line" ] @@ -32,7 +11,8 @@ print_dokku_scale_file(){ } generate_scale_file() { - local APP="$1"; local IMAGE="dokku/$APP"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + local APP="$1"; local TAG="$3"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + verify_app_name "$APP" "$TAG" copy_from_image "$IMAGE" "/app/DOKKU_SCALE" "$DOKKU_ROOT/$APP" 2>/dev/null || true if [[ ! -f $DOKKU_SCALE_FILE ]]; then dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Defaulting to a single web process" @@ -62,4 +42,3 @@ set_scale() { fi done } - diff --git a/plugins/tag/commands b/plugins/tag/commands new file mode 100755 index 000000000..f035cbca4 --- /dev/null +++ b/plugins/tag/commands @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" +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"; TAG="$3" + verify_app_name "$APP" + verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found" + + tag_image "$IMAGE:latest" "$IMAGE:$TAG" + dokku_log_info2_quiet "Added $TAG tag to $IMAGE" + ;; + + tag:deploy) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + APP="$2"; TAG="$3" + verify_app_name "$APP" + verify_image "$IMAGE:$TAG" || dokku_log_fail "App image ($IMAGE:$TAG) not found" + + release_and_deploy $APP $TAG + ;; + + tag:list) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + APP="$2"; verify_app_name "$APP" + + dokku_log_info2_quiet "Image tags for $IMAGE" + docker images "$IMAGE" + ;; + + tag:rm) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + APP="$2"; TAG="$3" + verify_app_name "$2" + + case "$TAG" in + latest) + dokku_log_fail "You can't remove internal dokku tag ($TAG) for $IMAGE" + ;; + + *) + docker rmi "$IMAGE:$TAG" + ;; + esac + ;; + + help | tag:help) + cat && cat< Add tag to latest running app image + tag:deploy Deploy tagged app image + tag:list List all app image tags + tag:rm Remove app image tag +EOF + ;; + + *) + exit $DOKKU_NOT_IMPLEMENTED_EXIT + ;; + +esac diff --git a/plugins/tag/functions b/plugins/tag/functions new file mode 100755 index 000000000..717eefb8c --- /dev/null +++ b/plugins/tag/functions @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$(dirname $0)/../common/functions" + +tag_image() { + docker tag -f "$1" "$2" +} diff --git a/tests/unit/tag.bats b/tests/unit/tag.bats new file mode 100644 index 000000000..879f1ef8c --- /dev/null +++ b/tests/unit/tag.bats @@ -0,0 +1,47 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + deploy_app +} + +teardown() { + destroy_app +} + +@test "(tag) tag:add, tag:list, tag:rm" { + run /bin/bash -c "dokku tag:add $TEST_APP v0.9.0" + echo "output: "$output + echo "status: "$status + assert_success + run /bin/bash -c "dokku tag:list $TEST_APP | egrep -q 'v0.9.0'" + echo "output: "$output + echo "status: "$status + assert_success + + run /bin/bash -c "dokku tag:rm $TEST_APP v0.9.0" + echo "output: "$output + echo "status: "$status + assert_success + run /bin/bash -c "dokku tag:list $TEST_APP | egrep -q 'v0.9.0'" + echo "output: "$output + echo "status: "$status + assert_failure + +} + +@test "(tag) tag:deploy" { + run /bin/bash -c "dokku tag:add $TEST_APP v0.9.0" + echo "output: "$output + echo "status: "$status + assert_success + run /bin/bash -c "dokku tag:deploy $TEST_APP v0.9.0" + echo "output: "$output + echo "status: "$status + assert_success + run /bin/bash -c "docker ps | egrep '/start web'| egrep -q dokku/node-js-app:v0.9.0" + echo "output: "$output + echo "status: "$status + assert_success +} From 5be7641f875e264cb0a453523373f7127c3f6f17 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 10 Jun 2015 18:10:48 -0700 Subject: [PATCH 02/16] call tag-add and tag-remove pluginhooks --- docs/development/pluginhooks.md | 36 +++++++++++++++++++++++++++++++++ plugins/tag/commands | 2 ++ 2 files changed, 38 insertions(+) diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index 202328e28..8236b0563 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -629,3 +629,39 @@ if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then fi pluginhook receive-app $APP $newrev ``` + +### `tag-add` + +- Description: Allows you to run commands once a tag for an application image has been added +- Invoked by: `dokku tag:add` +- Arguments: `$APP $TAG` +- Example: + +```shell +#!/usr/bin/env bash +# Upload an application image to docker hub + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +APP="$1"; TAG="$2"; IMAGE="dokku/${APP}:${TAG}" + +IMAGE_ID=$(docker inspect --format '{{ .Id }}' $IMAGE) +docker tag -f $IMAGE_ID $DOCKER_HUB_USER/$APP:$TAG +docker push $DOCKER_HUB_USER/$APP:$TAG +``` + +### `tag-remove` + +- Description: Allows you to run commands once a tag for an application image has been removed +- Invoked by: `dokku tag:remove` +- Arguments: `$APP $TAG` +- Example: + +```shell +#!/usr/bin/env bash +# Remove an image tag from docker hub + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +APP="$1"; TAG="$2" + +some code to remove a docker hub tag because it's not implemented in the CLI.... +``` diff --git a/plugins/tag/commands b/plugins/tag/commands index f035cbca4..8bc308dd4 100755 --- a/plugins/tag/commands +++ b/plugins/tag/commands @@ -12,6 +12,7 @@ case "$1" in tag_image "$IMAGE:latest" "$IMAGE:$TAG" dokku_log_info2_quiet "Added $TAG tag to $IMAGE" + pluginhook tag-add $APP $TAG ;; tag:deploy) @@ -45,6 +46,7 @@ case "$1" in docker rmi "$IMAGE:$TAG" ;; esac + pluginhook tag-remove $APP $TAG ;; help | tag:help) From 1c8722c763a74afc5ddfc375ca359d467ad1f99c Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 10 Jun 2015 18:14:41 -0700 Subject: [PATCH 03/16] fix my copypasta in unit test --- tests/unit/tag.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tag.bats b/tests/unit/tag.bats index 879f1ef8c..e1433ab64 100644 --- a/tests/unit/tag.bats +++ b/tests/unit/tag.bats @@ -40,7 +40,7 @@ teardown() { echo "output: "$output echo "status: "$status assert_success - run /bin/bash -c "docker ps | egrep '/start web'| egrep -q dokku/node-js-app:v0.9.0" + run /bin/bash -c "docker ps | egrep '/start web'| egrep -q dokku/${TEST_APP}:v0.9.0" echo "output: "$output echo "status: "$status assert_success From d8828c2d25dcfdb523538b0bd90b3148ed187713 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Fri, 12 Jun 2015 11:56:23 -0700 Subject: [PATCH 04/16] [ci skip] add documentation note about $IMAGE and get_running_image_tag() --- docs/development/plugin-creation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/development/plugin-creation.md b/docs/development/plugin-creation.md index b5dd86fb6..0a72c2869 100644 --- a/docs/development/plugin-creation.md +++ b/docs/development/plugin-creation.md @@ -80,3 +80,4 @@ A few notes: dokku config:set --no-restart APP KEY1=VALUE1 [KEY2=VALUE2 ...] dokku config:unset --no-restart APP KEY1 [KEY2 ...] ``` +- As of 0.4.0, we allow image tagging and deployment of said tagged images. Therefore, hard-coding of `$IMAGE` as `dokku/$APP` is no longer sufficient. Instead, for non `pre/post-build-*` plugins, use `get_running_image_tag()` as sourced from common/functions. From d696013fe24a77ab94d5b3ff71233285bbcc632a Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 2 Sep 2015 11:19:46 -0700 Subject: [PATCH 05/16] use get_running_image_tag in new enter plugin --- plugins/enter/commands | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/enter/commands b/plugins/enter/commands index 5f5f2d4a8..601895036 100755 --- a/plugins/enter/commands +++ b/plugins/enter/commands @@ -4,8 +4,8 @@ source "$(dirname "$0")/../common/functions" case "$1" in enter) - APP="$2"; IMAGE="dokku/$APP"; CONTAINER_TYPE="$3" - verify_app_name "$APP" + APP="$2"; TAG=$(get_running_image_tag $APP); CONTAINER_TYPE="$3" + verify_app_name "$APP" "$TAG" [[ ! -n "$3" ]] && dokku_log_fail "No container id specified" From 8be5c874ec5eace43333f4e36fa475db2fc01016 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 2 Sep 2015 11:59:50 -0700 Subject: [PATCH 06/16] errant use of local. derp --- plugins/ps/commands | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ps/commands b/plugins/ps/commands index 0cc80d937..6f6210dd3 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -6,7 +6,7 @@ source "$(dirname $0)/functions" case "$1" in ps) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; verify_app_name "$APP"; local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) + APP="$2"; verify_app_name "$APP"; DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 for CID in $DOKKU_APP_RUNNING_CONTAINER_IDS; do @@ -30,7 +30,7 @@ case "$1" in ps:stop) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; verify_app_name "$APP"; local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) + APP="$2"; verify_app_name "$APP"; DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then From 2f16b06a7664a448ecf9c6832160f4b6808ffd4b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 2 Sep 2015 12:22:55 -0700 Subject: [PATCH 07/16] [ci skip] fix up docs --- docs/development/plugin-creation.md | 2 +- docs/development/pluginhooks.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/development/plugin-creation.md b/docs/development/plugin-creation.md index 0a72c2869..2252be29f 100644 --- a/docs/development/plugin-creation.md +++ b/docs/development/plugin-creation.md @@ -21,7 +21,7 @@ case "$1" in hello) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 APP="$2"; TAG=$(get_running_image_tag $APP) - verify_app_name "$2" "$TAG" + verify_app_name "$APP" "$TAG" echo "Hello $APP" ;; diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index 8236b0563..c6ec23a96 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -305,7 +305,7 @@ docker commit $ID $IMAGE > /dev/null #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; TAG=$(get_running_image_tag $APP) verify_app_name "$APP" "$TAG" @@ -323,7 +323,7 @@ verify_app_name "$APP" "$TAG" #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; TAG=$(get_running_image_tag $APP) verify_app_name "$APP" "$TAG" @@ -407,7 +407,7 @@ curl "http://httpstat.us/200" # Clears out the gulp asset build cache for applications set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp" TAG=$(get_running_image_tag $APP) @@ -463,7 +463,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; TAG=$(get_running_image_tag $APP) verify_app_name "$APP" "$TAG" @@ -481,7 +481,7 @@ verify_app_name "$APP" "$TAG" #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; TAG=$(get_running_image_tag $APP) verify_app_name "$APP" "$TAG" From 495b1d2ba0346183f7495c957c7d8458360d1508 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 16:07:23 -0700 Subject: [PATCH 08/16] refactor to explicitly set IMAGE via get_app_image_name() --- docs/development/plugin-creation.md | 6 +-- docs/development/pluginhooks.md | 63 ++++++++++++++--------------- dokku | 11 ++--- plugins/00_dokku-standard/commands | 30 +++++++------- plugins/apps/commands | 7 ++-- plugins/apps/pre-delete | 2 +- plugins/build-env/pre-build | 2 +- plugins/common/functions | 33 +++++++++------ plugins/config/docker-args-deploy | 4 +- plugins/enter/commands | 4 +- plugins/ps/commands | 23 +++++++---- plugins/ps/functions | 5 ++- plugins/tag/commands | 32 ++++++++------- plugins/tag/functions | 7 ---- 14 files changed, 122 insertions(+), 107 deletions(-) delete mode 100755 plugins/tag/functions diff --git a/docs/development/plugin-creation.md b/docs/development/plugin-creation.md index 2252be29f..78f3e0f9e 100644 --- a/docs/development/plugin-creation.md +++ b/docs/development/plugin-creation.md @@ -20,8 +20,8 @@ source "$PLUGIN_PATH/common/functions" case "$1" in hello) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG=$(get_running_image_tag $APP) - verify_app_name "$APP" "$TAG" + APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + verify_app_name "$APP" echo "Hello $APP" ;; @@ -80,4 +80,4 @@ A few notes: dokku config:set --no-restart APP KEY1=VALUE1 [KEY2=VALUE2 ...] dokku config:unset --no-restart APP KEY1 [KEY2 ...] ``` -- As of 0.4.0, we allow image tagging and deployment of said tagged images. Therefore, hard-coding of `$IMAGE` as `dokku/$APP` is no longer sufficient. Instead, for non `pre/post-build-*` plugins, use `get_running_image_tag()` as sourced from common/functions. +- As of 0.4.0, we allow image tagging and deployment of said tagged images. Therefore, hard-coding of `$IMAGE` as `dokku/$APP` is no longer sufficient. Instead, for non `pre/post-build-*` plugins, use `get_running_image_tag()` & `get_app_image_name()` as sourced from common/functions. See [pluginhooks](http://progrium.viewdocs.io/dokku/development/pluginhooks) doc for examples. diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index c6ec23a96..c74fb049a 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -244,7 +244,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using buildpacks. - Invoked by: `dokku release` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -253,8 +253,8 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" dokku_log_info1" Installing GraphicsMagick..." @@ -271,7 +271,7 @@ docker commit $ID $IMAGE > /dev/null - Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using buildpacks. - Invoked by: `dokku release` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -280,8 +280,8 @@ docker commit $ID $IMAGE > /dev/null set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" dokku_log_info1" Installing $CONTAINER_PACKAGE..." @@ -298,7 +298,7 @@ docker commit $ID $IMAGE > /dev/null - Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile. - Invoked by: `dokku release` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -306,8 +306,8 @@ docker commit $ID $IMAGE > /dev/null set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" # TODO ``` @@ -316,7 +316,7 @@ verify_app_name "$APP" "$TAG" - Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile. - Invoked by: `dokku release` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -324,8 +324,8 @@ verify_app_name "$APP" "$TAG" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" # TODO ``` @@ -360,7 +360,7 @@ fi - Description: Allows the running of code before the container's process is started. - Invoked by: `dokku deploy` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -369,8 +369,8 @@ fi set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" dokku_log_info1 "Running gulp" id=$(docker run -d $IMAGE /bin/bash -c "cd /app && gulp default") @@ -399,7 +399,7 @@ curl "http://httpstat.us/200" - Description: Can be used to run commands before an app is deleted. - Invoked by: `dokku apps:destroy` -- Arguments: `$APP` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -409,9 +409,8 @@ curl "http://httpstat.us/200" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp" -TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; GULP_CACHE_DIR="$DOKKU_ROOT/$APP/gulp"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" if [[ -d $GULP_CACHE_DIR ]]; then docker run --rm -v "$GULP_CACHE_DIR:/gulp" "$IMAGE" find /gulp -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true @@ -422,7 +421,7 @@ fi - Description: Can be used to run commands after an application is deleted. - Invoked by: `dokku apps:destroy` -- Arguments: `$APP` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -456,7 +455,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x - Description: - Invoked by: `dokku deploy` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -464,8 +463,8 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" # TODO ``` @@ -474,7 +473,7 @@ verify_app_name "$APP" "$TAG" - Description: - Invoked by: `dokku run` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -482,8 +481,8 @@ verify_app_name "$APP" "$TAG" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; TAG=$(get_running_image_tag $APP) -verify_app_name "$APP" "$TAG" +APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" # TODO ``` @@ -634,7 +633,7 @@ pluginhook receive-app $APP $newrev - Description: Allows you to run commands once a tag for an application image has been added - Invoked by: `dokku tag:add` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -642,18 +641,18 @@ pluginhook receive-app $APP $newrev # Upload an application image to docker hub set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -APP="$1"; TAG="$2"; IMAGE="dokku/${APP}:${TAG}" +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) IMAGE_ID=$(docker inspect --format '{{ .Id }}' $IMAGE) -docker tag -f $IMAGE_ID $DOCKER_HUB_USER/$APP:$TAG -docker push $DOCKER_HUB_USER/$APP:$TAG +docker tag -f $IMAGE_ID $DOCKER_HUB_USER/$APP:$IMAGE_TAG +docker push $DOCKER_HUB_USER/$APP:$IMAGE_TAG ``` ### `tag-remove` - Description: Allows you to run commands once a tag for an application image has been removed - Invoked by: `dokku tag:remove` -- Arguments: `$APP $TAG` +- Arguments: `$APP $IMAGE_TAG` - Example: ```shell @@ -661,7 +660,7 @@ docker push $DOCKER_HUB_USER/$APP:$TAG # Remove an image tag from docker hub set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -APP="$1"; TAG="$2" +APP="$1"; IMAGE_TAG="$2" some code to remove a docker hub tag because it's not implemented in the CLI.... ``` diff --git a/dokku b/dokku index 7881fcf26..e054a5e61 100755 --- a/dokku +++ b/dokku @@ -51,7 +51,7 @@ fi case "$1" in receive) - APP="$2"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" + APP="$2"; IMAGE=$(get_app_image_name $APP); IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" dokku_log_info1 "Cleaning up..." dokku cleanup dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..." @@ -64,8 +64,9 @@ case "$1" in deploy) [[ -z $2 ]] && dokku_log_fail "Please specify an app to deploy" - APP="$2"; TAG="$3"; verify_app_name "$APP" "$TAG" - pluginhook pre-deploy $APP $TAG + APP="$2"; IMAGE_TAG="$3"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + verify_app_name "$APP" + pluginhook pre-deploy $APP $IMAGE_TAG is_image_herokuish_based "$IMAGE" && DOKKU_HEROKUISH=true DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" @@ -85,10 +86,10 @@ case "$1" in DOKKU_PORT_FILE="$DOKKU_ROOT/$APP/PORT.$PROC_TYPE.$CONTAINER_INDEX" # start the app - DOCKER_ARGS=$(: | pluginhook docker-args $APP deploy $TAG) + DOCKER_ARGS=$(: | pluginhook docker-args $APP deploy $IMAGE_TAG) DOCKER_ARGS+=" -e DYNO=$PROC_TYPE " DOCKER_ARGS+=" -e DYNO_TYPE_NUMBER='$PROC_TYPE.$CONTAINER_INDEX' " - DOCKER_ARGS+=$(: | pluginhook docker-args-deploy $APP $TAG) + DOCKER_ARGS+=$(: | pluginhook docker-args-deploy $APP $IMAGE_TAG) BIND_EXTERNAL=$(pluginhook bind-external-ip $APP) [[ -n "$DOKKU_HEROKUISH" ]] && START_CMD="/start $PROC_TYPE" diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index fc0a42a3c..bd9864851 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -5,7 +5,7 @@ source "$PLUGIN_PATH/config/functions" case "$1" in build) - APP="$2"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4" + APP="$2"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4"; IMAGE=$(get_app_image_name $APP) verify_app_name "$APP" CACHE_DIR="$DOKKU_ROOT/$APP/cache" @@ -60,16 +60,16 @@ case "$1" in ;; release) - APP="$2"; IMAGE_SOURCE_TYPE="$3"; TAG="$4" - verify_app_name "$APP" "$TAG" + APP="$2"; IMAGE_SOURCE_TYPE="$3"; IMAGE_TAG="$4"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + verify_app_name "$APP" case "$IMAGE_SOURCE_TYPE" in herokuish) # *DEPRECATED* in v0.3.15: `pluginhook pre-release` will be removed in future releases - pluginhook pre-release "$APP" "$TAG" + pluginhook pre-release $APP $IMAGE_TAG # *DEPRECATED* in v0.3.22: `pluginhook pre-release-buildstep` will be removed in future releases - pluginhook pre-release-buildstep "$APP" "$TAG" - pluginhook pre-release-buildpack "$APP" "$TAG" + pluginhook pre-release-buildstep $APP $IMAGE_TAG + pluginhook pre-release-buildpack $APP $IMAGE_TAG if [[ -n $(config_export global) ]]; then id=$(config_export global | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh") test "$(docker wait $id)" -eq 0 @@ -81,15 +81,15 @@ case "$1" in docker commit $id $IMAGE > /dev/null fi # *DEPRECATED* in v0.3.15: `pluginhook post-release` will be removed in future releases - pluginhook post-release "$APP" "$TAG" + pluginhook post-release $APP $IMAGE_TAG # *DEPRECATED* in v0.3.22: `pluginhook post-release-buildstep` will be removed in future releases - pluginhook post-release-buildstep "$APP" "$TAG" - pluginhook post-release-buildpack "$APP" "$TAG" + pluginhook post-release-buildstep $APP $IMAGE_TAG + pluginhook post-release-buildpack $APP $IMAGE_TAG ;; dockerfile) - pluginhook pre-release-dockerfile "$APP" "$TAG" - pluginhook post-release-dockerfile "$APP" "$TAG" + pluginhook pre-release-dockerfile $APP $IMAGE_TAG + pluginhook post-release-dockerfile $APP $IMAGE_TAG ;; *) @@ -170,13 +170,13 @@ case "$1" in run) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG=$(get_running_image_tag $APP) - verify_app_name "$APP" "$TAG" + APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + verify_app_name "$APP" shift 2 - DOCKER_ARGS=$(: | pluginhook docker-args $APP run $TAG) - DOCKER_ARGS+=$(: | pluginhook docker-args-run $APP $TAG) + DOCKER_ARGS=$(: | pluginhook docker-args $APP run $IMAGE_TAG) + DOCKER_ARGS+=$(: | pluginhook docker-args-run $APP $IMAGE_TAG) [[ $DOKKU_RM_CONTAINER ]] && DOKKU_RUN_OPTS="--rm" has_tty && DOKKU_RUN_OPTS+=" -i -t" is_image_herokuish_based "$IMAGE" && EXEC_CMD="/exec" diff --git a/plugins/apps/commands b/plugins/apps/commands index 4924fb13b..f2e29666d 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -21,7 +21,8 @@ case "$1" in [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1 [[ "$3" == "force" ]] && DOKKU_APPS_FORCE_DELETE=1 - APP="$2"; verify_app_name "$APP" + APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP) + verify_app_name "$APP" if [[ -z "$DOKKU_APPS_FORCE_DELETE" ]]; then dokku_log_warn "WARNING: Potentially Destructive Action" @@ -38,7 +39,7 @@ case "$1" in echo "Destroying $APP (including all add-ons)" - pluginhook pre-delete $APP + pluginhook pre-delete $APP $IMAGE_TAG DOKKU_APP_CIDS=$(get_app_container_ids $APP) if [[ -n $DOKKU_APP_CIDS ]]; then for ID in $DOKKU_APP_CIDS;do @@ -47,7 +48,7 @@ case "$1" in done fi - pluginhook post-delete $APP + pluginhook post-delete $APP $IMAGE_TAG ;; help | apps:help) diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index c6f563d2c..49f3762bc 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -2,7 +2,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$(dirname $0)/../common/functions" -APP="$1"; CACHE_DIR="$DOKKU_ROOT/$APP/cache" +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG); CACHE_DIR="$DOKKU_ROOT/$APP/cache" verify_app_name "$APP" if [[ -d $CACHE_DIR ]]; then diff --git a/plugins/build-env/pre-build b/plugins/build-env/pre-build index 900ee800f..98e9afd99 100755 --- a/plugins/build-env/pre-build +++ b/plugins/build-env/pre-build @@ -3,7 +3,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" source "$PLUGIN_PATH/config/functions" -APP="$1"; BUILD_ENV="" +APP="$1"; IMAGE=$(get_app_image_name $APP); BUILD_ENV="" verify_app_name "$APP" [[ -f "$DOKKU_ROOT/BUILD_ENV" ]] && cat "$DOKKU_ROOT/BUILD_ENV" >> "$DOKKU_ROOT/ENV" && { diff --git a/plugins/common/functions b/plugins/common/functions index 7b0111c45..b3df13581 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -114,16 +114,10 @@ dokku_container_log_verbose_quiet() { } verify_app_name() { - local APP="$1"; local TAG="$2" + local APP="$1" [[ ! -n "$APP" ]] && dokku_log_fail "(verify_app_name) APP must not be null" [[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist" - if [[ -n "$TAG" ]]; then - IMAGE="dokku/$APP:$TAG" - else - IMAGE="dokku/$APP" - fi - export IMAGE return 0 } @@ -136,12 +130,26 @@ verify_image() { fi } +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" + + if [[ -n "$IMAGE_TAG" ]]; then + IMAGE="dokku/$APP:$IMAGE_TAG" + verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found" + else + IMAGE="dokku/$APP:latest" + fi + echo $IMAGE +} + get_running_image_tag() { + # retrieve current image tag for a given app. returns empty string if no deployed containers are found local APP="$1" [[ ! -n "$APP" ]] && dokku_log_fail "(get_running_image_tag) APP must not be null" verify_app_name "$APP" - CIDS=( $(get_container_ids $APP) ) + CIDS=( $(get_app_container_ids $APP) ) RUNNING_IMAGE_TAG=$(docker ps -a --no-trunc | egrep ${CIDS[0]} 2>/dev/null | awk '{ print $2 }' | awk -F: '{ print $2 }' || echo '') echo $RUNNING_IMAGE_TAG } @@ -284,7 +292,8 @@ is_app_running() { } release_and_deploy() { - local APP="$1"; local TAG="$2"; verify_app_name "$APP" "$TAG" + local APP="$1"; local IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + verify_app_name "$APP" if verify_image "$IMAGE"; then if is_image_herokuish_based "$IMAGE"; then @@ -294,11 +303,11 @@ release_and_deploy() { fi dokku_log_info1 "Releasing $APP ($IMAGE)..." - dokku release "$APP" "$IMAGE_SOURCE_TYPE" "$TAG" + dokku release "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE_TAG" dokku_log_info1 "Deploying $APP ($IMAGE)..." - dokku deploy "$APP" "$TAG" + dokku deploy "$APP" "$IMAGE_TAG" dokku_log_info2 "Application deployed:" - dokku urls $APP | sed "s/^/ /" + dokku urls $APP | sed "s/^/ /" echo fi } diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 9fee5b7c6..f63a2cb5b 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -3,9 +3,9 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" source "$PLUGIN_PATH/config/functions" -STDIN=$(cat); APP="$1"; TAG="$2" +STDIN=$(cat); APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE" -verify_app_name "$APP" "$TAG" +verify_app_name "$APP" if ! is_image_herokuish_based "$IMAGE"; then > "$DOCKERFILE_ENV_FILE" diff --git a/plugins/enter/commands b/plugins/enter/commands index 601895036..e78e4ba13 100755 --- a/plugins/enter/commands +++ b/plugins/enter/commands @@ -4,8 +4,8 @@ source "$(dirname "$0")/../common/functions" case "$1" in enter) - APP="$2"; TAG=$(get_running_image_tag $APP); CONTAINER_TYPE="$3" - verify_app_name "$APP" "$TAG" + APP="$2"; CONTAINER_TYPE="$3"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + verify_app_name "$APP" [[ ! -n "$3" ]] && dokku_log_fail "No container id specified" diff --git a/plugins/ps/commands b/plugins/ps/commands index 6f6210dd3..0acf81ac5 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -18,11 +18,13 @@ case "$1" in ps:start) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG=$(get_running_image_tag "$APP"); verify_app_name "$APP" "$TAG" + APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); + verify_app_name "$APP" + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 if ! (is_app_running $APP); then - release_and_deploy "$APP" "$TAG" + release_and_deploy "$APP" "$IMAGE_TAG" else echo "App $APP already running" fi @@ -30,7 +32,9 @@ case "$1" in ps:stop) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; verify_app_name "$APP"; DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) + APP="$2"; DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP) + verify_app_name "$APP" + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then @@ -60,10 +64,12 @@ case "$1" in ps:restart) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG=$(get_running_image_tag $APP); verify_app_name "$APP" "$TAG" + APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP) + verify_app_name "$APP" + ! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0 - release_and_deploy "$APP" "$TAG" + release_and_deploy "$APP" "$IMAGE_TAG" ;; ps:restartall) @@ -78,18 +84,19 @@ case "$1" in ps:scale) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG=$(get_running_image_tag "$APP"); verify_app_name "$APP" "$TAG" + APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP) + verify_app_name "$APP" DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" shift 2 - generate_scale_file "$APP" "$TAG" + generate_scale_file "$APP" "$IMAGE_TAG" if [[ -z "$@" ]];then dokku_log_info1 "Scaling for $APP" dokku_log_info2 "$(< $DOKKU_SCALE_FILE)" else set_scale "$APP" "$@" - release_and_deploy "$APP" "$TAG" + release_and_deploy "$APP" "$IMAGE_TAG" fi ;; diff --git a/plugins/ps/functions b/plugins/ps/functions index f54f10101..f0e5aef78 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -11,8 +11,9 @@ print_dokku_scale_file(){ } generate_scale_file() { - local APP="$1"; local TAG="$3"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" - verify_app_name "$APP" "$TAG" + local APP="$1"; local IMAGE_TAG="$3"; local IMAGE=$(get_app_image_name $APP $IMAGE_TAG); local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + verify_app_name "$APP" + copy_from_image "$IMAGE" "/app/DOKKU_SCALE" "$DOKKU_ROOT/$APP" 2>/dev/null || true if [[ ! -f $DOKKU_SCALE_FILE ]]; then dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Defaulting to a single web process" diff --git a/plugins/tag/commands b/plugins/tag/commands index 8bc308dd4..67d5496e4 100755 --- a/plugins/tag/commands +++ b/plugins/tag/commands @@ -1,32 +1,36 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$(dirname $0)/../common/functions" -source "$(dirname $0)/functions" + +tag_image() { + docker tag -f "$1" "$2" +} case "$1" in tag:add) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG="$3" + APP="$2"; IMAGE_TAG="$3" verify_app_name "$APP" verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found" - tag_image "$IMAGE:latest" "$IMAGE:$TAG" - dokku_log_info2_quiet "Added $TAG tag to $IMAGE" - pluginhook tag-add $APP $TAG + tag_image "$IMAGE:latest" "$IMAGE:$IMAGE_TAG" + dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE" + pluginhook tag-add $APP $IMAGE_TAG ;; tag:deploy) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG="$3" + APP="$2"; IMAGE_TAG="$3" verify_app_name "$APP" - verify_image "$IMAGE:$TAG" || dokku_log_fail "App image ($IMAGE:$TAG) not found" + verify_image "$IMAGE:$IMAGE_TAG" || dokku_log_fail "App image ($IMAGE:$IMAGE_TAG) not found" - release_and_deploy $APP $TAG + release_and_deploy $APP $IMAGE_TAG ;; tag:list) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; verify_app_name "$APP" + APP="$2" + verify_app_name "$APP" dokku_log_info2_quiet "Image tags for $IMAGE" docker images "$IMAGE" @@ -34,19 +38,19 @@ case "$1" in tag:rm) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; TAG="$3" + APP="$2"; IMAGE_TAG="$3" verify_app_name "$2" - case "$TAG" in + case "$IMAGE_TAG" in latest) - dokku_log_fail "You can't remove internal dokku tag ($TAG) for $IMAGE" + dokku_log_fail "You can't remove internal dokku tag ($IMAGE_TAG) for $IMAGE" ;; *) - docker rmi "$IMAGE:$TAG" + docker rmi "$IMAGE:$IMAGE_TAG" ;; esac - pluginhook tag-remove $APP $TAG + pluginhook tag-remove $APP $IMAGE_TAG ;; help | tag:help) diff --git a/plugins/tag/functions b/plugins/tag/functions deleted file mode 100755 index 717eefb8c..000000000 --- a/plugins/tag/functions +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" - -tag_image() { - docker tag -f "$1" "$2" -} From 880c4d11a0ba86a0e253e715649e173c4187da22 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 16:43:44 -0700 Subject: [PATCH 09/16] include setting IMAGE_TAG from args --- docs/development/pluginhooks.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index c74fb049a..c6771d636 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -253,7 +253,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" dokku_log_info1" Installing GraphicsMagick..." @@ -280,7 +280,7 @@ docker commit $ID $IMAGE > /dev/null set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" dokku_log_info1" Installing $CONTAINER_PACKAGE..." @@ -306,7 +306,7 @@ docker commit $ID $IMAGE > /dev/null set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" # TODO @@ -324,7 +324,7 @@ verify_app_name "$APP" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" # TODO @@ -369,7 +369,7 @@ fi set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" dokku_log_info1 "Running gulp" @@ -463,7 +463,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" # TODO @@ -481,7 +481,7 @@ verify_app_name "$APP" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_PATH/common/functions" -APP="$1"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" # TODO From 14acb8af1a02324be28575b9b17df7a7ec7c26bc Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 16:52:23 -0700 Subject: [PATCH 10/16] move tag_image() to shared functions. explicitly set IMAGE --- plugins/tag/commands | 25 ++++++++++--------------- plugins/tag/functions | 7 +++++++ 2 files changed, 17 insertions(+), 15 deletions(-) create mode 100755 plugins/tag/functions diff --git a/plugins/tag/commands b/plugins/tag/commands index 67d5496e4..7e982c730 100755 --- a/plugins/tag/commands +++ b/plugins/tag/commands @@ -1,17 +1,13 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" - -tag_image() { - docker tag -f "$1" "$2" -} +source "$PLUGIN_PATH/common/functions" +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" + APP="$2"; IMAGE_TAG="$3"; IMAGE="dokku/$APP" verify_app_name "$APP" - verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found" tag_image "$IMAGE:latest" "$IMAGE:$IMAGE_TAG" dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE" @@ -20,16 +16,15 @@ case "$1" in tag:deploy) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE_TAG="$3" + APP="$2"; IMAGE_TAG="$3"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" - verify_image "$IMAGE:$IMAGE_TAG" || dokku_log_fail "App image ($IMAGE:$IMAGE_TAG) not found" release_and_deploy $APP $IMAGE_TAG ;; tag:list) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2" + APP="$2"; IMAGE="dokku/$APP" verify_app_name "$APP" dokku_log_info2_quiet "Image tags for $IMAGE" @@ -38,7 +33,7 @@ case "$1" in tag:rm) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE_TAG="$3" + APP="$2"; IMAGE_TAG="$3"; IMAGE="dokku/$APP" verify_app_name "$2" case "$IMAGE_TAG" in @@ -55,10 +50,10 @@ case "$1" in help | tag:help) cat && cat< Add tag to latest running app image - tag:deploy Deploy tagged app image - tag:list List all app image tags - tag:rm Remove app image tag + tag:add , Add tag to latest running app image + tag:deploy , Deploy tagged app image + tag:list , List all app image tags + tag:rm , Remove app image tag EOF ;; diff --git a/plugins/tag/functions b/plugins/tag/functions new file mode 100755 index 000000000..7dd55157b --- /dev/null +++ b/plugins/tag/functions @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_PATH/common/functions" + +tag_image() { + docker tag -f "$1" "$2" +} From 433db656354222f7800ef93749d73ed861c16537 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 16:52:35 -0700 Subject: [PATCH 11/16] use PLUGIN_PATH --- plugins/apps/pre-delete | 2 +- plugins/enter/commands | 2 +- plugins/tar/commands | 4 ++-- plugins/tar/receive-app | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index 49f3762bc..a8eb8facb 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG); CACHE_DIR="$DOKKU_ROOT/$APP/cache" verify_app_name "$APP" diff --git a/plugins/enter/commands b/plugins/enter/commands index e78e4ba13..dd5a592ef 100755 --- a/plugins/enter/commands +++ b/plugins/enter/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname "$0")/../common/functions" +source "$PLUGIN_PATH/common/functions" case "$1" in enter) diff --git a/plugins/tar/commands b/plugins/tar/commands index f18898e66..cb6575fbd 100755 --- a/plugins/tar/commands +++ b/plugins/tar/commands @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" case "$1" in tar-from|tar:from) @@ -14,7 +14,7 @@ case "$1" in tar-in|tar:in) APP="$2" verify_app_name "$2" - tee "$DOKKU_ROOT/$APP/src.tar" | wc -c + tee "$DOKKU_ROOT/$APP/src.tar" | wc -c pluginhook -p receive-app $APP ;; diff --git a/plugins/tar/receive-app b/plugins/tar/receive-app index 1c9428ccb..0bf09425b 100755 --- a/plugins/tar/receive-app +++ b/plugins/tar/receive-app @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$(dirname $0)/../common/functions" +source "$PLUGIN_PATH/common/functions" APP="$1"; REV="$2" From 9c37069a6a7cecbc2935b77c2934a9f84d22cda5 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 17:05:49 -0700 Subject: [PATCH 12/16] create get_app_image_repo() to define our app image pattern and use it --- plugins/apps/post-delete | 5 +++-- plugins/common/functions | 16 ++++++++++++---- plugins/tag/commands | 20 ++++++++++---------- 3 files changed, 25 insertions(+), 16 deletions(-) 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 From ccb9e4a571aa59b810810c681f0fca25a34402dc Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 17:25:28 -0700 Subject: [PATCH 13/16] remove duplicate output --- dokku | 3 --- 1 file changed, 3 deletions(-) diff --git a/dokku b/dokku index e054a5e61..8142338f1 100755 --- a/dokku +++ b/dokku @@ -57,9 +57,6 @@ case "$1" in dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..." dokku build "$APP" "$IMAGE_SOURCE_TYPE" "$TMP_WORK_DIR" release_and_deploy "$APP" - dokku_log_info2 "Application deployed:" - dokku urls "$APP" | sed "s/^/ /" - echo ;; deploy) From 5f7c4426b7f59e10afae47dac7f9ef0878f4dd24 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 18:26:02 -0700 Subject: [PATCH 14/16] rename tag to tags. make verbs more consistent --- docs/development/pluginhooks.md | 8 ++--- docs/process-management.md | 19 ++++++------ plugins/{tag => tags}/commands | 50 +++++++++++++++--------------- plugins/{tag => tags}/functions | 0 tests/unit/{tag.bats => tags.bats} | 17 +++++----- 5 files changed, 47 insertions(+), 47 deletions(-) rename plugins/{tag => tags}/commands (63%) rename plugins/{tag => tags}/functions (100%) rename tests/unit/{tag.bats => tags.bats} (60%) diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index c6771d636..957e77584 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -629,10 +629,10 @@ fi pluginhook receive-app $APP $newrev ``` -### `tag-add` +### `tags-create` - Description: Allows you to run commands once a tag for an application image has been added -- Invoked by: `dokku tag:add` +- Invoked by: `dokku tags:create` - Arguments: `$APP $IMAGE_TAG` - Example: @@ -648,10 +648,10 @@ docker tag -f $IMAGE_ID $DOCKER_HUB_USER/$APP:$IMAGE_TAG docker push $DOCKER_HUB_USER/$APP:$IMAGE_TAG ``` -### `tag-remove` +### `tags-destroy` - Description: Allows you to run commands once a tag for an application image has been removed -- Invoked by: `dokku tag:remove` +- Invoked by: `dokku tags:destroy` - Arguments: `$APP $IMAGE_TAG` - Example: diff --git a/docs/process-management.md b/docs/process-management.md index 64d88a4c1..c00d7d84a 100644 --- a/docs/process-management.md +++ b/docs/process-management.md @@ -45,31 +45,32 @@ Like Heroku, we handle the `web` proctype differently from others. The `web` pro ## Image tagging -The dokku tag plugin allows you to add docker image tags to the currently deployed app image for versioning and subsequent deployment. +The dokku tags plugin allows you to add docker image tags to the currently deployed app image for versioning and subsequent deployment. ``` -tag:add Add tag to latest running app image -tag:deploy Deploy tagged app image -tag:list List all app image tags -tag:rm Remove app image tag +tags List all app image tags +tags:create Add tag to latest running app image +tags:deploy Deploy tagged app image +tags:destroy Remove app image tag ``` Example: ``` -root@dokku:~# dokku tag:list node-js-app +root@dokku:~# dokku tags node-js-app =====> Image tags for dokku/node-js-app REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB -root@dokku:~# dokku tag:add node-js-app v0.9.0 +root@dokku:~# dokku tags:create node-js-app v0.9.0 =====> Added v0.9.0 tag to dokku/node-js-app -root@dokku:~# dokku tag:list node-js-app + +root@dokku:~# dokku tags node-js-app =====> Image tags for dokku/node-js-app REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB dokku/node-js-app v0.9.0 936a42f25901 About a minute ago 1.025 GB -root@dokku:~# dokku tag:deploy node-js-app v0.9.0 +root@dokku:~# dokku tags:deploy node-js-app v0.9.0 -----> Releasing node-js-app (dokku/node-js-app:v0.9.0)... -----> Deploying node-js-app (dokku/node-js-app:v0.9.0)... -----> Running pre-flight checks diff --git a/plugins/tag/commands b/plugins/tags/commands similarity index 63% rename from plugins/tag/commands rename to plugins/tags/commands index 35816ce4f..a77f8bc93 100755 --- a/plugins/tag/commands +++ b/plugins/tags/commands @@ -4,17 +4,26 @@ source "$PLUGIN_PATH/common/functions" source "$(dirname $0)/functions" case "$1" in - tag:add) + tags) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + APP="$2"; IMAGE_REPO=$(get_app_image_repo $APP) + verify_app_name "$APP" + + dokku_log_info2_quiet "Image tags for $IMAGE_REPO" + docker images "$IMAGE_REPO" + ;; + + tags:create) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 APP="$2"; IMAGE_TAG="$3"; IMAGE_REPO=$(get_app_image_repo $APP) verify_app_name "$APP" 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 + pluginhook tags-create $APP $IMAGE_TAG ;; - tag:deploy) + tags:deploy) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 APP="$2"; IMAGE_TAG="$3" verify_app_name "$APP" @@ -22,38 +31,29 @@ case "$1" in release_and_deploy $APP $IMAGE_TAG ;; - tag:list) - [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - APP="$2"; IMAGE_REPO=$(get_app_image_repo $APP) - verify_app_name "$APP" - - dokku_log_info2_quiet "Image tags for IMAGE_REPO" - docker images "IMAGE_REPO" - ;; - - tag:rm) + tags:destroy) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 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_REPO" - ;; + latest) + dokku_log_fail "You can't remove internal dokku tag ($IMAGE_TAG) for $IMAGE_REPO" + ;; - *) - docker rmi "$IMAGE_REPO:$IMAGE_TAG" - ;; + *) + docker rmi "$IMAGE_REPO:$IMAGE_TAG" + ;; esac - pluginhook tag-remove $APP $IMAGE_TAG + pluginhook tags-destroy $APP $IMAGE_TAG ;; - help | tag:help) + help | tags:help) cat && cat< , Add tag to latest running app image - tag:deploy , Deploy tagged app image - tag:list , List all app image tags - tag:rm , Remove app image tag + tags , List all app image tags + tags:create , Add tag to latest running app image + tags:deploy , Deploy tagged app image + tags:destroy , Remove app image tag EOF ;; diff --git a/plugins/tag/functions b/plugins/tags/functions similarity index 100% rename from plugins/tag/functions rename to plugins/tags/functions diff --git a/tests/unit/tag.bats b/tests/unit/tags.bats similarity index 60% rename from tests/unit/tag.bats rename to tests/unit/tags.bats index e1433ab64..02d154506 100644 --- a/tests/unit/tag.bats +++ b/tests/unit/tags.bats @@ -10,33 +10,32 @@ teardown() { destroy_app } -@test "(tag) tag:add, tag:list, tag:rm" { - run /bin/bash -c "dokku tag:add $TEST_APP v0.9.0" +@test "(tags) tags:create, tags, tags:destroy" { + run /bin/bash -c "dokku tags:create $TEST_APP v0.9.0" echo "output: "$output echo "status: "$status assert_success - run /bin/bash -c "dokku tag:list $TEST_APP | egrep -q 'v0.9.0'" + run /bin/bash -c "dokku tags $TEST_APP | egrep -q 'v0.9.0'" echo "output: "$output echo "status: "$status assert_success - run /bin/bash -c "dokku tag:rm $TEST_APP v0.9.0" + run /bin/bash -c "dokku tags:destroy $TEST_APP v0.9.0" echo "output: "$output echo "status: "$status assert_success - run /bin/bash -c "dokku tag:list $TEST_APP | egrep -q 'v0.9.0'" + run /bin/bash -c "dokku tags $TEST_APP | egrep -q 'v0.9.0'" echo "output: "$output echo "status: "$status assert_failure - } -@test "(tag) tag:deploy" { - run /bin/bash -c "dokku tag:add $TEST_APP v0.9.0" +@test "(tags) tags:deploy" { + run /bin/bash -c "dokku tags:create $TEST_APP v0.9.0" echo "output: "$output echo "status: "$status assert_success - run /bin/bash -c "dokku tag:deploy $TEST_APP v0.9.0" + run /bin/bash -c "dokku tags:deploy $TEST_APP v0.9.0" echo "output: "$output echo "status: "$status assert_success From 74e1bf9f4634e6b1b89f2437f16d53088024fe9b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 18:55:33 -0700 Subject: [PATCH 15/16] [ci skip] move taging to deployment doc --- docs/application-deployment.md | 61 ++++++++++++++++++++++++++++++++-- docs/process-management.md | 55 ------------------------------ 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/docs/application-deployment.md b/docs/application-deployment.md index 0fee05ac7..61268bfab 100644 --- a/docs/application-deployment.md +++ b/docs/application-deployment.md @@ -121,7 +121,7 @@ This is in particular useful, then you want to deploy to root domain, as remote: -----> Application deployed: remote: http://dokku.me -# Zero downtime deploy +## Zero downtime deploy Following a deploy, dokku will now wait `DOKKU_DEFAULT_CHECKS_WAIT` seconds (default: `10`), and if the container is still running, then route traffic to the new container. @@ -147,7 +147,7 @@ Checks can be skipped entirely by setting `DOKKU_SKIP_ALL_CHECKS` to `true` eith See [checks-examples.md](checks-examples.md) for examples and output. -# Removing a deployed app +## Removing a deployed app SSH onto the server, then execute: @@ -155,6 +155,61 @@ SSH onto the server, then execute: dokku apps:destroy myapp ``` -# Dokku/Docker Container Management Compatibility +## Image tagging + +The dokku tags plugin allows you to add docker image tags to the currently deployed app image for versioning and subsequent deployment. + +``` +tags List all app image tags +tags:create Add tag to latest running app image +tags:deploy Deploy tagged app image +tags:destroy Remove app image tag +``` + +Example: +``` +root@dokku:~# dokku tags node-js-app +=====> Image tags for dokku/node-js-app +REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE +dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB + +root@dokku:~# dokku tags:create node-js-app v0.9.0 +=====> Added v0.9.0 tag to dokku/node-js-app + +root@dokku:~# dokku tags node-js-app +=====> Image tags for dokku/node-js-app +REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE +dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB +dokku/node-js-app v0.9.0 936a42f25901 About a minute ago 1.025 GB + +root@dokku:~# dokku tags:deploy node-js-app v0.9.0 +-----> Releasing node-js-app (dokku/node-js-app:v0.9.0)... +-----> Deploying node-js-app (dokku/node-js-app:v0.9.0)... +-----> Running pre-flight checks + For more efficient zero downtime deployments, create a file CHECKS. + See http://progrium.viewdocs.io/dokku/checks-examples.md for examples + CHECKS file not found in container: Running simple container check... +-----> Waiting for 10 seconds ... +-----> Default container check successful! +=====> node-js-app container output: + Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY) + Recommending WEB_CONCURRENCY=1 + > node-js-sample@0.1.0 start /app + > node index.js + Node app is running at localhost:5000 +=====> end node-js-app container output +-----> Running post-deploy +-----> Configuring node-js-app.dokku.me... +-----> Creating http nginx.conf +-----> Running nginx-pre-reload + Reloading nginx +-----> Shutting down old containers in 60 seconds +=====> 025eec3fa3b442fded90933d58d8ed8422901f0449f5ea0c23d00515af5d3137 +=====> Application deployed: + http://node-js-app.dokku.me + +``` + +## Dokku/Docker Container Management Compatibility Dokku is, at it's core, a docker container manager. Thus, it does not necessarily play well with other out-of-band processes interacting with the docker daemon. One thing to note as in [issue #1220](https://github.com/progrium/dokku/issues/1220), dokku executes a cleanup function prior to every deployment. This function removes all exited containers and all 'unattached' images. diff --git a/docs/process-management.md b/docs/process-management.md index c00d7d84a..f7c5e6b4c 100644 --- a/docs/process-management.md +++ b/docs/process-management.md @@ -42,58 +42,3 @@ dokku ps:scale app_name web=1 worker=2 ## The web proctype Like Heroku, we handle the `web` proctype differently from others. The `web` proctype is the only proctype that will invoke custom checks as defined by a CHECKS file. It is also the only proctype that will be launched in a container that is either proxied via nginx or bound to an external port. - -## Image tagging - -The dokku tags plugin allows you to add docker image tags to the currently deployed app image for versioning and subsequent deployment. - -``` -tags List all app image tags -tags:create Add tag to latest running app image -tags:deploy Deploy tagged app image -tags:destroy Remove app image tag -``` - -Example: -``` -root@dokku:~# dokku tags node-js-app -=====> Image tags for dokku/node-js-app -REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE -dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB - -root@dokku:~# dokku tags:create node-js-app v0.9.0 -=====> Added v0.9.0 tag to dokku/node-js-app - -root@dokku:~# dokku tags node-js-app -=====> Image tags for dokku/node-js-app -REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE -dokku/node-js-app latest 936a42f25901 About a minute ago 1.025 GB -dokku/node-js-app v0.9.0 936a42f25901 About a minute ago 1.025 GB - -root@dokku:~# dokku tags:deploy node-js-app v0.9.0 ------> Releasing node-js-app (dokku/node-js-app:v0.9.0)... ------> Deploying node-js-app (dokku/node-js-app:v0.9.0)... ------> Running pre-flight checks - For more efficient zero downtime deployments, create a file CHECKS. - See http://progrium.viewdocs.io/dokku/checks-examples.md for examples - CHECKS file not found in container: Running simple container check... ------> Waiting for 10 seconds ... ------> Default container check successful! -=====> node-js-app container output: - Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY) - Recommending WEB_CONCURRENCY=1 - > node-js-sample@0.1.0 start /app - > node index.js - Node app is running at localhost:5000 -=====> end node-js-app container output ------> Running post-deploy ------> Configuring node-js-app.dokku.me... ------> Creating http nginx.conf ------> Running nginx-pre-reload - Reloading nginx ------> Shutting down old containers in 60 seconds -=====> 025eec3fa3b442fded90933d58d8ed8422901f0449f5ea0c23d00515af5d3137 -=====> Application deployed: - http://node-js-app.dokku.me - -``` From 9eb30d9e33c2f1188577fa7c8adc5295f5dfda69 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 3 Sep 2015 18:55:52 -0700 Subject: [PATCH 16/16] make local consistent in functions --- plugins/common/functions | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 1b6000c01..44cab7fc8 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -102,7 +102,7 @@ dokku_log_pluginhook_call() { } dokku_container_log_verbose_quiet() { - CID=$1; + local CID=$1; shift OIFS=$IFS @@ -132,7 +132,7 @@ verify_image() { get_app_image_repo() { # central definition of our image repo pattern - local APP="$1"; IMAGE_REPO="dokku/$APP" + local APP="$1"; local IMAGE_REPO="dokku/$APP" [[ -z "$APP" ]] && dokku_log_fail "(get_app_image_repo) APP must not be null" echo $IMAGE_REPO } @@ -198,7 +198,8 @@ parse_args() { } copy_from_image() { - local IMAGE="$1"; local SRC_FILE="$2"; local DST_DIR="$3"; verify_app_name $APP + local IMAGE="$1"; local SRC_FILE="$2"; local DST_DIR="$3" + verify_app_name $APP if verify_image "$IMAGE"; then CID=$(docker run -d $IMAGE bash) @@ -210,7 +211,7 @@ copy_from_image() { } get_app_container_ids() { - APP="$1"; CONTAINER_TYPE="$2" + local APP="$1"; local CONTAINER_TYPE="$2" verify_app_name $APP [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< $DOKKU_ROOT/$APP/CONTAINER) @@ -255,7 +256,7 @@ get_app_running_container_ids() { } is_deployed() { - APP="$1" + local APP="$1" if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] || [[ $(ls $DOKKU_ROOT/$APP/CONTAINER.* &> /dev/null; echo $?) -eq 0 ]];then return 0 else @@ -300,7 +301,7 @@ is_app_running() { } release_and_deploy() { - local APP="$1"; local IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) + local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name $APP $IMAGE_TAG) verify_app_name "$APP" if verify_image "$IMAGE"; then