From c9d9750afef590ef26cc090c22f0f568b6879cc0 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 3 Mar 2018 18:16:50 -0500 Subject: [PATCH 1/5] feat: add a new plugin trigger for detecting what the current deployment method is This is currently used solely for reporting. Closes #3047 --- docs/deployment/application-management.md | 4 ++- docs/development/plugin-triggers.md | 31 +++++++++++++++++++++-- plugins/20_events/bind-external-ip | 5 ---- plugins/20_events/deploy-method | 1 + plugins/apps/subcommands/report | 1 + plugins/git/deploy-method | 21 +++++++++++++++ plugins/tar/deploy-method | 21 +++++++++++++++ 7 files changed, 76 insertions(+), 8 deletions(-) delete mode 100755 plugins/20_events/bind-external-ip create mode 120000 plugins/20_events/deploy-method create mode 100755 plugins/git/deploy-method create mode 100755 plugins/tar/deploy-method diff --git a/docs/deployment/application-management.md b/docs/deployment/application-management.md index 6caa19a58..bfbacd755 100644 --- a/docs/deployment/application-management.md +++ b/docs/deployment/application-management.md @@ -169,12 +169,14 @@ dokku apps:report ``` =====> node-js-app App dir: /home/dokku/node-js-app - Git sha: dbddc3f + Git sha: dbddc3f + Deploy method: git =====> python-sample not deployed =====> ruby-sample App dir: /home/dokku/ruby-sample Git sha: a2d477c + Deploy method: git ``` You can run the command for a specific app also. diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 6bcc83697..ef24f68e6 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -122,7 +122,7 @@ curl "http://httpstat.us/200" ### `dependencies` -- Description: Used to install system-level dependencies. Invoked by `plugin:install-dependencies`. +- Description: Used to install system-level dependencies. - Invoked by: `dokku plugin:install-dependencies` - Arguments: None - Example: @@ -147,6 +147,33 @@ case "$DOKKU_DISTRO" in esac ``` +### `deploy-method` + +- Description: Used for reporting what the current detected deployment method is. The first detected method should always win. +- Invoked by: `dokku apps:report` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash +# Checks if the app should be deployed via git + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +APP="$1" +STDIN=$(cat) + +# bail if another method is detected +if [[ -n "$STDIN" ]]; then + echo "$STDIN" + return +fi + +if [[ -d "$DOKKU_ROOT/$APP/refs" ]]; then + echo "git" +fi +``` + ### `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` @@ -1155,7 +1182,7 @@ sshcommand acl-add dokku NAME < $PATH_TO_SSH_KEY Note that the `NAME` value is set at the first ssh key match. If an ssh key is set in the `/home/dokku/.ssh/authorized_keys` multiple times, the first match will decide the value. - Description: Allows you to deny access to a Dokku command by either ssh user or associated ssh-command NAME user. -- Invoked by `dokku` +- Invoked by: `dokku` - Arguments: `$SSH_USER $SSH_NAME $DOKKU_COMMAND` - Example: diff --git a/plugins/20_events/bind-external-ip b/plugins/20_events/bind-external-ip deleted file mode 100755 index 3c099ee21..000000000 --- a/plugins/20_events/bind-external-ip +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - -[[ ! "$DOKKU_EVENTS" ]] || dokku_log_plugn_trigger_call "$(basename "$0")" "$@" diff --git a/plugins/20_events/deploy-method b/plugins/20_events/deploy-method new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/deploy-method @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/apps/subcommands/report b/plugins/apps/subcommands/report index ce47d7666..7bf3b0d54 100755 --- a/plugins/apps/subcommands/report +++ b/plugins/apps/subcommands/report @@ -15,6 +15,7 @@ report_single_app() { local flag_map=( "--app-dir: $APP_DIR" "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2> /dev/null || false)" + "--deploy-method: $(plugn trigger deploy-method "$APP")" ) if [[ -z "$INFO_FLAG" ]]; then diff --git a/plugins/git/deploy-method b/plugins/git/deploy-method new file mode 100755 index 000000000..ffac0e48c --- /dev/null +++ b/plugins/git/deploy-method @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +git_deploy_method() { + declare desc="git deploy-method plugin trigger" + declare trigger="git_deploy_method" + declare APP="$1" + local STDIN=$(cat) + + # bail if another method is detected + if [[ -n "$STDIN" ]]; then + echo "$STDIN" + return + fi + + if [[ -d "$DOKKU_ROOT/$APP/refs" ]]; then + echo "git" + fi +} + +git_deploy_method "$@" diff --git a/plugins/tar/deploy-method b/plugins/tar/deploy-method new file mode 100755 index 000000000..a48e6a2be --- /dev/null +++ b/plugins/tar/deploy-method @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +tar_deploy_method() { + declare desc="tar deploy-method plugin trigger" + declare trigger="tar_deploy_method" + declare APP="$1" + local STDIN=$(cat) + + # bail if another method is detected + if [[ -n "$STDIN" ]]; then + echo "$STDIN" + return + fi + + if [[ -f "$DOKKU_ROOT/$APP/src.tar" ]]; then + echo "tar" + fi +} + +tar_deploy_method "$@" From 2b0d34d0db5ddbac3ab9485e3af77c64ec597031 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 3 Mar 2018 18:30:17 -0500 Subject: [PATCH 2/5] fix: do not trigger git builds when calling tar:from Closes #3047 --- plugins/git/functions | 17 ++++++++++++++++- plugins/git/receive-app | 17 ----------------- plugins/tar/functions | 17 ++++++++++++++++- plugins/tar/receive-app | 17 ----------------- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/plugins/git/functions b/plugins/git/functions index c98efab1b..b7dc22b2f 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -141,7 +141,7 @@ git_hook_cmd() { if [[ $refname = "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then # broken out into plugin so we might support other methods to receive an app # shellcheck disable=SC2086 - plugn trigger receive-app $APP $newrev + git_receive_app "$APP" "$newrev" else if [[ $(find "$PLUGIN_PATH"/enabled/*/receive-branch 2>/dev/null | wc -l) != 0 ]]; then # shellcheck disable=SC2086 @@ -169,6 +169,21 @@ git_build() { git_build_app_repo $APP $REF } +git_receive_app() { + declare desc="git receive-app plugin trigger" + declare APP="$1" REV="$2" + + # Don't trigger git build if there is no git repository. + if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then + true + else + acquire_app_deploy_lock "$APP" "exclusive" + # shellcheck disable=SC2086 + git_build $APP $REV + release_app_deploy_lock "$APP" + fi +} + git_upload_pack_cmd() { declare desc="executes git-upload-pack" declare cmd="git-upload-pack" diff --git a/plugins/git/receive-app b/plugins/git/receive-app index 652bc15b2..dc00a4c11 100755 --- a/plugins/git/receive-app +++ b/plugins/git/receive-app @@ -1,22 +1,5 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/git/functions" -git_receive_app() { - declare desc="git receive-app plugin trigger" - local trigger="git_receive_app" - local APP="$1"; local REV="$2" - - # Don't trigger git build if there is no git repository. - if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then - true - else - acquire_app_deploy_lock "$APP" "exclusive" - # shellcheck disable=SC2086 - git_build $APP $REV - release_app_deploy_lock "$APP" - fi -} - git_receive_app "$@" diff --git a/plugins/tar/functions b/plugins/tar/functions index 2219874b6..6c4ee5b00 100755 --- a/plugins/tar/functions +++ b/plugins/tar/functions @@ -57,7 +57,7 @@ tar_in_cmd() { verify_app_name "$2" tee "$DOKKU_ROOT/$APP/src.tar" | wc -c - plugn trigger receive-app "$APP" + tar_receive_app "$APP" } tar_from_cmd() { @@ -69,3 +69,18 @@ tar_from_cmd() { shift 3 curl -# --insecure -L "$URL" | tar_in_cmd "tar:in" "$APP" "$@" } + +tar_receive_app() { + declare desc="tar receive-app plugin trigger" + declare APP="$1" + + # Don't trigger tar build if there is no tarball. + if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then + true + else + acquire_app_deploy_lock "$APP" + # shellcheck disable=SC2086 + tar_build "$@" + release_app_deploy_lock "$APP" + fi +} diff --git a/plugins/tar/receive-app b/plugins/tar/receive-app index 4ff75f293..9c249be45 100755 --- a/plugins/tar/receive-app +++ b/plugins/tar/receive-app @@ -1,22 +1,5 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/tar/functions" -tar_receive_app() { - declare desc="tar receive-app plugin trigger" - local trigger="tar_receive_app" - local APP="$1"; local REV="$2" - - # Don't trigger tar build if there is no tarball. - if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then - true - else - acquire_app_deploy_lock "$APP" - # shellcheck disable=SC2086 - tar_build "$@" - release_app_deploy_lock "$APP" - fi -} - tar_receive_app "$@" From 726c1571eb857e2c7e511aafa0bff8351604a9ec Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 3 Mar 2018 18:33:16 -0500 Subject: [PATCH 3/5] fix: Declare and assign separately to avoid masking return values. --- plugins/git/deploy-method | 3 ++- plugins/tar/deploy-method | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/git/deploy-method b/plugins/git/deploy-method index ffac0e48c..32fe06198 100755 --- a/plugins/git/deploy-method +++ b/plugins/git/deploy-method @@ -5,7 +5,8 @@ git_deploy_method() { declare desc="git deploy-method plugin trigger" declare trigger="git_deploy_method" declare APP="$1" - local STDIN=$(cat) + local STDIN + STDIN=$(cat) # bail if another method is detected if [[ -n "$STDIN" ]]; then diff --git a/plugins/tar/deploy-method b/plugins/tar/deploy-method index a48e6a2be..0fb6a0e03 100755 --- a/plugins/tar/deploy-method +++ b/plugins/tar/deploy-method @@ -5,7 +5,8 @@ tar_deploy_method() { declare desc="tar deploy-method plugin trigger" declare trigger="tar_deploy_method" declare APP="$1" - local STDIN=$(cat) + local STDIN + STDIN=$(cat) # bail if another method is detected if [[ -n "$STDIN" ]]; then From 9a1dd41e9f179c686cad58d3e9c7f8c977f3b2f6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 3 Mar 2018 19:11:49 -0500 Subject: [PATCH 4/5] refactor: rename to deploy-source --- docs/development/plugin-triggers.md | 6 +++--- plugins/apps/subcommands/report | 2 +- plugins/git/{deploy-method => deploy-source} | 10 +++++----- plugins/tar/{deploy-method => deploy-source} | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) rename plugins/git/{deploy-method => deploy-source} (58%) rename plugins/tar/{deploy-method => deploy-source} (59%) diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index ef24f68e6..6a172b32a 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -147,9 +147,9 @@ case "$DOKKU_DISTRO" in esac ``` -### `deploy-method` +### `deploy-source` -- Description: Used for reporting what the current detected deployment method is. The first detected method should always win. +- Description: Used for reporting what the current detected deployment source is. The first detected source should always win. - Invoked by: `dokku apps:report` - Arguments: `$APP` - Example: @@ -163,7 +163,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x APP="$1" STDIN=$(cat) -# bail if another method is detected +# bail if another source is detected if [[ -n "$STDIN" ]]; then echo "$STDIN" return diff --git a/plugins/apps/subcommands/report b/plugins/apps/subcommands/report index 7bf3b0d54..5aa2c5759 100755 --- a/plugins/apps/subcommands/report +++ b/plugins/apps/subcommands/report @@ -15,7 +15,7 @@ report_single_app() { local flag_map=( "--app-dir: $APP_DIR" "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2> /dev/null || false)" - "--deploy-method: $(plugn trigger deploy-method "$APP")" + "--deploy-source: $(plugn trigger deploy-source "$APP")" ) if [[ -z "$INFO_FLAG" ]]; then diff --git a/plugins/git/deploy-method b/plugins/git/deploy-source similarity index 58% rename from plugins/git/deploy-method rename to plugins/git/deploy-source index 32fe06198..8f086c7be 100755 --- a/plugins/git/deploy-method +++ b/plugins/git/deploy-source @@ -1,14 +1,14 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -git_deploy_method() { - declare desc="git deploy-method plugin trigger" - declare trigger="git_deploy_method" +git_deploy_source() { + declare desc="git deploy-source plugin trigger" + declare trigger="git_deploy_source" declare APP="$1" local STDIN STDIN=$(cat) - # bail if another method is detected + # bail if another source is detected if [[ -n "$STDIN" ]]; then echo "$STDIN" return @@ -19,4 +19,4 @@ git_deploy_method() { fi } -git_deploy_method "$@" +git_deploy_source "$@" diff --git a/plugins/tar/deploy-method b/plugins/tar/deploy-source similarity index 59% rename from plugins/tar/deploy-method rename to plugins/tar/deploy-source index 0fb6a0e03..14736c7de 100755 --- a/plugins/tar/deploy-method +++ b/plugins/tar/deploy-source @@ -1,14 +1,14 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -tar_deploy_method() { - declare desc="tar deploy-method plugin trigger" - declare trigger="tar_deploy_method" +tar_deploy_source() { + declare desc="tar deploy-source plugin trigger" + declare trigger="tar_deploy_source" declare APP="$1" local STDIN STDIN=$(cat) - # bail if another method is detected + # bail if another source is detected if [[ -n "$STDIN" ]]; then echo "$STDIN" return @@ -19,4 +19,4 @@ tar_deploy_method() { fi } -tar_deploy_method "$@" +tar_deploy_source "$@" From c3dba4900709beef962f44b2de32f95fb7e45ac6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 3 Mar 2018 20:54:33 -0500 Subject: [PATCH 5/5] fix: pass in empty string for stdin --- plugins/apps/subcommands/report | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/apps/subcommands/report b/plugins/apps/subcommands/report index 5aa2c5759..39e848665 100755 --- a/plugins/apps/subcommands/report +++ b/plugins/apps/subcommands/report @@ -15,7 +15,7 @@ report_single_app() { local flag_map=( "--app-dir: $APP_DIR" "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2> /dev/null || false)" - "--deploy-source: $(plugn trigger deploy-source "$APP")" + "--deploy-source: $(: | plugn trigger deploy-source "$APP")" ) if [[ -z "$INFO_FLAG" ]]; then