Merge pull request #3091 from dokku/3047-detect-deploy-method

Properly trigger tar-based deploys on git-deployed repositories
This commit is contained in:
Jose Diaz-Gonzalez
2018-03-03 21:36:11 -05:00
committed by GitHub
11 changed files with 110 additions and 44 deletions

View File

@@ -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.

View File

@@ -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-source`
- 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:
```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 source 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:

View File

@@ -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")" "$@"

View File

@@ -0,0 +1 @@
hook

View File

@@ -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-source: $(: | plugn trigger deploy-source "$APP")"
)
if [[ -z "$INFO_FLAG" ]]; then

22
plugins/git/deploy-source Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
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 source is detected
if [[ -n "$STDIN" ]]; then
echo "$STDIN"
return
fi
if [[ -d "$DOKKU_ROOT/$APP/refs" ]]; then
echo "git"
fi
}
git_deploy_source "$@"

View File

@@ -147,7 +147,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
@@ -175,6 +175,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"

View File

@@ -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 "$@"

22
plugins/tar/deploy-source Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
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 source is detected
if [[ -n "$STDIN" ]]; then
echo "$STDIN"
return
fi
if [[ -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
echo "tar"
fi
}
tar_deploy_source "$@"

View File

@@ -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
}

View File

@@ -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 "$@"