mirror of
https://github.com/dokku/dokku.git
synced 2026-05-18 05:05:46 +02:00
refactor: set deploy-source and metadata at deploy time
This ensures the value is correct, where previously it was computed based on a file - and therefore did not distinguish between git:from-archive and git:from-image. Closes #4464
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
15
plugins/apps/apps.go
Normal file
15
plugins/apps/apps.go
Normal file
@@ -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,
|
||||
}
|
||||
)
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 "$@"
|
||||
@@ -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 <dokku> ${refname/refs\/heads\//}:${DOKKU_DEPLOY_BRANCH}'"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user