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.
This commit is contained in:
@@ -179,7 +179,7 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|||||||
return common.CloneAppData("app-json", oldAppName, newAppName)
|
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 {
|
func TriggerPostCreate(appName string) error {
|
||||||
return common.CreateAppDataDirectory("app-json", appName)
|
return common.CreateAppDataDirectory("app-json", appName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
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
|
BUILD = commands subcommands triggers
|
||||||
PLUGIN_NAME = apps
|
PLUGIN_NAME = apps
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ func appExists(appName string) error {
|
|||||||
|
|
||||||
// checks if an app is locked
|
// checks if an app is locked
|
||||||
func appIsLocked(appName string) bool {
|
func appIsLocked(appName string) bool {
|
||||||
lockfilePath := fmt.Sprintf("%v/.deploy.lock", common.AppRoot(appName))
|
lockPath := getLockPath(appName)
|
||||||
_, err := os.Stat(lockfilePath)
|
_, err := os.Stat(lockPath)
|
||||||
return !os.IsNotExist(err)
|
return !os.IsNotExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +94,11 @@ func destroyApp(appName string) error {
|
|||||||
return nil
|
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
|
// creates an app if allowed
|
||||||
func maybeCreateApp(appName string) error {
|
func maybeCreateApp(appName string) error {
|
||||||
if err := appExists(appName); err == nil {
|
if err := appExists(appName); err == nil {
|
||||||
|
|||||||
@@ -41,10 +41,17 @@ func main() {
|
|||||||
oldAppName := flag.Arg(0)
|
oldAppName := flag.Arg(0)
|
||||||
newAppName := flag.Arg(1)
|
newAppName := flag.Arg(1)
|
||||||
err = apps.TriggerPostAppCloneSetup(oldAppName, newAppName)
|
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":
|
case "post-app-rename-setup":
|
||||||
oldAppName := flag.Arg(0)
|
oldAppName := flag.Arg(0)
|
||||||
newAppName := flag.Arg(1)
|
newAppName := flag.Arg(1)
|
||||||
err = apps.TriggerPostAppRenameSetup(oldAppName, newAppName)
|
err = apps.TriggerPostAppRenameSetup(oldAppName, newAppName)
|
||||||
|
case "post-create":
|
||||||
|
appName := flag.Arg(0)
|
||||||
|
err = apps.TriggerPostCreate(appName)
|
||||||
case "post-delete":
|
case "post-delete":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
err = apps.TriggerPostDelete(appName)
|
err = apps.TriggerPostDelete(appName)
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ func CommandLock(appName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
lockfilePath := fmt.Sprintf("%v/.deploy.lock", common.AppRoot(appName))
|
lockPath := getLockPath(appName)
|
||||||
if _, err := os.Create(lockfilePath); err != nil {
|
if _, err := os.Create(lockPath); err != nil {
|
||||||
return errors.New("Unable to create deploy lock")
|
return errors.New("Unable to create deploy lock")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ func CommandUnlock(appName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
lockfilePath := fmt.Sprintf("%v/.deploy.lock", common.AppRoot(appName))
|
lockfilePath := getLockPath(appName)
|
||||||
if _, err := os.Stat(lockfilePath); !os.IsNotExist(err) {
|
if _, err := os.Stat(lockfilePath); !os.IsNotExist(err) {
|
||||||
common.LogWarn("A deploy may be in progress.")
|
common.LogWarn("A deploy may be in progress.")
|
||||||
common.LogWarn("Removing the app lock will not stop in progress deploys.")
|
common.LogWarn("Removing the app lock will not stop in progress deploys.")
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ func TriggerInstall() error {
|
|||||||
return fmt.Errorf("Unable to install the apps plugin: %s", err.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()
|
apps, err := common.UnfilteredDokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -79,7 +83,12 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
|
|||||||
return err
|
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
|
// TriggerPostAppRenameSetup renames apps files
|
||||||
@@ -92,14 +101,22 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|||||||
return err
|
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 {
|
func TriggerPostDelete(appName string) error {
|
||||||
if err := common.PropertyDestroy("apps", appName); err != nil {
|
dataErr := common.RemoveAppDataDirectory("apps", appName)
|
||||||
common.LogWarn(err.Error())
|
propertyErr := common.PropertyDestroy("apps", appName)
|
||||||
|
|
||||||
|
if dataErr != nil {
|
||||||
|
return dataErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return propertyErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|||||||
return common.CloneAppData("logs", oldAppName, newAppName)
|
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 {
|
func TriggerPostCreate(appName string) error {
|
||||||
return common.CreateAppDataDirectory("logs", appName)
|
return common.CreateAppDataDirectory("logs", appName)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user