feat: implement heroku's postdeploy deployment task
This occurs during the postdeploy on the first deploy of an app, mimicking heroku. It currently happens _after_ the `postdeploy` and `release` deploy tasks.
This commit is contained in:
@@ -14,6 +14,7 @@ type AppJSON struct {
|
||||
Predeploy string `json:"predeploy"`
|
||||
Postdeploy string `json:"postdeploy"`
|
||||
} `json:"dokku"`
|
||||
Postdeploy string `json:"postdeploy"`
|
||||
} `json:"scripts"`
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,10 @@ func getPhaseScript(appName string, phase string) (string, error) {
|
||||
return "", fmt.Errorf("Cannot parse app.json: %v", err)
|
||||
}
|
||||
|
||||
if phase == "heroku.postdeploy" {
|
||||
return appJSON.Scripts.Postdeploy, nil
|
||||
}
|
||||
|
||||
if phase == "predeploy" {
|
||||
return appJSON.Scripts.Dokku.Predeploy, nil
|
||||
}
|
||||
@@ -143,7 +147,11 @@ func getDokkuAppShell(appName string) string {
|
||||
}
|
||||
|
||||
func executeScript(appName string, image string, imageTag string, phase string) error {
|
||||
common.LogInfo1(fmt.Sprintf("Checking for %s task", phase))
|
||||
phaseName := phase
|
||||
if phase == "heroku.postdeploy" {
|
||||
phaseName = "first deploy postdeploy"
|
||||
}
|
||||
common.LogInfo1(fmt.Sprintf("Checking for %s task", phaseName))
|
||||
command := ""
|
||||
phaseSource := ""
|
||||
if phase == "release" {
|
||||
@@ -158,11 +166,11 @@ func executeScript(appName string, image string, imageTag string, phase string)
|
||||
}
|
||||
|
||||
if command == "" {
|
||||
common.LogVerbose(fmt.Sprintf("No %s task found, skipping", phase))
|
||||
common.LogVerbose(fmt.Sprintf("No %s task found, skipping", phaseName))
|
||||
return nil
|
||||
}
|
||||
|
||||
common.LogInfo1(fmt.Sprintf("Executing %s task from %s: %s", phase, phaseSource, command))
|
||||
common.LogInfo1(fmt.Sprintf("Executing %s task from %s: %s", phaseName, phaseSource, command))
|
||||
isHerokuishImage := common.IsImageHerokuishBased(image, appName)
|
||||
isCnbImage := common.IsImageCnbBased(image)
|
||||
dockerfileEntrypoint := ""
|
||||
@@ -241,15 +249,15 @@ func executeScript(appName string, image string, imageTag string, phase string)
|
||||
}
|
||||
|
||||
if !waitForExecution(containerID) {
|
||||
common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phase, containerID[0:9]))
|
||||
common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
|
||||
common.LogVerboseQuietContainerLogs(containerID)
|
||||
common.LogInfo2Quiet(fmt.Sprintf("End of %s %s task (%s) output", appName, phase, containerID[0:9]))
|
||||
common.LogFail(fmt.Sprintf("Execution of %s task failed: %s", phase, command))
|
||||
common.LogInfo2Quiet(fmt.Sprintf("End of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
|
||||
common.LogFail(fmt.Sprintf("Execution of %s task failed: %s", phase, phaseName))
|
||||
}
|
||||
|
||||
common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phase, containerID[0:9]))
|
||||
common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
|
||||
common.LogVerboseQuietContainerLogs(containerID)
|
||||
common.LogInfo2Quiet(fmt.Sprintf("End of %s %s task (%s) output", appName, phase, containerID[0:9]))
|
||||
common.LogInfo2Quiet(fmt.Sprintf("End of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
|
||||
|
||||
if phase != "predeploy" {
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package appjson
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -9,16 +10,16 @@ import (
|
||||
|
||||
// TriggerInstall initializes app restart policies
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("common"); err != nil {
|
||||
return fmt.Errorf("Unable to install the common plugin: %s", err.Error())
|
||||
}
|
||||
|
||||
directory := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "app-json")
|
||||
if err := os.MkdirAll(directory, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := common.SetPermissions(directory, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return common.SetPermissions(directory, 0755)
|
||||
}
|
||||
|
||||
// TriggerPostDelete destroys the app-json data for a given app container
|
||||
@@ -41,10 +42,7 @@ func TriggerPostDeploy(appName string, imageTag string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := executeScript(appName, image, imageTag, "postdeploy"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return executeScript(appName, image, imageTag, "postdeploy")
|
||||
}
|
||||
|
||||
// TriggerPreDeploy is a trigger to execute predeploy and release deployment tasks
|
||||
@@ -65,5 +63,19 @@ func TriggerPreDeploy(appName string, imageTag string) error {
|
||||
if err := executeScript(appName, image, imageTag, "release"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
if common.PropertyGet("common", appName, "deployed") == "true" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensure that a failed postdeploy does not trigger twice
|
||||
if common.PropertyGet("app-json", appName, "heroku.postdeploy") == "executed" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := common.PropertyWrite("app-json", appName, "heroku.postdeploy", "executed"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return executeScript(appName, image, imageTag, "heroku.postdeploy")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user