refactor: move all golang code for managing data directories to common plugin

Additionally, ensure the golang plugins handle setup/teardown of plugin and app-specific data directories during install, rename, and clone phases.
This commit is contained in:
Jose Diaz-Gonzalez
2023-01-08 23:24:15 -05:00
parent 38fdb87c79
commit 6cbe93c245
14 changed files with 153 additions and 47 deletions

View File

@@ -66,7 +66,7 @@ func getProcfileCommand(procfilePath string, processType string, port int) (stri
}
func getProcfilePath(appName string) string {
directory := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", appName)
directory := common.GetAppDataDirectory("ps", appName)
return filepath.Join(directory, "Procfile")
}

View File

@@ -104,7 +104,7 @@ func CommandRestore(appName string, allApps bool, parallelCount int) error {
// CommandRetire ensures old containers are retired
func CommandRetire(appName string) error {
lockFile := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", "retire")
lockFile := filepath.Join(common.GetDataDirectory("ps"), "retire")
scheduler := ""
if appName == "" {
scheduler = common.GetGlobalScheduler()

View File

@@ -116,12 +116,7 @@ func TriggerInstall() error {
return fmt.Errorf("Unable to install the ps plugin: %s", err.Error())
}
directory := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps")
if err := os.MkdirAll(directory, 0755); err != nil {
return err
}
if err := common.SetPermissions(directory, 0755); err != nil {
if err := common.SetupAppData("ps"); err != nil {
return err
}
@@ -130,6 +125,12 @@ func TriggerInstall() error {
return nil
}
for _, appName := range apps {
if err := common.CreateAppDataDirectory("ps", appName); err != nil {
return err
}
}
for _, appName := range apps {
policies, err := getRestartPolicy(appName)
if err != nil {
@@ -188,12 +189,15 @@ func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
return err
}
// TODO: Copy data dir
return nil
return common.CloneAppData("ps", oldAppName, newAppName)
}
// TriggerPostAppRename rebuilds the renamed app
func TriggerPostAppRename(oldAppName string, newAppName string) error {
if err := common.RemoveAppDataDirectory("ps", oldAppName); err != nil {
return err
}
if os.Getenv("SKIP_REBUILD") == "true" {
return nil
}
@@ -211,8 +215,7 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
return err
}
// TODO: Move data dir
return nil
return common.CloneAppData("ps", oldAppName, newAppName)
}
// TriggerPostCreate ensures apps have a default restart policy
@@ -222,12 +225,7 @@ func TriggerPostCreate(appName string) error {
return err
}
directory := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", appName)
if err := os.MkdirAll(directory, 0755); err != nil {
return err
}
if err := common.SetPermissions(directory, 0755); err != nil {
if err := common.CreateAppDataDirectory("ps", appName); err != nil {
return err
}
@@ -242,8 +240,7 @@ func TriggerPostCreate(appName string) error {
// TriggerPostDelete destroys the ps properties for a given app container
func TriggerPostDelete(appName string) error {
directory := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", appName)
dataErr := os.RemoveAll(directory)
dataErr := common.RemoveAppDataDirectory("ps", appName)
propertyErr := common.PropertyDestroy("ps", appName)
if dataErr != nil {