-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert from powershell to libbuildpack
- This enables use as a multi buildpack finalizer.
- Loading branch information
Showing
15 changed files
with
309 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/go_buildpack-*.zip | ||
/bin/finalize.exe | ||
/bin/supply.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1 | ||
0.1.0 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gowindowsbuildpack | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/cloudfoundry/libbuildpack" | ||
) | ||
|
||
type Finalizer struct { | ||
Manifest Manifest | ||
Stager Stager | ||
Command Command | ||
Log *libbuildpack.Logger | ||
} | ||
|
||
func (f *Finalizer) Run() error { | ||
f.Log.BeginStep("Go Build") | ||
cmd := exec.Command("go", "build", "-o", "myapp.exe", ".") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
cmd.Dir = f.Stager.BuildDir() | ||
cmd.Env = append(os.Environ(), "GOROOT="+f.Stager.DepDir()) | ||
if err := f.Command.Run(cmd); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/cloudfoundry/libbuildpack" | ||
bp "github.com/dgodd/go-windows-buildpack" | ||
) | ||
|
||
func main() { | ||
logger := libbuildpack.NewLogger(os.Stdout) | ||
|
||
buildpackDir, err := libbuildpack.GetBuildpackDir() | ||
if err != nil { | ||
logger.Error("Unable to determine buildpack directory: %s", err.Error()) | ||
os.Exit(9) | ||
} | ||
|
||
manifest, err := libbuildpack.NewManifest(buildpackDir, logger, time.Now()) | ||
if err != nil { | ||
logger.Error("Unable to load buildpack manifest: %s", err.Error()) | ||
os.Exit(10) | ||
} | ||
|
||
stager := libbuildpack.NewStager(os.Args[1:], logger, manifest) | ||
|
||
if err = manifest.ApplyOverride(stager.DepsDir()); err != nil { | ||
logger.Error("Unable to apply override.yml files: %s", err) | ||
os.Exit(17) | ||
} | ||
|
||
if err := stager.SetStagingEnvironment(); err != nil { | ||
logger.Error("Unable to setup environment variables: %s", err.Error()) | ||
os.Exit(11) | ||
} | ||
|
||
f := bp.Finalizer{ | ||
Manifest: manifest, | ||
Stager: stager, | ||
Command: &libbuildpack.Command{}, | ||
Log: logger, | ||
} | ||
|
||
if err := f.Run(); err != nil { | ||
os.Exit(12) | ||
} | ||
|
||
if err := libbuildpack.RunAfterCompile(stager); err != nil { | ||
logger.Error("After Compile: %s", err.Error()) | ||
os.Exit(13) | ||
} | ||
|
||
if err := stager.SetLaunchEnvironment(); err != nil { | ||
logger.Error("Unable to setup launch environment: %s", err.Error()) | ||
os.Exit(14) | ||
} | ||
|
||
stager.StagingComplete() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/dgodd/go-windows-buildpack | ||
|
||
require github.com/cloudfoundry/libbuildpack v0.0.0-20190115190946-c10a4cd29881 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= | ||
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= | ||
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= | ||
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= | ||
github.com/cloudfoundry/libbuildpack v0.0.0-20190115190946-c10a4cd29881 h1:640+S316H9WsAQKPvI99n+0k6n/Wp1cFIHRql6fRkqM= | ||
github.com/cloudfoundry/libbuildpack v0.0.0-20190115190946-c10a4cd29881/go.mod h1:rdSHSV2PLp7YHbdQgYbYMSmE6NJ1ZOAYnhMBQdkUVx0= | ||
github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= | ||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= | ||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | ||
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= | ||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= | ||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= | ||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
github.com/google/subcommands v0.0.0-20181012225330-46f0354f6315/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= | ||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= | ||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | ||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= | ||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= | ||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= | ||
github.com/tidwall/gjson v1.1.3/go.mod h1:c/nTNbUr0E0OrXEhq1pwa8iEgc2DOt4ZZqAt1HtCkPA= | ||
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= | ||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= | ||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= | ||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 h1:IcgEB62HYgAhX0Nd/QrVgZlxlcyxbGQHElLUhW2X4Fo= | ||
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= | ||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | ||
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20181117152235-275e9df93516 h1:H6trpavCIuipdInWrab8l34Mf+GGVfphniHostMdMaQ= | ||
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20181117152235-275e9df93516/go.mod h1:d3R+NllX3X5e0zlG1Rful3uLvsGC/Q3OHut5464DEQw= | ||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= | ||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= | ||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gowindowsbuildpack | ||
|
||
import ( | ||
"io" | ||
"os/exec" | ||
|
||
"github.com/cloudfoundry/libbuildpack" | ||
) | ||
|
||
type Stager interface { | ||
BuildDir() string | ||
CacheDir() string | ||
DepDir() string | ||
} | ||
|
||
type Manifest interface { | ||
DefaultVersion(string) (libbuildpack.Dependency, error) | ||
} | ||
|
||
type Installer interface { | ||
InstallOnlyVersion(string, string) error | ||
} | ||
|
||
type Command interface { | ||
Execute(string, io.Writer, io.Writer, string, ...string) error | ||
Run(*exec.Cmd) error | ||
// Output(dir string, program string, args ...string) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
language: go | ||
dependencies: | ||
- name: go | ||
version: 1.11.4 | ||
uri: https://dl.google.com/go/go1.11.4.windows-amd64.zip | ||
sha256: eeb20e21702f2b9469d9381df5de85e2f731b64a1f54effe196d0f7d0227fe14 | ||
cf_stacks: | ||
- windows2016 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gowindowsbuildpack | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/cloudfoundry/libbuildpack" | ||
) | ||
|
||
type Supplier struct { | ||
Manifest Manifest | ||
Installer Installer | ||
Stager Stager | ||
Command Command | ||
Log *libbuildpack.Logger | ||
} | ||
|
||
func (s *Supplier) Run() error { | ||
s.Log.BeginStep("Supplying go") | ||
|
||
if err := s.Installer.InstallOnlyVersion("go", s.Stager.DepDir()); err != nil { | ||
return err | ||
} | ||
files, err := ioutil.ReadDir(filepath.Join(s.Stager.DepDir(), "go")) | ||
if err != nil { | ||
return err | ||
} | ||
for _, file := range files { | ||
os.Remove(filepath.Join(s.Stager.DepDir(), file.Name())) | ||
if err := os.Rename(filepath.Join(s.Stager.DepDir(), "go", file.Name()), filepath.Join(s.Stager.DepDir(), file.Name())); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return os.Remove(filepath.Join(s.Stager.DepDir(), "go")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/cloudfoundry/libbuildpack" | ||
bp "github.com/dgodd/go-windows-buildpack" | ||
) | ||
|
||
func main() { | ||
logger := libbuildpack.NewLogger(os.Stdout) | ||
|
||
buildpackDir, err := libbuildpack.GetBuildpackDir() | ||
if err != nil { | ||
logger.Error("Unable to determine buildpack directory: %s", err.Error()) | ||
os.Exit(9) | ||
} | ||
|
||
manifest, err := libbuildpack.NewManifest(buildpackDir, logger, time.Now()) | ||
if err != nil { | ||
logger.Error("Unable to load buildpack manifest: %s", err.Error()) | ||
os.Exit(10) | ||
} | ||
installer := libbuildpack.NewInstaller(manifest) | ||
|
||
stager := libbuildpack.NewStager(os.Args[1:], logger, manifest) | ||
if err := stager.CheckBuildpackValid(); err != nil { | ||
os.Exit(11) | ||
} | ||
|
||
os.MkdirAll(filepath.Join(stager.DepDir(), "bin"), 0755) | ||
os.MkdirAll(filepath.Join(stager.DepDir(), "lib"), 0755) | ||
|
||
if err = installer.SetAppCacheDir(stager.CacheDir()); err != nil { | ||
logger.Error("Unable to setup app cache dir: %s", err) | ||
os.Exit(18) | ||
} | ||
if err = manifest.ApplyOverride(stager.DepsDir()); err != nil { | ||
logger.Error("Unable to apply override.yml files: %s", err) | ||
os.Exit(17) | ||
} | ||
|
||
err = libbuildpack.RunBeforeCompile(stager) | ||
if err != nil { | ||
logger.Error("Before Compile: %s", err.Error()) | ||
os.Exit(12) | ||
} | ||
|
||
if err := os.MkdirAll(filepath.Join(stager.DepDir(), "bin"), 0755); err != nil { | ||
logger.Error("Unable to create bin directory: %s", err.Error()) | ||
os.Exit(13) | ||
} | ||
|
||
err = stager.SetStagingEnvironment() | ||
if err != nil { | ||
logger.Error("Unable to setup environment variables: %s", err.Error()) | ||
os.Exit(14) | ||
} | ||
|
||
s := bp.Supplier{ | ||
Manifest: manifest, | ||
Installer: installer, | ||
Stager: stager, | ||
Command: &libbuildpack.Command{}, | ||
Log: logger, | ||
} | ||
|
||
err = s.Run() | ||
if err != nil { | ||
logger.Error("Error: %s", err) | ||
os.Exit(15) | ||
} | ||
|
||
if err := stager.WriteConfigYml(nil); err != nil { | ||
logger.Error("Error writing config.yml: %s", err.Error()) | ||
os.Exit(16) | ||
} | ||
if err = installer.CleanupAppCache(); err != nil { | ||
logger.Error("Unable clean up app cache: %s", err) | ||
os.Exit(19) | ||
} | ||
} |