refactor: always return an error from the buildpacks triggers
This commit is contained in:
@@ -19,7 +19,7 @@ func main() {
|
|||||||
var err error
|
var err error
|
||||||
switch trigger {
|
switch trigger {
|
||||||
case "install":
|
case "install":
|
||||||
buildpacks.TriggerInstall()
|
err = buildpacks.TriggerInstall()
|
||||||
case "post-app-clone-setup":
|
case "post-app-clone-setup":
|
||||||
oldAppName := flag.Arg(0)
|
oldAppName := flag.Arg(0)
|
||||||
newAppName := flag.Arg(1)
|
newAppName := flag.Arg(1)
|
||||||
@@ -30,11 +30,11 @@ func main() {
|
|||||||
err = buildpacks.TriggerPostAppRenameSetup(oldAppName, newAppName)
|
err = buildpacks.TriggerPostAppRenameSetup(oldAppName, newAppName)
|
||||||
case "post-delete":
|
case "post-delete":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
buildpacks.TriggerPostDelete(appName)
|
err = buildpacks.TriggerPostDelete(appName)
|
||||||
case "post-extract":
|
case "post-extract":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
sourceWorkDir := flag.Arg(1)
|
sourceWorkDir := flag.Arg(1)
|
||||||
buildpacks.TriggerPostExtract(appName, sourceWorkDir)
|
err = buildpacks.TriggerPostExtract(appName, sourceWorkDir)
|
||||||
case "report":
|
case "report":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
err = buildpacks.ReportSingleApp(appName, "")
|
err = buildpacks.ReportSingleApp(appName, "")
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// TriggerInstall runs the install step for the buildpacks plugin
|
// TriggerInstall runs the install step for the buildpacks plugin
|
||||||
func TriggerInstall() {
|
func TriggerInstall() error {
|
||||||
if err := common.PropertySetup("buildpacks"); err != nil {
|
if err := common.PropertySetup("buildpacks"); err != nil {
|
||||||
common.LogFail(fmt.Sprintf("Unable to install the buildpacks plugin: %s", err.Error()))
|
return fmt.Errorf("Unable to install the buildpacks plugin: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TriggerPostAppCloneSetup creates new buildpacks files
|
// TriggerPostAppCloneSetup creates new buildpacks files
|
||||||
@@ -40,29 +42,25 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TriggerPostDelete destroys the buildpacks property for a given app container
|
// TriggerPostDelete destroys the buildpacks property for a given app container
|
||||||
func TriggerPostDelete(appName string) {
|
func TriggerPostDelete(appName string) error {
|
||||||
err := common.PropertyDestroy("buildpacks", appName)
|
return common.PropertyDestroy("buildpacks", appName)
|
||||||
if err != nil {
|
|
||||||
common.LogFail(err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TriggerPostExtract writes a .buildpacks file into the app
|
// TriggerPostExtract writes a .buildpacks file into the app
|
||||||
func TriggerPostExtract(appName string, sourceWorkDir string) {
|
func TriggerPostExtract(appName string, sourceWorkDir string) error {
|
||||||
buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks")
|
buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(buildpacks) == 0 {
|
if len(buildpacks) == 0 {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
buildpacksPath := filepath.Join(sourceWorkDir, ".buildpacks")
|
buildpacksPath := filepath.Join(sourceWorkDir, ".buildpacks")
|
||||||
file, err := os.OpenFile(buildpacksPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600)
|
file, err := os.OpenFile(buildpacksPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogFail(fmt.Sprintf("Error writing .buildpacks file: %s", err.Error()))
|
return fmt.Errorf("Error writing .buildpacks file: %s", err.Error())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w := bufio.NewWriter(file)
|
w := bufio.NewWriter(file)
|
||||||
@@ -71,8 +69,9 @@ func TriggerPostExtract(appName string, sourceWorkDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Flush(); err != nil {
|
if err = w.Flush(); err != nil {
|
||||||
common.LogFail(fmt.Sprintf("Error writing .buildpacks file: %s", err.Error()))
|
return fmt.Errorf("Error writing .buildpacks file: %s", err.Error())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
file.Chmod(0600)
|
file.Chmod(0600)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user