From 77c6393a5fb9039589cf429dd902362edda3939e Mon Sep 17 00:00:00 2001 From: Don Nguyen Date: Mon, 19 Aug 2019 18:45:48 -0400 Subject: [PATCH] Do not reuse packages layer [#167655092] --- dep/dep.go | 6 +-- integration/integration_test.go | 43 ++++++++----------- .../with_lockfile_modified/Gopkg.lock | 15 +++++++ .../with_lockfile_modified/Gopkg.toml | 4 ++ .../with_lockfile_modified/buildpack.yml | 2 + .../testdata/with_lockfile_modified/site.go | 27 ++++++++++++ 6 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 integration/testdata/with_lockfile_modified/Gopkg.lock create mode 100644 integration/testdata/with_lockfile_modified/Gopkg.toml create mode 100644 integration/testdata/with_lockfile_modified/buildpack.yml create mode 100644 integration/testdata/with_lockfile_modified/site.go diff --git a/dep/dep.go b/dep/dep.go index fc3c5d3..2447c52 100644 --- a/dep/dep.go +++ b/dep/dep.go @@ -57,9 +57,6 @@ type Runner interface { } func NewContributor(context build.Build, runner Runner) (Contributor, bool, error) { - - - dependency, wantDependency, err := context.Plans.GetShallowMerged(Dependency) if err != nil { return Contributor{}, false, nil @@ -173,9 +170,8 @@ func (c *Contributor) ContributePackages() error { os.Stdout, os.Stderr, depBin, "ensure") - }, layers.Cache) + }) } - func (c *Contributor) ContributeBinary() error { return c.appBinaryLayer.Contribute(getAppBinaryMetadata(), func(layer layers.Layer) error { layer.Logger.SubsequentLine("Running `go install`") diff --git a/integration/integration_test.go b/integration/integration_test.go index b244897..75cf7e9 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -77,43 +77,34 @@ func testIntegration(t *testing.T, when spec.G, it spec.S) { Expect(app.BuildLogs()).To(MatchRegexp("Dep.*: Contributing to layer")) }) - it("uses Gopkg.lock as a lockfile for re-builds", func() { - appDir := filepath.Join("testdata", "with_lockfile") + it("uses the vendored packages when the app is vendored", func() { + appDir := filepath.Join("testdata", "vendored_app") app, err := dagger.PackBuild(appDir, goURI, depURI) Expect(err).ToNot(HaveOccurred()) - defer app.Destroy() - - depPrefix := "Dep \\d*\\.\\d*\\.\\d*: " - depPackagesPrefix := "Dep Packages \\w*: " - contributeMsg := "Contributing to layer" - Expect(app.BuildLogs()).To(MatchRegexp(depPrefix + contributeMsg)) - Expect(app.BuildLogs()).To(MatchRegexp(depPackagesPrefix + contributeMsg)) - _, imageID, _, err := app.Info() - Expect(err).NotTo(HaveOccurred()) + Expect(app.BuildLogs()).To(ContainSubstring("Note: skipping `dep ensure` due to non-empty vendor directory.")) - app, err = dagger.PackBuildNamedImage(imageID, appDir, goURI, depURI) + Expect(app.Start()).To(Succeed()) + _, _, err = app.HTTPGet("/") Expect(err).ToNot(HaveOccurred()) + }) - rebuildLogs := app.BuildLogs() - reuseMsg := "Reusing cached layer" - Expect(rebuildLogs).To(MatchRegexp(depPrefix + reuseMsg)) - Expect(rebuildLogs).To(MatchRegexp(depPackagesPrefix + reuseMsg)) - Expect(app.Start()).To(Succeed()) + it("uses updated source code on a rebuild", func() { + appRoot := filepath.Join("testdata", "with_lockfile") - _, _, err = app.HTTPGet("/") + app, err := dagger.PackBuild(appRoot, goURI, depURI) Expect(err).NotTo(HaveOccurred()) - }) + defer app.Destroy() - it("uses the vendored packages when the app is vendored", func() { - appDir := filepath.Join("testdata", "vendored_app") - app, err := dagger.PackBuild(appDir, goURI, depURI) Expect(err).ToNot(HaveOccurred()) + Expect(app.BuildLogs()).To(MatchRegexp("Dep.*: Contributing to layer")) - Expect(app.BuildLogs()).To(ContainSubstring("Note: skipping `dep ensure` due to non-empty vendor directory.")) - + _, imageID, _, err := app.Info() + appRoot = filepath.Join("testdata", "with_lockfile_modified") + app, err = dagger.PackBuildNamedImage(imageID, appRoot, goURI, depURI) Expect(app.Start()).To(Succeed()) - _, _, err = app.HTTPGet("/") - Expect(err).ToNot(HaveOccurred()) + body, _, err := app.HTTPGet("/") + Expect(err).NotTo(HaveOccurred()) + Expect(body).To(ContainSubstring("The source changed!")) }) } diff --git a/integration/testdata/with_lockfile_modified/Gopkg.lock b/integration/testdata/with_lockfile_modified/Gopkg.lock new file mode 100644 index 0000000..5e9c7b1 --- /dev/null +++ b/integration/testdata/with_lockfile_modified/Gopkg.lock @@ -0,0 +1,15 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/ZiCog/shiny-thing" + packages = ["foo"] + revision = "e9e19444ccf5362bba846441c4700a49a94b8118" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "f508e7d90d5c3c48e1df5c85f51b6a6bfd4f99f4d6fa4d515d678c07e30a5da6" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/integration/testdata/with_lockfile_modified/Gopkg.toml b/integration/testdata/with_lockfile_modified/Gopkg.toml new file mode 100644 index 0000000..5308f2f --- /dev/null +++ b/integration/testdata/with_lockfile_modified/Gopkg.toml @@ -0,0 +1,4 @@ + +[[constraint]] + branch = "master" + name = "github.com/ZiCog/shiny-thing" diff --git a/integration/testdata/with_lockfile_modified/buildpack.yml b/integration/testdata/with_lockfile_modified/buildpack.yml new file mode 100644 index 0000000..13f4aa3 --- /dev/null +++ b/integration/testdata/with_lockfile_modified/buildpack.yml @@ -0,0 +1,2 @@ +go: + import-path: hubgit.net/user/app diff --git a/integration/testdata/with_lockfile_modified/site.go b/integration/testdata/with_lockfile_modified/site.go new file mode 100644 index 0000000..c65725f --- /dev/null +++ b/integration/testdata/with_lockfile_modified/site.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "net/http" + "os" + + "github.com/ZiCog/shiny-thing/foo" +) + +func main() { + foo.Do() + http.HandleFunc("/", hello) + port := "8080" + if os.Getenv("PORT") != "" { + port = os.Getenv("PORT") + } + fmt.Println(fmt.Sprintf("listening on %s...", port)) + err := http.ListenAndServe(":"+port, nil) + if err != nil { + panic(err) + } +} + +func hello(res http.ResponseWriter, req *http.Request) { + fmt.Fprintln(res, "The source changed!") +}