From 1f851f2f131b75b143d958321f27e70a099e3698 Mon Sep 17 00:00:00 2001 From: Frankie G-J Date: Wed, 2 Mar 2022 17:29:22 -0500 Subject: [PATCH] Remove deprecated buildpack.yml (#282) * Remove buildpack.yml from README * remove buildpack.yml parsing --- README.md | 33 ------ build_configuration_parser.go | 27 +---- build_configuration_parser_test.go | 139 +----------------------- fakes/buildpack_yml_parser.go | 35 ------ go.mod | 3 - go.sum | 4 - go_buildpack_yml_parser.go | 85 --------------- go_buildpack_yml_parser_test.go | 166 ----------------------------- init_test.go | 1 - integration/buildpack_yml_test.go | 101 ------------------ integration/init_test.go | 1 - run/main.go | 2 +- 12 files changed, 7 insertions(+), 590 deletions(-) delete mode 100644 fakes/buildpack_yml_parser.go delete mode 100644 go_buildpack_yml_parser.go delete mode 100644 go_buildpack_yml_parser_test.go delete mode 100644 integration/buildpack_yml_test.go diff --git a/README.md b/README.md index 377c3354..f30e69e4 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,6 @@ when compiling your program. BP_GO_BUILD_LDFLAGS= -X main.variable=some-value ``` -_Note: Specifying the `Go Build` configuration through `buildpack.yml` configuration -will be deprecated in Go Build Buildpack v1.0.0._ - -To migrate from using `buildpack.yml` please set the following environment -variables at build time either directly (ex. `pack build my-app --env -BP_ENVIRONMENT_VARIABLE=some-value`) or through a [`project.toml` -file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md) - ### `BP_GO_TARGETS` The `BP_GO_TARGETS` variable allows you to specify multiple programs to be compiled. The first target will be used as the start command for the image. @@ -52,14 +44,6 @@ compiled. The first target will be used as the start command for the image. BP_GO_TARGETS=./cmd/web-server:./cmd/debug-server ``` -This will replace the following structure in `buildpack.yml`: -```yaml -go: - targets: - - ./cmd/web-server - - ./cmd/debug-server -``` - ### `BP_GO_BUILD_FLAGS` The `BP_GO_BUILD_FLAGS` variable allows you to override the default build flags when compiling your program. @@ -68,16 +52,6 @@ when compiling your program. BP_GO_BUILD_FLAGS= -buildmode=default -tags=paketo -ldflags="-X main.variable=some-value" ``` -This will replace the following structure in `buildpack.yml`: -```yaml -go: - build: - flags: - - -buildmode=default - - -tags=paketo - - -ldflags="-X main.variable=some-value" -``` - ### `BP_GO_BUILD_IMPORT_PATH` The `BP_GO_BUILD_IMPORT_PATH` allows you to specify an import path for your application. This is necessary if you are building a $GOPATH application that @@ -87,13 +61,6 @@ imports its own sub-packages. BP_GO_BUILD_IMPORT_PATH= example.com/some-app ``` -This will replace the following structure in `buildpack.yml`: -```yaml -go: - build: - import-path: example.com/some-app -``` - ### `BP_KEEP_FILES` The `BP_KEEP_FILES` variable allows to you to specity a path list of files (including file globs) that you would like to appear in the workspace of the diff --git a/build_configuration_parser.go b/build_configuration_parser.go index 05a825f4..6042ae4d 100644 --- a/build_configuration_parser.go +++ b/build_configuration_parser.go @@ -1,7 +1,6 @@ package gobuild import ( - "errors" "fmt" "os" "path/filepath" @@ -16,11 +15,6 @@ type TargetManager interface { GenerateDefaults(workingDir string) ([]string, error) } -//go:generate faux --interface BuildpackYMLParser --output fakes/buildpack_yml_parser.go -type BuildpackYMLParser interface { - Parse(buildpackVersion, workingDir string) (BuildConfiguration, error) -} - type BuildConfiguration struct { Targets []string Flags []string @@ -28,36 +22,23 @@ type BuildConfiguration struct { } type BuildConfigurationParser struct { - targetManager TargetManager - buildpackYMLParser BuildpackYMLParser + targetManager TargetManager } -func NewBuildConfigurationParser(targetManager TargetManager, buildpackYMLParser BuildpackYMLParser) BuildConfigurationParser { +func NewBuildConfigurationParser(targetManager TargetManager) BuildConfigurationParser { return BuildConfigurationParser{ - targetManager: targetManager, - buildpackYMLParser: buildpackYMLParser, + targetManager: targetManager, } } func (p BuildConfigurationParser) Parse(buildpackVersion, workingDir string) (BuildConfiguration, error) { var buildConfiguration BuildConfiguration - _, err := os.Stat(filepath.Join(workingDir, "buildpack.yml")) - if err != nil { - if !errors.Is(err, os.ErrNotExist) { - return BuildConfiguration{}, err - } - } else { - buildConfiguration, err = p.buildpackYMLParser.Parse(buildpackVersion, workingDir) - if err != nil { - return BuildConfiguration{}, err - } - } - if val, ok := os.LookupEnv("BP_GO_TARGETS"); ok { buildConfiguration.Targets = filepath.SplitList(val) } + var err error if len(buildConfiguration.Targets) > 0 { buildConfiguration.Targets, err = p.targetManager.CleanAndValidate(buildConfiguration.Targets, workingDir) if err != nil { diff --git a/build_configuration_parser_test.go b/build_configuration_parser_test.go index a96567ad..5c6394e0 100644 --- a/build_configuration_parser_test.go +++ b/build_configuration_parser_test.go @@ -3,7 +3,6 @@ package gobuild_test import ( "errors" "os" - "path/filepath" "testing" gobuild "github.com/paketo-buildpacks/go-build" @@ -19,8 +18,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) { workingDir string - targetManager *fakes.TargetManager - buildpackYMLParser *fakes.BuildpackYMLParser + targetManager *fakes.TargetManager parser gobuild.BuildConfigurationParser ) @@ -33,16 +31,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) { targetManager = &fakes.TargetManager{} targetManager.GenerateDefaultsCall.Returns.StringSlice = []string{"."} - buildpackYMLParser = &fakes.BuildpackYMLParser{} - buildpackYMLParser.ParseCall.Returns.BuildConfiguration = gobuild.BuildConfiguration{ - Targets: []string{"./first", "./second"}, - Flags: []string{ - "-first=value", - }, - ImportPath: "some-import-path", - } - - parser = gobuild.NewBuildConfigurationParser(targetManager, buildpackYMLParser) + parser = gobuild.NewBuildConfigurationParser(targetManager) }) it.After(func() { @@ -205,131 +194,7 @@ func testBuildConfigurationParser(t *testing.T, context spec.G, it spec.S) { }) }) - context("when there is a buildpack.yml and environment variables are not set", func() { - it.Before(func() { - err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644) - Expect(err).NotTo(HaveOccurred()) - - targetManager.CleanAndValidateCall.Returns.StringSlice = []string{"./first", "./second"} - }) - - it("parses the targets and flags from a buildpack.yml", func() { - configuration, err := parser.Parse("1.2.3", workingDir) - Expect(err).NotTo(HaveOccurred()) - Expect(configuration).To(Equal(gobuild.BuildConfiguration{ - Targets: []string{"./first", "./second"}, - Flags: []string{ - "-first=value", - }, - ImportPath: "some-import-path", - })) - - Expect(buildpackYMLParser.ParseCall.Receives.WorkingDir).To(Equal(workingDir)) - - Expect(targetManager.CleanAndValidateCall.Receives.Targets).To(Equal([]string{"./first", "./second"})) - Expect(targetManager.CleanAndValidateCall.Receives.WorkingDir).To(Equal(workingDir)) - }) - }) - - context("when there is a buildpack.yml and environment variables are set", func() { - it.Before(func() { - err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644) - Expect(err).NotTo(HaveOccurred()) - - os.Setenv("BP_GO_BUILD_IMPORT_PATH", "./some/import/path") - os.Setenv("BP_GO_TARGETS", "some/target1:./some/target2") - os.Setenv("BP_GO_BUILD_FLAGS", `-some-flag=some-value`) - - targetManager.CleanAndValidateCall.Returns.StringSlice = []string{"./some/target1", "./some/target2"} - }) - - it.After(func() { - os.Unsetenv("BP_GO_BUILD_IMPORT_PATH") - os.Unsetenv("BP_GO_TARGETS") - os.Unsetenv("BP_GO_BUILD_FLAGS") - }) - - it("parses the targets and flags from a buildpack.yml but uses the values from the environment variables", func() { - configuration, err := parser.Parse("1.2.3", workingDir) - Expect(err).NotTo(HaveOccurred()) - Expect(configuration).To(Equal(gobuild.BuildConfiguration{ - Targets: []string{"./some/target1", "./some/target2"}, - Flags: []string{ - "-some-flag=some-value", - }, - ImportPath: "./some/import/path", - })) - - Expect(buildpackYMLParser.ParseCall.Receives.WorkingDir).To(Equal(workingDir)) - Expect(targetManager.CleanAndValidateCall.Receives.Targets).To(Equal([]string{"some/target1", "./some/target2"})) - Expect(targetManager.CleanAndValidateCall.Receives.WorkingDir).To(Equal(workingDir)) - }) - }) - - context("buildpack.yml specifies flags including -ldflags and BP_GO_BUILD_LDFLAGS is set", func() { - it.Before(func() { - err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644) - Expect(err).NotTo(HaveOccurred()) - - buildpackYMLParser.ParseCall.Returns.BuildConfiguration = gobuild.BuildConfiguration{ - Targets: []string{"."}, - Flags: []string{ - `-ldflags="-buildpack -yml -flags"`, - `-otherflag`, - }, - } - - os.Setenv("BP_GO_BUILD_LDFLAGS", `-env -value`) - }) - - it.After(func() { - os.Unsetenv("BP_GO_BUILD_LDFLAGS") - }) - - it("uses build flags from the buildpack.yml EXCEPT -ldflags", func() { - configuration, err := parser.Parse("1.2.3", workingDir) - Expect(err).NotTo(HaveOccurred()) - Expect(configuration).To(Equal(gobuild.BuildConfiguration{ - Flags: []string{ - `-ldflags=-env -value`, - `-otherflag`, - }, - })) - - Expect(buildpackYMLParser.ParseCall.Receives.WorkingDir).To(Equal(workingDir)) - }) - }) - context("failure cases", func() { - context("when the buildpack.yml cannot be stat'd", func() { - it.Before(func() { - Expect(os.Chmod(workingDir, 0000)).To(Succeed()) - }) - - it.After(func() { - Expect(os.Chmod(workingDir, os.ModePerm)).To(Succeed()) - }) - - it("returns an error", func() { - _, err := parser.Parse("1.2.3", workingDir) - Expect(err).To(MatchError(ContainSubstring("permission denied"))) - }) - }) - - context("buildpack.yml parsing fails", func() { - it.Before(func() { - err := os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), nil, 0644) - Expect(err).NotTo(HaveOccurred()) - - buildpackYMLParser.ParseCall.Returns.Error = errors.New("failed to parse buildpack.yml") - }) - - it("returns an error", func() { - _, err := parser.Parse("1.2.3", workingDir) - Expect(err).To(MatchError("failed to parse buildpack.yml")) - }) - }) - context("go targets fail to be cleaned an validated", func() { it.Before(func() { os.Setenv("BP_GO_TARGETS", "./some/target") diff --git a/fakes/buildpack_yml_parser.go b/fakes/buildpack_yml_parser.go deleted file mode 100644 index 2610163b..00000000 --- a/fakes/buildpack_yml_parser.go +++ /dev/null @@ -1,35 +0,0 @@ -package fakes - -import ( - "sync" - - gobuild "github.com/paketo-buildpacks/go-build" -) - -type BuildpackYMLParser struct { - ParseCall struct { - mutex sync.Mutex - CallCount int - Receives struct { - BuildpackVersion string - WorkingDir string - } - Returns struct { - BuildConfiguration gobuild.BuildConfiguration - Error error - } - Stub func(string, string) (gobuild.BuildConfiguration, error) - } -} - -func (f *BuildpackYMLParser) Parse(param1 string, param2 string) (gobuild.BuildConfiguration, error) { - f.ParseCall.mutex.Lock() - defer f.ParseCall.mutex.Unlock() - f.ParseCall.CallCount++ - f.ParseCall.Receives.BuildpackVersion = param1 - f.ParseCall.Receives.WorkingDir = param2 - if f.ParseCall.Stub != nil { - return f.ParseCall.Stub(param1, param2) - } - return f.ParseCall.Returns.BuildConfiguration, f.ParseCall.Returns.Error -} diff --git a/go.mod b/go.mod index 43eed8f2..99dc7aab 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,9 @@ go 1.16 require ( github.com/BurntSushi/toml v1.0.0 - github.com/Masterminds/semver v1.5.0 - github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251 github.com/mattn/go-shellwords v1.0.11-0.20201201010856-2c8720de5e83 github.com/onsi/gomega v1.18.1 github.com/paketo-buildpacks/occam v0.6.0 github.com/paketo-buildpacks/packit/v2 v2.1.0 github.com/sclevine/spec v1.4.0 - gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 673795c1..f1f512c1 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,6 @@ github.com/CycloneDX/cyclonedx-go v0.4.0 h1:Wz4QZ9B4RXGWIWTypVLEOVJgOdFfy5mcS5PG github.com/CycloneDX/cyclonedx-go v0.4.0/go.mod h1:rmRcf//gT7PIzovatusbWi377xqCg1FS4jyST0GH20E= github.com/ForestEckhardt/freezer v0.0.10 h1:CQbYPeA/KxXMZhNeRd3Mk7IYV9uw7w9OkmW4alHqIFw= github.com/ForestEckhardt/freezer v0.0.10/go.mod h1:GHguI9kaXxL6on564JrxYs25dWuMqbqTYQVtvnkH4os= -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= @@ -150,8 +148,6 @@ github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7 github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8= github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= -github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251 h1:k6UDF1uPYOs0iy1HPeotNa155qXRWrzKnqAaGXHLZCE= -github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251/go.mod h1:gbPR1gPu9dB96mucYIR7T3B7p/78hRVSOuzIWLHK2Y4= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= diff --git a/go_buildpack_yml_parser.go b/go_buildpack_yml_parser.go deleted file mode 100644 index 3c28846d..00000000 --- a/go_buildpack_yml_parser.go +++ /dev/null @@ -1,85 +0,0 @@ -package gobuild - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/Masterminds/semver" - "github.com/buildkite/interpolate" - "github.com/paketo-buildpacks/packit/v2/scribe" - "gopkg.in/yaml.v2" -) - -type GoBuildpackYMLParser struct { - logger scribe.Emitter -} - -func NewGoBuildpackYMLParser(logger scribe.Emitter) GoBuildpackYMLParser { - return GoBuildpackYMLParser{ - logger: logger, - } -} - -func (p GoBuildpackYMLParser) Parse(buildpackVersion, workingDir string) (BuildConfiguration, error) { - file, err := os.Open(filepath.Join(workingDir, "buildpack.yml")) - if err != nil { - return BuildConfiguration{}, fmt.Errorf("failed to read buildpack.yml: %w", err) - } - - var config struct { - Go struct { - Targets []string `yaml:"targets"` - Build struct { - Flags []string `yaml:"flags"` - ImportPath string `yaml:"import-path"` - } `yaml:"build"` - } `yaml:"go"` - } - - err = yaml.NewDecoder(file).Decode(&config) - if err != nil { - return BuildConfiguration{}, fmt.Errorf("failed to decode buildpack.yml: %w", err) - } - - var buildFlags []string - for _, flag := range config.Go.Build.Flags { - for _, f := range splitFlags(flag) { - interpolatedFlag, err := interpolate.Interpolate(interpolate.NewSliceEnv(os.Environ()), f) - if err != nil { - return BuildConfiguration{}, fmt.Errorf("environment variable expansion failed: %w", err) - } - buildFlags = append(buildFlags, interpolatedFlag) - } - } - config.Go.Build.Flags = buildFlags - - buildConfiguration := BuildConfiguration{ - Targets: config.Go.Targets, - Flags: config.Go.Build.Flags, - ImportPath: config.Go.Build.ImportPath, - } - - if buildConfiguration.Targets != nil || buildConfiguration.Flags != nil || buildConfiguration.ImportPath != "" { - nextMajorVersion := semver.MustParse(buildpackVersion).IncMajor() - p.logger.Process("WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v%s.", nextMajorVersion.String()) - p.logger.Process("Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information.") - p.logger.Break() - } - - return buildConfiguration, nil -} - -func splitFlags(flag string) []string { - parts := strings.SplitN(flag, "=", 2) - if len(parts) == 2 { - if len(parts[1]) >= 2 { - if c := parts[1][len(parts[1])-1]; parts[1][0] == c && (c == '"' || c == '\'') { - parts[1] = parts[1][1 : len(parts[1])-1] - } - } - } - - return parts -} diff --git a/go_buildpack_yml_parser_test.go b/go_buildpack_yml_parser_test.go deleted file mode 100644 index 967d85af..00000000 --- a/go_buildpack_yml_parser_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package gobuild_test - -import ( - "bytes" - "os" - "path/filepath" - "testing" - - gobuild "github.com/paketo-buildpacks/go-build" - "github.com/paketo-buildpacks/packit/v2/scribe" - "github.com/sclevine/spec" - - . "github.com/onsi/gomega" -) - -func testGoBuildpackYMLParser(t *testing.T, context spec.G, it spec.S) { - var ( - Expect = NewWithT(t).Expect - - workingDir string - logs *bytes.Buffer - - goBuildpackYMLParser gobuild.GoBuildpackYMLParser - ) - - it.Before(func() { - var err error - workingDir, err = os.MkdirTemp("", "working-dir") - Expect(err).NotTo(HaveOccurred()) - - Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`--- -go: - targets: - - first - - ./second - build: - flags: - - -first - - value - - -second=value - import-path: some-import-path -`), 0644)).To(Succeed()) - - logs = bytes.NewBuffer(nil) - goBuildpackYMLParser = gobuild.NewGoBuildpackYMLParser(scribe.NewEmitter(logs)) - }) - - it.After(func() { - Expect(os.RemoveAll(workingDir)).To(Succeed()) - }) - - context("Parse", func() { - it("parses the buildpack and returns a build configuration", func() { - config, err := goBuildpackYMLParser.Parse("1.2.3", workingDir) - Expect(err).NotTo(HaveOccurred()) - - Expect(config).To(Equal(gobuild.BuildConfiguration{ - Targets: []string{"first", "./second"}, - Flags: []string{ - "-first", - "value", - "-second", - "value", - }, - ImportPath: "some-import-path", - })) - Expect(logs.String()).To(ContainSubstring("WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v2.0.0.")) - Expect(logs.String()).To(ContainSubstring("Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information.")) - }) - - context("when the flags have an env var in them", func() { - it.Before(func() { - Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`--- -go: - build: - flags: - - -first=$FIRST - - -second=${SECOND} -`), 0644)).To(Succeed()) - - os.Setenv("FIRST", "first-val") - os.Setenv("SECOND", "second-val") - }) - - it.After(func() { - os.Unsetenv("FIRST") - os.Unsetenv("SECOND") - }) - - it("interpolates the env vars those into the flags", func() { - config, err := goBuildpackYMLParser.Parse("1.2.3", workingDir) - Expect(err).NotTo(HaveOccurred()) - - Expect(config).To(Equal(gobuild.BuildConfiguration{ - Flags: []string{ - "-first", - "first-val", - "-second", - "second-val", - }, - })) - }) - }, spec.Sequential()) - - context("when the buildpack.yml does not contain go configuration", func() { - it.Before(func() { - Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`--- -not-go: - build: - flags: - - -first=value -`), 0644)).To(Succeed()) - }) - - it("does not return a deprecation message", func() { - config, err := goBuildpackYMLParser.Parse("1.2.3", workingDir) - Expect(err).NotTo(HaveOccurred()) - - Expect(config).To(Equal(gobuild.BuildConfiguration{})) - Expect(logs.String()).To(BeEmpty()) - }) - }) - - context("failure cases", func() { - context("buildpack.yml cannot be opened", func() { - it.Before(func() { - Expect(os.Chmod(filepath.Join(workingDir, "buildpack.yml"), 0000)).To(Succeed()) - }) - - it("returns an error", func() { - _, err := goBuildpackYMLParser.Parse("1.2.3", workingDir) - Expect(err).To(MatchError(ContainSubstring("failed to read buildpack.yml"))) - Expect(err).To(MatchError(ContainSubstring("permission denied"))) - }) - }) - - context("buildpack.yml fails to parse", func() { - it.Before(func() { - Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`%%%`), 0644)).To(Succeed()) - }) - - it("returns an error", func() { - _, err := goBuildpackYMLParser.Parse("1.2.3", workingDir) - Expect(err).To(MatchError(ContainSubstring("failed to decode buildpack.yml"))) - Expect(err).To(MatchError(ContainSubstring("could not find expected directive name"))) - }) - }) - - context("when a the env var interpolation fails", func() { - it.Before(func() { - Expect(os.WriteFile(filepath.Join(workingDir, "buildpack.yml"), []byte(`--- -go: - build: - flags: - - -first=$& -`), 0644)).To(Succeed()) - }) - - it("returns an error", func() { - _, err := goBuildpackYMLParser.Parse("1.2.3", workingDir) - Expect(err).To(MatchError(ContainSubstring("environment variable expansion failed:"))) - }) - }) - }) - }) -} diff --git a/init_test.go b/init_test.go index beb068e7..f7ce2e0c 100644 --- a/init_test.go +++ b/init_test.go @@ -13,7 +13,6 @@ func TestUnitGoBuild(t *testing.T) { suite("BuildConfigurationParser", testBuildConfigurationParser, spec.Sequential()) suite("Detect", testDetect, spec.Sequential()) suite("GoBuildProcess", testGoBuildProcess) - suite("GoBuildpackYMLParser", testGoBuildpackYMLParser) suite("GoPathManager", testGoPathManager) suite("GoTargetManager", testGoTargetManager) suite("SourceDeleter", testSourceDeleter) diff --git a/integration/buildpack_yml_test.go b/integration/buildpack_yml_test.go deleted file mode 100644 index f19e5d41..00000000 --- a/integration/buildpack_yml_test.go +++ /dev/null @@ -1,101 +0,0 @@ -package integration_test - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/paketo-buildpacks/occam" - "github.com/sclevine/spec" - - . "github.com/onsi/gomega" - . "github.com/paketo-buildpacks/occam/matchers" -) - -func testBuildpackYML(t *testing.T, context spec.G, it spec.S) { - var ( - Expect = NewWithT(t).Expect - Eventually = NewWithT(t).Eventually - - pack occam.Pack - docker occam.Docker - ) - - it.Before(func() { - pack = occam.NewPack().WithVerbose().WithNoColor() - docker = occam.NewDocker() - }) - - context("when building an app with multiple targets", func() { - var ( - image occam.Image - container occam.Container - - name string - source string - ) - - it.Before(func() { - var err error - name, err = occam.RandomName() - Expect(err).NotTo(HaveOccurred()) - - source, err = occam.Source(filepath.Join("testdata", "targets")) - Expect(err).NotTo(HaveOccurred()) - - err = os.WriteFile(filepath.Join(source, "buildpack.yml"), []byte(`--- -go: - targets: - - first - - ./second`), 0600) - Expect(err).NotTo(HaveOccurred()) - }) - - it.After(func() { - Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed()) - Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) - Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) - Expect(os.RemoveAll(source)).To(Succeed()) - }) - - context("when building an app with target specified via BP_GO_TARGETS env", func() { - it("builds succesfully and overrides buildpack.yml while still printing a warning", func() { - var err error - var logs fmt.Stringer - image, logs, err = pack.Build. - WithPullPolicy("never"). - WithEnv(map[string]string{"BP_GO_TARGETS": "./third"}). - WithBuildpacks( - settings.Buildpacks.GoDist.Online, - settings.Buildpacks.GoBuild.Online, - ). - Execute(name, source) - Expect(err).ToNot(HaveOccurred(), logs.String) - - container, err = docker.Container.Run. - WithEnv(map[string]string{"PORT": "8080"}). - WithPublish("8080"). - WithPublishAll(). - Execute(image.ID) - Expect(err).NotTo(HaveOccurred()) - - Eventually(container).Should(Serve(ContainSubstring("third: go1.16")).OnPort(8080)) - - Expect(logs).To(ContainLines( - MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)), - " WARNING: Setting the Go Build configurations such as targets, build flags, and import path through buildpack.yml will be deprecated soon in Go Build Buildpack v2.0.0.", - " Please specify these configuration options through environment variables instead. See README.md or the documentation on paketo.io for more information.", - "", - )) - Expect(logs).To(ContainLines( - " Executing build process", - fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie -trimpath ./third'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")), - MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`), - "", - )) - }) - }) - }) -} diff --git a/integration/init_test.go b/integration/init_test.go index cc68ca45..db46aa3d 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -100,7 +100,6 @@ func TestIntegration(t *testing.T) { suite := spec.New("Integration", spec.Report(report.Terminal{}), spec.Parallel()) suite("BuildFailure", testBuildFailure) suite("BuildFlags", testBuildFlags) - suite("BuildpackYML", testBuildpackYML) suite("Default", testDefault) suite("ImportPath", testImportPath) suite("KeepFiles", testKeepFiles) diff --git a/run/main.go b/run/main.go index 66b6faa3..468d8fc9 100644 --- a/run/main.go +++ b/run/main.go @@ -20,7 +20,7 @@ func (f Generator) Generate(dir string) (sbom.SBOM, error) { func main() { emitter := scribe.NewEmitter(os.Stdout).WithLevel(os.Getenv("BP_LOG_LEVEL")) - configParser := gobuild.NewBuildConfigurationParser(gobuild.NewGoTargetManager(), gobuild.NewGoBuildpackYMLParser(emitter)) + configParser := gobuild.NewBuildConfigurationParser(gobuild.NewGoTargetManager()) packit.Run( gobuild.Detect(