diff --git a/docs/appendices/0.26.0-migration-guide.md b/docs/appendices/0.26.0-migration-guide.md index 169dfcdec40..b752e8cc2c4 100644 --- a/docs/appendices/0.26.0-migration-guide.md +++ b/docs/appendices/0.26.0-migration-guide.md @@ -8,4 +8,5 @@ ## Changes - The `scheduler` plugin now controls the scheduler in use for deploys. Apps will have their `DOKKU_SCHEDULER` environment variables migrated to the scheduler plugin, after which that value will be removed from said app. Please see the [scheduler documentation](/docs/deployment/schedulers/scheduler-management.md) for more information. - +- The `deploy-source` metadata from `apps:report` is now no longer computed on the fly, but hydrated at deploy time via the `deploy-source-set` trigger. This value may be empty until your next deploy. + - Additionally, the `deploy-source` trigger has now been removed. diff --git a/docs/deployment/application-management.md b/docs/deployment/application-management.md index 31c933f3ed0..9536d32de24 100644 --- a/docs/deployment/application-management.md +++ b/docs/deployment/application-management.md @@ -243,17 +243,20 @@ dokku apps:report ``` =====> node-js-app app information - App dir: /home/dokku/node-js-app - App deploy source: git - App locked: false + App dir: /home/dokku/node-js-app + App deploy source: git + App deploy source metadata: cd7b8afccb202f222e7dc7b427553e71ba5ddafd + App locked: false =====> python-sample app information - App dir: /home/dokku/python-sample + App dir: /home/dokku/python-sample App deploy source: - App locked: false + App deploy source metadata: + App locked: false =====> ruby-sample app information - App dir: /home/dokku/ruby-sample - App deploy source: git - App locked: false + App dir: /home/dokku/ruby-sample + App deploy source: git + App deploy source metadata: c60921ea2799ca108276414b95ea197f16798d51 + App locked: false ``` You can run the command for a specific app also. @@ -264,9 +267,10 @@ dokku apps:report node-js-app ``` =====> node-js-app app information - App dir: /home/dokku/node-js-app - App deploy source: git - App locked: false + App dir: /home/dokku/node-js-app + App deploy source: git + App deploy source metadata: cd7b8afccb202f222e7dc7b427553e71ba5ddafd + App locked: false ``` You can pass flags which will output only the value of the specific information you want. For example: diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 5ff757bd97a..e5e98bba51b 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -446,33 +446,6 @@ APP="$1" IMAGE_TAG="$2" PROC_TYPE="$3" # TODO ``` -### `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` diff --git a/plugins/20_events/deploy-source b/plugins/20_events/deploy-source-set similarity index 100% rename from plugins/20_events/deploy-source rename to plugins/20_events/deploy-source-set diff --git a/plugins/apps/Makefile b/plugins/apps/Makefile index 12aea8f6537..8a92e94b9e7 100644 --- a/plugins/apps/Makefile +++ b/plugins/apps/Makefile @@ -1,5 +1,5 @@ SUBCOMMANDS = subcommands/clone subcommands/create subcommands/destroy subcommands/exists subcommands/list subcommands/lock subcommands/locked subcommands/rename subcommands/report subcommands/unlock -TRIGGERS = triggers/app-create triggers/app-destroy triggers/app-exists triggers/app-maybe-create triggers/post-delete triggers/report +TRIGGERS = triggers/app-create triggers/app-destroy triggers/app-exists triggers/app-maybe-create triggers/deploy-source-set triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = apps diff --git a/plugins/apps/apps.go b/plugins/apps/apps.go new file mode 100644 index 00000000000..3369609ca61 --- /dev/null +++ b/plugins/apps/apps.go @@ -0,0 +1,15 @@ +package apps + +var ( + // DefaultProperties is a map of all valid network properties with corresponding default property values + DefaultProperties = map[string]string{ + "deploy-source": "", + "deploy-source-metadata": "", + } + + // GlobalProperties is a map of all valid global network properties + GlobalProperties = map[string]bool{ + "deploy-source": true, + "deploy-source-metadata": true, + } +) diff --git a/plugins/apps/report.go b/plugins/apps/report.go index ec69410bee2..78f406ad2e3 100644 --- a/plugins/apps/report.go +++ b/plugins/apps/report.go @@ -1,8 +1,6 @@ package apps import ( - "strings" - "github.com/dokku/dokku/plugins/common" ) @@ -13,9 +11,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error { } flags := map[string]common.ReportFunc{ - "--app-dir": reportDir, - "--app-deploy-source": reportDeploySource, - "--app-locked": reportLocked, + "--app-deploy-source": reportDeploySource, + "--app-deploy-source-metadata": reportDeploySourceMetadata, + "--app-dir": reportDir, + "--app-locked": reportLocked, } flagKeys := []string{} @@ -29,17 +28,16 @@ func ReportSingleApp(appName string, format string, infoFlag string) error { return common.ReportSingleApp("app", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter) } -func reportDir(appName string) string { - return common.AppRoot(appName) +func reportDeploySource(appName string) string { + return common.PropertyGet("apps", appName, "deploy-source") } -func reportDeploySource(appName string) string { - deploySource := "" - if b, err := common.PlugnTriggerSetup("deploy-source", []string{appName}...).SetInput("").Output(); err != nil { - deploySource = strings.TrimSpace(string(b[:])) - } +func reportDeploySourceMetadata(appName string) string { + return common.PropertyGet("apps", appName, "deploy-source-metadata") +} - return deploySource +func reportDir(appName string) string { + return common.AppRoot(appName) } func reportLocked(appName string) string { diff --git a/plugins/apps/src/triggers/triggers.go b/plugins/apps/src/triggers/triggers.go index 0fc2dbebea6..9a0ce9d5c70 100644 --- a/plugins/apps/src/triggers/triggers.go +++ b/plugins/apps/src/triggers/triggers.go @@ -30,6 +30,21 @@ func main() { case "app-maybe-create": appName := flag.Arg(0) err = apps.TriggerAppMaybeCreate(appName) + case "deploy-source-set": + appName := flag.Arg(0) + sourceType := flag.Arg(0) + sourceMetadata := flag.Arg(0) + err = apps.TriggerDeploySourceSet(appName, sourceType, sourceMetadata) + case "install": + err = apps.TriggerInstall() + case "post-app-clone-setup": + oldAppName := flag.Arg(0) + newAppName := flag.Arg(1) + err = apps.TriggerPostAppCloneSetup(oldAppName, newAppName) + case "post-app-rename-setup": + oldAppName := flag.Arg(0) + newAppName := flag.Arg(1) + err = apps.TriggerPostAppRenameSetup(oldAppName, newAppName) case "post-delete": appName := flag.Arg(0) err = apps.TriggerPostDelete(appName) diff --git a/plugins/apps/triggers.go b/plugins/apps/triggers.go index 49f53d9c94b..b70076c6453 100644 --- a/plugins/apps/triggers.go +++ b/plugins/apps/triggers.go @@ -1,6 +1,8 @@ package apps import ( + "fmt" + "github.com/dokku/dokku/plugins/common" ) @@ -24,15 +26,59 @@ func TriggerAppMaybeCreate(appName string) error { return maybeCreateApp(appName) } +// TriggerDeploySourceSet sets the current deploy source +func TriggerDeploySourceSet(appName string, sourceType string, sourceMetadata string) error { + if err := common.PropertyWrite("apps", appName, "deploy-source", sourceType); err != nil { + return err + } + + return common.PropertyWrite("apps", appName, "deploy-source-metadata", sourceMetadata) +} + +// TriggerInstall runs the install step for the apps plugin +func TriggerInstall() error { + if err := common.PropertySetup("apps"); err != nil { + return fmt.Errorf("Unable to install the apps plugin: %s", err.Error()) + } + + return nil +} + +// TriggerPostAppCloneSetup creates new apps files +func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error { + err := common.PropertyClone("apps", oldAppName, newAppName) + if err != nil { + return err + } + + return nil +} + +// TriggerPostAppRenameSetup renames apps files +func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error { + if err := common.PropertyClone("apps", oldAppName, newAppName); err != nil { + return err + } + + if err := common.PropertyDestroy("apps", oldAppName); err != nil { + return err + } + + return nil +} + // TriggerPostDelete is the apps post-delete plugin trigger func TriggerPostDelete(appName string) error { - imageRepo := common.GetAppImageRepo(appName) + if err := common.PropertyDestroy("apps", appName); err != nil { + common.LogWarn(err.Error()) + } imagesByAppLabel, err := listImagesByAppLabel(appName) if err != nil { common.LogWarn(err.Error()) } + imageRepo := common.GetAppImageRepo(appName) imagesByRepo, err := listImagesByImageRepo(imageRepo) if err != nil { common.LogWarn(err.Error()) diff --git a/plugins/git/deploy-source b/plugins/git/deploy-source deleted file mode 100755 index c9c26e707a9..00000000000 --- a/plugins/git/deploy-source +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x - -trigger-git-deploy-source() { - declare desc="git deploy-source plugin trigger" - declare trigger="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 -} - -trigger-git-deploy-source "$@" diff --git a/plugins/git/functions b/plugins/git/functions index 3f5357a333e..5d4a62549de 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -93,14 +93,17 @@ cmd-git-hook() { if [[ $refname == "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then # broken out into plugin so we might support other methods to receive an app git_receive_app "$APP" "$newrev" + plugn trigger deploy-source-set "$APP" "git-push" "$newrev" else if [[ $(find "$PLUGIN_PATH"/enabled/*/receive-branch 2>/dev/null | wc -l) != 1 ]]; then # shellcheck disable=SC2086 plugn trigger receive-branch $APP $newrev $refname + plugn trigger deploy-source-set "$APP" "git-push" "$newrev" elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then echo $'\e[1G\e[K'"-----> Set ${refname/refs\/heads\//} to DOKKU_DEPLOY_BRANCH." fn-plugin-property-write "git" "$app" "deploy-branch" "${refname/refs\/heads\//}" git_receive_app "$APP" "$newrev" + plugn trigger deploy-source-set "$APP" "git-push" "$newrev" else echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to ${DOKKU_DEPLOY_BRANCH}." echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\//}:${DOKKU_DEPLOY_BRANCH}'" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 0085c1da9c6..6d35ea2b1c6 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -53,6 +53,7 @@ cmd-git-from-archive() { fi plugn trigger git-from-archive "$APP" "$ARCHIVE_URL" "$ARCHIVE_TYPE" "$USER_NAME" "$USER_EMAIL" + plugn trigger deploy-source-set "$APP" "$ARCHIVE_TYPE" "$ARCHIVE_URL" } cmd-git-auth() { @@ -110,6 +111,7 @@ cmd-git-from-image() { [[ -z "$DOCKER_IMAGE" ]] && dokku_log_fail "Please specify a docker image" plugn trigger git-from-image "$APP" "$DOCKER_IMAGE" "$BUILD_DIR" "$USER_NAME" "$USER_EMAIL" + plugn trigger deploy-source-set "$APP" "docker-image" "$DOCKER_IMAGE" } cmd-git-sync() { @@ -165,6 +167,7 @@ cmd-git-sync() { else plugn trigger receive-app "$APP" fi + plugn trigger deploy-source-set "$APP" "git-sync" "${GIT_REMOTE}#${GIT_REF}" fi }