From ec8a0dbac75adaa0c4cfd3c7d70801a8e3023f07 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 28 Nov 2017 13:15:36 -0600 Subject: [PATCH] progress! Signed-off-by: Kenneth Reitz --- cmd/herald-worker/main.go | 7 +++-- herald.go | 63 ++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/cmd/herald-worker/main.go b/cmd/herald-worker/main.go index 6eb1775..0f2e3b8 100644 --- a/cmd/herald-worker/main.go +++ b/cmd/herald-worker/main.go @@ -12,10 +12,13 @@ func main() { for { // Do the buldpack thing. - herald.DownloadBuildpacks() + buildpacks := herald.GetBuildpacks() + for _, bp := range(buildpacks) { + log.Print(bp.Download()) + } log.Print("Sleeping for 5 minutes…") - + // Sleep for five minutes. time.Sleep(5*time.Minute) diff --git a/herald.go b/herald.go index 5f57a1b..ff1473f 100644 --- a/herald.go +++ b/herald.go @@ -10,35 +10,56 @@ import "log" const BP_TARBALL_TEMPLATE = "https://github.com/heroku/heroku-buildpack-%s/archive/master.zip" var BUILDPACKS = []string { "python", "php", "nodejs" } -func getBuildpackZipballs() []string { - collected := []string{} - - for _, bp := range(BUILDPACKS) { - // Add comment here. - collected = append(collected, fmt.Sprintf(BP_TARBALL_TEMPLATE, bp)) - } - - return collected +type Version string + +type Buildpack struct{ + Versions []Version + Tarball string + Path string + // ExecutablePath string + Name string } -func DownloadBuildpacks() { - - // create temp directory - // use 'fake' for now - target, err := ioutil.TempDir("", "buildpacks") - if err != nil { - log.Fatal(err) - } +func (b Buildpack) ZipballURI() string { + return fmt.Sprintf(BP_TARBALL_TEMPLATE, b.Name) +} +func (b Buildpack) Download() string { + target, _ := ioutil.TempDir("", "buildpacks") + + log.Printf("Downloading '%s'…", b.Name) + + getter.Get(target, b.ZipballURI()) + + return target - // Download and unpack each Zipball from GitHub. - for _, tb := range(getBuildpackZipballs()) { - log.Printf("Downloading '%s' to '%s'…", tb, target) - getter.Get(target, tb) +} + +func NewBuildpack(name string) Buildpack { + return Buildpack{ + // Path: nil, + // ExecutablePath: path + "/bin/execute", + Name: name, } } +func GetBuildpacks() []Buildpack { + // Download and unpack each Zipball from GitHub. + + buildpacks := []Buildpack{} + for _, bp := range(BUILDPACKS) { + // log.Printf("Downloading '%s'…", bp) + + // err := getter.Get(target, tb) + // if err != nil { + // return err + buildpacks = append(buildpacks, NewBuildpack(bp)) + } + + return buildpacks +} + // func ExecutesBuildpacks() { // glob('*/updater/detect'