From e61421b53bc365848c12bbf5445d73d1d82cdd2d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 27 Aug 2023 13:10:45 -0400 Subject: [PATCH 1/4] refactor: migrate the app deploy lock to the data directory This removes it from the app path, hopefully making backups a bit easier to perform. --- plugins/app-json/triggers.go | 2 +- plugins/apps/Makefile | 2 +- plugins/apps/functions.go | 9 +++++++-- plugins/apps/src/triggers/triggers.go | 7 +++++++ plugins/apps/subcommands.go | 6 +++--- plugins/apps/triggers.go | 29 +++++++++++++++++++++------ plugins/logs/triggers.go | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/plugins/app-json/triggers.go b/plugins/app-json/triggers.go index 230e423c1..72fd1ccab 100644 --- a/plugins/app-json/triggers.go +++ b/plugins/app-json/triggers.go @@ -179,7 +179,7 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error { return common.CloneAppData("app-json", oldAppName, newAppName) } -// TriggerPostCreate ensures apps the correct data directory structure +// TriggerPostCreate ensures apps have the correct data directory structure func TriggerPostCreate(appName string) error { return common.CreateAppDataDirectory("app-json", appName) } diff --git a/plugins/apps/Makefile b/plugins/apps/Makefile index 8a92e94b9..7bf928361 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/deploy-source-set triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup 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 triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = apps diff --git a/plugins/apps/functions.go b/plugins/apps/functions.go index 60cfb6e4c..0b59d5744 100644 --- a/plugins/apps/functions.go +++ b/plugins/apps/functions.go @@ -17,8 +17,8 @@ func appExists(appName string) error { // checks if an app is locked func appIsLocked(appName string) bool { - lockfilePath := fmt.Sprintf("%v/.deploy.lock", common.AppRoot(appName)) - _, err := os.Stat(lockfilePath) + lockPath := getLockPath(appName) + _, err := os.Stat(lockPath) return !os.IsNotExist(err) } @@ -94,6 +94,11 @@ func destroyApp(appName string) error { return nil } +// returns the lock path +func getLockPath(appName string) string { + return fmt.Sprintf("%v/.deploy.lock", common.GetDataDirectory(appName)) +} + // creates an app if allowed func maybeCreateApp(appName string) error { if err := appExists(appName); err == nil { diff --git a/plugins/apps/src/triggers/triggers.go b/plugins/apps/src/triggers/triggers.go index e79febbed..191ba79c3 100644 --- a/plugins/apps/src/triggers/triggers.go +++ b/plugins/apps/src/triggers/triggers.go @@ -41,10 +41,17 @@ func main() { oldAppName := flag.Arg(0) newAppName := flag.Arg(1) err = apps.TriggerPostAppCloneSetup(oldAppName, newAppName) + case "post-app-rename": + oldAppName := flag.Arg(0) + newAppName := flag.Arg(1) + err = apps.TriggerPostAppRename(oldAppName, newAppName) case "post-app-rename-setup": oldAppName := flag.Arg(0) newAppName := flag.Arg(1) err = apps.TriggerPostAppRenameSetup(oldAppName, newAppName) + case "post-create": + appName := flag.Arg(0) + err = apps.TriggerPostCreate(appName) case "post-delete": appName := flag.Arg(0) err = apps.TriggerPostDelete(appName) diff --git a/plugins/apps/subcommands.go b/plugins/apps/subcommands.go index d8eef9ba2..de74cefb3 100644 --- a/plugins/apps/subcommands.go +++ b/plugins/apps/subcommands.go @@ -108,8 +108,8 @@ func CommandLock(appName string) error { return err } - lockfilePath := fmt.Sprintf("%v/.deploy.lock", common.AppRoot(appName)) - if _, err := os.Create(lockfilePath); err != nil { + lockPath := getLockPath(appName) + if _, err := os.Create(lockPath); err != nil { return errors.New("Unable to create deploy lock") } @@ -206,7 +206,7 @@ func CommandUnlock(appName string) error { return err } - lockfilePath := fmt.Sprintf("%v/.deploy.lock", common.AppRoot(appName)) + lockfilePath := getLockPath(appName) if _, err := os.Stat(lockfilePath); !os.IsNotExist(err) { common.LogWarn("A deploy may be in progress.") common.LogWarn("Removing the app lock will not stop in progress deploys.") diff --git a/plugins/apps/triggers.go b/plugins/apps/triggers.go index 9a82d9363..ad16adb10 100644 --- a/plugins/apps/triggers.go +++ b/plugins/apps/triggers.go @@ -43,6 +43,10 @@ func TriggerInstall() error { return fmt.Errorf("Unable to install the apps plugin: %s", err.Error()) } + if err := common.SetupAppData("apps"); err != nil { + return err + } + apps, err := common.UnfilteredDokkuApps() if err != nil { return nil @@ -79,7 +83,12 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error { return err } - return nil + return common.CloneAppData("apps", oldAppName, newAppName) +} + +// TriggerPostAppRename removes the old app data +func TriggerPostAppRename(oldAppName string, newAppName string) error { + return common.MigrateAppDataDirectory("apps", oldAppName, newAppName) } // TriggerPostAppRenameSetup renames apps files @@ -92,14 +101,22 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error { return err } - return nil + return common.CloneAppData("apps", oldAppName, newAppName) } -// TriggerPostDelete is the apps post-delete plugin trigger +// TriggerPostCreate ensures apps have the correct data directory structure +func TriggerPostCreate(appName string) error { + return common.CreateAppDataDirectory("apps", appName) +} + +// TriggerPostDelete destroys the apps data for a given app container func TriggerPostDelete(appName string) error { - if err := common.PropertyDestroy("apps", appName); err != nil { - common.LogWarn(err.Error()) + dataErr := common.RemoveAppDataDirectory("apps", appName) + propertyErr := common.PropertyDestroy("apps", appName) + + if dataErr != nil { + return dataErr } - return nil + return propertyErr } diff --git a/plugins/logs/triggers.go b/plugins/logs/triggers.go index 457839816..eeab9790f 100644 --- a/plugins/logs/triggers.go +++ b/plugins/logs/triggers.go @@ -133,7 +133,7 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error { return common.CloneAppData("logs", oldAppName, newAppName) } -// TriggerPostCreate ensures apps the correct data directory structure +// TriggerPostCreate ensures apps have the correct data directory structure func TriggerPostCreate(appName string) error { return common.CreateAppDataDirectory("logs", appName) } From b7a3ef2f8aba61c86f9a4be71d8013b4a97ee047 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 30 Jan 2024 18:31:29 -0500 Subject: [PATCH 2/4] fix: use correct path for lock --- plugins/common/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 7359a980a..6d16919a3 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -929,7 +929,7 @@ acquire_app_deploy_lock() { declare desc="acquire advisory lock for use in deploys" local APP="$1" local LOCK_TYPE="${2:-waiting}" - local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock" + local APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/$APP/.deploy.lock" local LOCK_WAITING_MSG="$APP currently has a deploy lock in place. Waiting..." local LOCK_FAILED_MSG="$APP currently has a deploy lock in place. Exiting..." @@ -939,7 +939,7 @@ acquire_app_deploy_lock() { release_app_deploy_lock() { declare desc="release advisory lock used in deploys" local APP="$1" - local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock" + local APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/$APP/.deploy.lock" release_advisory_lock "$APP_DEPLOY_LOCK_FILE" } From f0c6f45596d63af4afdd9c18899b7df657face00 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 9 Feb 2024 14:38:43 -0500 Subject: [PATCH 3/4] fix: correctly namespace the lock file --- plugins/apps/functions.go | 2 +- plugins/common/functions | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/apps/functions.go b/plugins/apps/functions.go index 0b59d5744..3c42cd3d5 100644 --- a/plugins/apps/functions.go +++ b/plugins/apps/functions.go @@ -96,7 +96,7 @@ func destroyApp(appName string) error { // returns the lock path func getLockPath(appName string) string { - return fmt.Sprintf("%v/.deploy.lock", common.GetDataDirectory(appName)) + return fmt.Sprintf("%v/.deploy.lock", common.GetAppDataDirectory("apps", appName)) } // creates an app if allowed diff --git a/plugins/common/functions b/plugins/common/functions index 6d16919a3..388e12470 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -437,19 +437,19 @@ parse_args() { fi case "$arg" in - --quiet) - export DOKKU_QUIET_OUTPUT=1 - ;; - --trace) - export DOKKU_TRACE=1 - ;; - --force) - export DOKKU_APPS_FORCE_DELETE=1 - ;; - --app) - export DOKKU_APP_NAME=${args[$next_index]} - skip=true - ;; + --quiet) + export DOKKU_QUIET_OUTPUT=1 + ;; + --trace) + export DOKKU_TRACE=1 + ;; + --force) + export DOKKU_APPS_FORCE_DELETE=1 + ;; + --app) + export DOKKU_APP_NAME=${args[$next_index]} + skip=true + ;; esac if [[ "$skip" == "true" ]]; then @@ -929,7 +929,7 @@ acquire_app_deploy_lock() { declare desc="acquire advisory lock for use in deploys" local APP="$1" local LOCK_TYPE="${2:-waiting}" - local APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/$APP/.deploy.lock" + local APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/apps/$APP/.deploy.lock" local LOCK_WAITING_MSG="$APP currently has a deploy lock in place. Waiting..." local LOCK_FAILED_MSG="$APP currently has a deploy lock in place. Exiting..." @@ -939,7 +939,7 @@ acquire_app_deploy_lock() { release_app_deploy_lock() { declare desc="release advisory lock used in deploys" local APP="$1" - local APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/$APP/.deploy.lock" + local APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/apps/$APP/.deploy.lock" release_advisory_lock "$APP_DEPLOY_LOCK_FILE" } From db476d3b51661b8791565f97a6de30a1b1d3fb18 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 9 Feb 2024 14:53:45 -0500 Subject: [PATCH 4/4] chore: run shfmt --- plugins/common/functions | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 388e12470..a6e12cddc 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -437,19 +437,19 @@ parse_args() { fi case "$arg" in - --quiet) - export DOKKU_QUIET_OUTPUT=1 - ;; - --trace) - export DOKKU_TRACE=1 - ;; - --force) - export DOKKU_APPS_FORCE_DELETE=1 - ;; - --app) - export DOKKU_APP_NAME=${args[$next_index]} - skip=true - ;; + --quiet) + export DOKKU_QUIET_OUTPUT=1 + ;; + --trace) + export DOKKU_TRACE=1 + ;; + --force) + export DOKKU_APPS_FORCE_DELETE=1 + ;; + --app) + export DOKKU_APP_NAME=${args[$next_index]} + skip=true + ;; esac if [[ "$skip" == "true" ]]; then