Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Do not reuse packages layer [#167655092]
Browse files Browse the repository at this point in the history
  • Loading branch information
ndon55555 committed Aug 19, 2019
1 parent d8bdde3 commit 77c6393
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 31 deletions.
6 changes: 1 addition & 5 deletions dep/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`")
Expand Down
43 changes: 17 additions & 26 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!"))
})
}
15 changes: 15 additions & 0 deletions integration/testdata/with_lockfile_modified/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions integration/testdata/with_lockfile_modified/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[[constraint]]
branch = "master"
name = "github.com/ZiCog/shiny-thing"
2 changes: 2 additions & 0 deletions integration/testdata/with_lockfile_modified/buildpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go:
import-path: hubgit.net/user/app
27 changes: 27 additions & 0 deletions integration/testdata/with_lockfile_modified/site.go
Original file line number Diff line number Diff line change
@@ -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!")
}

0 comments on commit 77c6393

Please sign in to comment.