fix: ensure app ENV directory exists at DOKKU_LIB_ROOT/config/{app}
The post-create trigger only created the property directory at
DOKKU_LIB_ROOT/config/config/{app}/, but getAppFile() writes the
ENV file to DOKKU_LIB_ROOT/config/{app}/ENV. Add setupAppConfigDir
to create and permission the ENV directory in both post-create and
install triggers, and clean it up on post-delete.
This commit is contained in:
1 file changed
+31
-1
@@ -60,6 +60,23 @@ func TriggerConfigUnset(appName string, key string, restart bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupAppConfigDir(appName string) error {
|
||||||
|
appFile, err := getAppFile(appName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
appConfigDir := filepath.Dir(appFile)
|
||||||
|
if err := os.MkdirAll(appConfigDir, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return common.SetPermissions(common.SetPermissionInput{
|
||||||
|
Filename: appConfigDir,
|
||||||
|
Mode: os.FileMode(0755),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func migrateGlobalEnv() error {
|
func migrateGlobalEnv() error {
|
||||||
if err := common.PropertySetup("--global"); err != nil {
|
if err := common.PropertySetup("--global"); err != nil {
|
||||||
return fmt.Errorf("Unable to setup global environment: %s", err.Error())
|
return fmt.Errorf("Unable to setup global environment: %s", err.Error())
|
||||||
@@ -114,6 +131,10 @@ func TriggerInstall() error {
|
|||||||
return fmt.Errorf("Unable to setup app environment: %s", err.Error())
|
return fmt.Errorf("Unable to setup app environment: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := setupAppConfigDir(appName); err != nil {
|
||||||
|
return fmt.Errorf("Unable to setup app config directory: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
oldEnvFile := filepath.Join(common.AppRoot(appName), "ENV")
|
oldEnvFile := filepath.Join(common.AppRoot(appName), "ENV")
|
||||||
isMigrated := common.PropertyGetDefault("config", appName, "env-migrated", "")
|
isMigrated := common.PropertyGetDefault("config", appName, "env-migrated", "")
|
||||||
// delete the old file on the next install
|
// delete the old file on the next install
|
||||||
@@ -198,10 +219,19 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|||||||
|
|
||||||
// TriggerPostCreate ensures apps have the correct config structure
|
// TriggerPostCreate ensures apps have the correct config structure
|
||||||
func TriggerPostCreate(appName string) error {
|
func TriggerPostCreate(appName string) error {
|
||||||
return common.PropertySetupApp("config", appName)
|
if err := common.PropertySetupApp("config", appName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return setupAppConfigDir(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TriggerPostDelete destroys the config data for a given app container
|
// TriggerPostDelete destroys the config data for a given app container
|
||||||
func TriggerPostDelete(appName string) error {
|
func TriggerPostDelete(appName string) error {
|
||||||
|
appFile, err := getAppFile(appName)
|
||||||
|
if err == nil {
|
||||||
|
os.RemoveAll(filepath.Dir(appFile))
|
||||||
|
}
|
||||||
|
|
||||||
return common.PropertyDestroy("config", appName)
|
return common.PropertyDestroy("config", appName)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user