2019-09-07 04:47:18 -04:00
|
|
|
package buildpacks
|
2019-01-21 19:41:49 -05:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
)
|
|
|
|
|
|
2019-09-15 17:20:49 -04:00
|
|
|
// TriggerInstall runs the install step for the buildpacks plugin
|
2019-09-07 04:47:18 -04:00
|
|
|
func TriggerInstall() {
|
|
|
|
|
if err := common.PropertySetup("buildpacks"); err != nil {
|
|
|
|
|
common.LogFail(fmt.Sprintf("Unable to install the buildpacks plugin: %s", err.Error()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 17:20:49 -04:00
|
|
|
// TriggerPostDelete destroys the buildpacks property for a given app container
|
2019-09-07 04:47:18 -04:00
|
|
|
func TriggerPostDelete(appName string) {
|
|
|
|
|
err := common.PropertyDestroy("buildpacks", appName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.LogFail(err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-21 19:41:49 -05:00
|
|
|
|
2019-09-15 17:20:49 -04:00
|
|
|
// TriggerPostExtract writes a .buildpacks file into the app
|
2019-09-07 04:47:18 -04:00
|
|
|
func TriggerPostExtract(appName string, sourceWorkDir string) {
|
2019-01-21 19:41:49 -05:00
|
|
|
buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(buildpacks) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-07 04:47:18 -04:00
|
|
|
buildpacksPath := path.Join(sourceWorkDir, ".buildpacks")
|
2019-04-16 22:02:24 -04:00
|
|
|
file, err := os.OpenFile(buildpacksPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600)
|
2019-01-21 19:41:49 -05:00
|
|
|
if err != nil {
|
|
|
|
|
common.LogFail(fmt.Sprintf("Error writing .buildpacks file: %s", err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w := bufio.NewWriter(file)
|
|
|
|
|
for _, buildpack := range buildpacks {
|
|
|
|
|
fmt.Fprintln(w, buildpack)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err = w.Flush(); err != nil {
|
|
|
|
|
common.LogFail(fmt.Sprintf("Error writing .buildpacks file: %s", err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
file.Chmod(0600)
|
|
|
|
|
}
|