From 3dccf814e854e05c56ee8957b15a83addc370bbf Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 5 Jul 2016 02:34:13 -0400 Subject: [PATCH 1/3] Add deployed-app-image-repo plugin hook This hook will allow users to modify the repo in use for deployed applications. An example use case would be one where the image being deployed is from a remote docker registry where the `dokku` username is taken and the app will be deployed from a separate username. --- docs/development/plugin-triggers.md | 19 ++++++++++++++++++- plugins/20_events/deployed-app-image-repo | 1 + plugins/common/functions | 14 ++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 120000 plugins/20_events/deployed-app-image-repo diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index c70074fe2..04014609a 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -177,6 +177,23 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x echo 'not-latest' ``` +### `deployed-app-image-repo` + +- Description: Used to manage the full repo of the image being deployed. Useful for deploying from an external registry where the repository name is not `dokku/$APP` +- Invoked by: `internal function dokku_deploy_cmd() (deploy phase)` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +APP="$1" +# change the repo from dokku/APP to dokkupaas/APP +echo "dokkupaas/$APP" +``` + ### `deployed-app-repository` - Description: Used to manage the remote repository of the image being deployed. @@ -211,7 +228,7 @@ cache-bust-build-arg() { local APP="$1" IMAGE_SOURCE_TYPE="$2" local output="" - if [[ "$IMAGE_SOURCE_TYPE" == "dockerfile" ]]; then + if [[ "$IMAGE_SOURCE_TYPE" == "dockerfile" ]]; then output=" --build-arg CACHEBUST=$(date +%s)" fi echo -n "$STDIN$output" diff --git a/plugins/20_events/deployed-app-image-repo b/plugins/20_events/deployed-app-image-repo new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/deployed-app-image-repo @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/common/functions b/plugins/common/functions index 764fd9c15..09543e77e 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -172,14 +172,20 @@ get_deploying_app_image_name() { local APP="$1"; local IMAGE_TAG="$2"; [[ -z "$APP" ]] && dokku_log_fail "(get_app_image_name) APP must not be null" + local IMAGE_REPO="" local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP") local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP") + local NEW_IMAGE_REPO=$(plugn trigger deployed-app-image-repo "$APP") if [[ -n "$NEW_IMAGE_TAG" ]]; then IMAGE_TAG="$NEW_IMAGE_TAG" fi - local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + if [[ -n "$NEW_IMAGE_REPO" ]]; then + IMAGE_REPO="$NEW_IMAGE_REPO" + fi + + local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG" "$IMAGE_REPO") if [[ -n "$IMAGE_REMOTE_REPOSITORY" ]]; then IMAGE="${IMAGE_REMOTE_REPOSITORY}${IMAGE}" fi @@ -188,9 +194,13 @@ get_deploying_app_image_name() { get_app_image_name() { declare desc="return image identifier for a given app, tag tuple. validate if tag is presented" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE_REPO=$(get_app_image_repo "$APP") + local APP="$1"; local IMAGE_TAG="$2"; IMAGE_REPO="$3" [[ -z "$APP" ]] && dokku_log_fail "(get_app_image_name) APP must not be null" + if [[ -z "$IMAGE_REPO" ]]; then + IMAGE_REPO=$(get_app_image_repo "$APP") + fi + if [[ -n "$IMAGE_TAG" ]]; then local IMAGE="$IMAGE_REPO:$IMAGE_TAG" verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found" From 72f1a8545915bb36a60a91fa4ccfb6cf35275849 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 5 Jul 2016 02:37:50 -0400 Subject: [PATCH 2/3] Use the deployed image name when running deploy tasks or running arbitrary commands This ensures the proper image is in use, regardless of the phase in which dokku creates a docker container. --- plugins/00_dokku-standard/exec-app-json-scripts | 2 +- plugins/00_dokku-standard/subcommands/run | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/00_dokku-standard/exec-app-json-scripts b/plugins/00_dokku-standard/exec-app-json-scripts index 3f7700fa7..68399a51f 100755 --- a/plugins/00_dokku-standard/exec-app-json-scripts +++ b/plugins/00_dokku-standard/exec-app-json-scripts @@ -23,7 +23,7 @@ get_phase_script() { execute_script() { declare desc="executes appropriate phase script key from app.json" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local PHASE_SCRIPT_KEY="$3" local SCRIPT_CMD=$(get_phase_script "$IMAGE" "$PHASE_SCRIPT_KEY" 2>/dev/null) if [[ -n "$SCRIPT_CMD" ]];then diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/00_dokku-standard/subcommands/run index fc06ac9e3..4a0d04d66 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/00_dokku-standard/subcommands/run @@ -8,7 +8,7 @@ dokku_run_cmd() { declare desc="runs command in container based on app image" local cmd="run" [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - local APP="$2"; local IMAGE_TAG=$(get_running_image_tag "$APP"); local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local APP="$2"; local IMAGE_TAG=$(get_running_image_tag "$APP"); local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") verify_app_name "$APP" shift 2 From 64c5a249191c8f3143ead112323432daadb88f9d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 5 Jul 2016 02:38:02 -0400 Subject: [PATCH 3/3] Create the cache directory if it does not exist for deployment tasks --- plugins/00_dokku-standard/exec-app-json-scripts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/00_dokku-standard/exec-app-json-scripts b/plugins/00_dokku-standard/exec-app-json-scripts index 68399a51f..ab2207aab 100755 --- a/plugins/00_dokku-standard/exec-app-json-scripts +++ b/plugins/00_dokku-standard/exec-app-json-scripts @@ -49,6 +49,8 @@ execute_script() { COMMAND+=" fi " local CACHE_DIR="$DOKKU_ROOT/$APP/cache" + [[ -d $CACHE_DIR ]] || mkdir -p "$CACHE_DIR" + local DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG") # strip --restart args from DOCKER_ARGS local DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<< "$DOCKER_ARGS")