refactor: move app.json extraction up to core-post-extract
This commit is contained in:
1 parent
173434ef34
commit
09eb0b2c8f
4 files changed
+118
-32
No files matched your search
@@ -3,8 +3,12 @@ package appjson
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/otiai10/copy"
|
||||
)
|
||||
|
||||
// TriggerAppJSONProcessDeployParallelism returns the max number of processes to deploy in parallel
|
||||
@@ -33,6 +37,83 @@ func TriggerAppJSONProcessDeployParallelism(appName string, processType string)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerCorePostDeploy sets a property to
|
||||
// allow the app to be restored on boot
|
||||
func TriggerCorePostDeploy(appName string) error {
|
||||
existingAppJSON := getAppJSONPath(appName)
|
||||
processSpecificAppJSON := fmt.Sprintf("%s.%s", existingAppJSON, os.Getenv("DOKKU_PID"))
|
||||
if common.FileExists(processSpecificAppJSON) {
|
||||
if err := os.Rename(processSpecificAppJSON, existingAppJSON); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if common.FileExists(fmt.Sprintf("%s.missing", processSpecificAppJSON)) {
|
||||
if err := os.Remove(fmt.Sprintf("%s.missing", processSpecificAppJSON)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if common.FileExists(existingAppJSON) {
|
||||
if err := os.Remove(existingAppJSON); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerCorePostExtract ensures that the main app.json is the one specified by app-json-path
|
||||
func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
appJSONPath := strings.Trim(reportComputedAppjsonpath(appName), "/")
|
||||
if appJSONPath == "" {
|
||||
appJSONPath = "app.json"
|
||||
}
|
||||
|
||||
existingAppJSON := getAppJSONPath(appName)
|
||||
files, err := filepath.Glob(fmt.Sprintf("%s.*", existingAppJSON))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range files {
|
||||
if err := os.Remove(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
processSpecificAppJSON := fmt.Sprintf("%s.%s", existingAppJSON, os.Getenv("DOKKU_PID"))
|
||||
b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...)
|
||||
appSourceImage := strings.TrimSpace(string(b[:]))
|
||||
|
||||
repoDefaultAppJSONPath := path.Join(sourceWorkDir, "app.json")
|
||||
if appSourceImage == "" {
|
||||
repoAppJSONPath := path.Join(sourceWorkDir, appJSONPath)
|
||||
if !common.FileExists(repoAppJSONPath) {
|
||||
if appJSONPath != "app.json" && common.FileExists(repoDefaultAppJSONPath) {
|
||||
if err := os.Remove(repoDefaultAppJSONPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificAppJSON))
|
||||
}
|
||||
|
||||
if err := copy.Copy(repoAppJSONPath, processSpecificAppJSON); err != nil {
|
||||
return fmt.Errorf("Unable to extract app.json: %v", err.Error())
|
||||
}
|
||||
|
||||
if appJSONPath != "app.json" {
|
||||
if err := copy.Copy(repoAppJSONPath, repoDefaultAppJSONPath); err != nil {
|
||||
return fmt.Errorf("Unable to move app.json into place: %v", err.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := common.CopyFromImage(appName, appSourceImage, appJSONPath, processSpecificAppJSON); err != nil {
|
||||
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificAppJSON))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add validation to app.json file by ensuring it can be deserialized
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerInstall initializes app-json directory structures
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("app-json"); err != nil {
|
||||
@@ -104,10 +185,6 @@ func TriggerPostDeploy(appName string, imageTag string) error {
|
||||
// TriggerPreDeploy is a trigger to execute predeploy and release deployment tasks
|
||||
func TriggerPreDeploy(appName string, imageTag string) error {
|
||||
image := common.GetAppImageName(appName, imageTag, "")
|
||||
if err := refreshAppJSON(appName, image); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := executeScript(appName, image, imageTag, "predeploy"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user