|
|
|
|
@@ -1,10 +1,9 @@
|
|
|
|
|
package appjson
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
@@ -58,90 +57,70 @@ func TriggerAppJSONGetContent(appName string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TriggerCorePostDeploy sets a property to
|
|
|
|
|
// allow the app to be restored on boot
|
|
|
|
|
// TriggerCorePostDeploy moves the extracted app.json to the app data directory
|
|
|
|
|
// allowing 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
|
|
|
|
|
return common.CorePostDeploy(common.CorePostDeployInput{
|
|
|
|
|
AppName: appName,
|
|
|
|
|
Destination: common.GetAppDataDirectory("app-json", appName),
|
|
|
|
|
PluginName: "app-json",
|
|
|
|
|
ExtractedPaths: []common.CorePostDeployPath{
|
|
|
|
|
{Path: "app.json", IsDirectory: false},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TriggerCorePostExtract ensures that the main app.json is the one specified by app-json-path
|
|
|
|
|
func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
|
|
|
|
destination := common.GetAppDataDirectory("app-json", appName)
|
|
|
|
|
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 {
|
|
|
|
|
validator := func(appName string, path string) error {
|
|
|
|
|
if !common.FileExists(path) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "app-json-is-valid",
|
|
|
|
|
Args: []string{appName, path},
|
|
|
|
|
StreamStdout: true,
|
|
|
|
|
StreamStderr: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
if result.StderrContents() != "" {
|
|
|
|
|
return errors.New(result.StderrContents())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processSpecificAppJSON := fmt.Sprintf("%s.%s", existingAppJSON, os.Getenv("DOKKU_PID"))
|
|
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "git-get-property",
|
|
|
|
|
Args: []string{appName, "source-image"},
|
|
|
|
|
})
|
|
|
|
|
appSourceImage := results.StdoutContents()
|
|
|
|
|
|
|
|
|
|
results, _ = common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "builder-get-property",
|
|
|
|
|
Args: []string{appName, "build-dir"},
|
|
|
|
|
})
|
|
|
|
|
buildDir := results.StdoutContents()
|
|
|
|
|
|
|
|
|
|
repoDefaultAppJSONPath := path.Join(sourceWorkDir, "app.json")
|
|
|
|
|
if appSourceImage == "" {
|
|
|
|
|
repoAppJSONPath := path.Join(sourceWorkDir, buildDir, 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 := common.Copy(repoAppJSONPath, processSpecificAppJSON); err != nil {
|
|
|
|
|
return fmt.Errorf("Unable to extract app.json: %v", err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if appJSONPath != "app.json" {
|
|
|
|
|
if err := common.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, path.Join(buildDir, 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
|
|
|
|
|
return common.CorePostExtract(common.CorePostExtractInput{
|
|
|
|
|
AppName: appName,
|
|
|
|
|
BuildDir: buildDir,
|
|
|
|
|
Destination: destination,
|
|
|
|
|
PluginName: "app-json",
|
|
|
|
|
SourceWorkDir: sourceWorkDir,
|
|
|
|
|
ToExtract: []common.CorePostExtractToExtract{
|
|
|
|
|
{
|
|
|
|
|
Path: appJSONPath,
|
|
|
|
|
IsDirectory: false,
|
|
|
|
|
Name: "app.json",
|
|
|
|
|
Destination: "app.json",
|
|
|
|
|
Validator: validator,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TriggerInstall initializes app-json directory structures
|
|
|
|
|
|