Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrades to packit v2.2.0 #301

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
Layers: packit.Layers{Path: layersDir},
})
Expect(err).To(MatchError(`"invalid-format" is not a supported SBOM format`))
Expect(err).To(MatchError(`unsupported SBOM format: 'invalid-format'`))
})
})

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require (
github.com/mattn/go-shellwords v1.0.11-0.20201201010856-2c8720de5e83
github.com/onsi/gomega v1.19.0
github.com/paketo-buildpacks/occam v0.7.0
github.com/paketo-buildpacks/packit/v2 v2.1.0
github.com/paketo-buildpacks/packit/v2 v2.2.0
github.com/sclevine/spec v1.4.0
)
1,656 changes: 1,622 additions & 34 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
fmt.Sprintf(" Running 'go build -o /layers/%s/targets/bin -buildmode pie -trimpath .'", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
"",
fmt.Sprintf(" Generating SBOM for directory /layers/%s/targets/bin", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
fmt.Sprintf(" Generating SBOM for /layers/%s/targets/bin", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
"",
" Writing SBOM in the following format(s):",
Expand Down
58 changes: 58 additions & 0 deletions integration/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/paketo-buildpacks/occam"
Expand Down Expand Up @@ -34,33 +35,43 @@ func testMod(t *testing.T, context spec.G, it spec.S) {

name string
source string

sbomDir string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

sbomDir, err = os.MkdirTemp("", "sbom")
Expect(err).NotTo(HaveOccurred())
Expect(os.Chmod(sbomDir, os.ModePerm)).To(Succeed())
})

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())
Expect(os.RemoveAll(sbomDir)).To(Succeed())
})

it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "mod"))
Expect(err).NotTo(HaveOccurred())

Expect(os.RemoveAll(filepath.Join(source, "vendor"))).To(Succeed())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.GoDist.Online,
settings.Buildpacks.GoBuild.Online,
).
WithSBOMOutputDir(sbomDir).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

Expand All @@ -72,6 +83,53 @@ func testMod(t *testing.T, context spec.G, it spec.S) {
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(Serve(ContainSubstring("go1.17")).OnPort(8080))

// check that all required SBOM files are present
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.cdx.json")).To(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.spdx.json")).To(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.syft.json")).To(BeARegularFile())

// check an SBOM file to make sure it contains the expected dependency
contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.cdx.json"))
Expect(err).NotTo(HaveOccurred())
Expect(string(contents)).To(ContainSubstring(`"name": "github.com/gorilla/mux"`))
})
context("when there is a go.mod AND modules are vendored", func() {
it("populates an SBOM with vendored packages", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "mod"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.GoDist.Online,
settings.Buildpacks.GoBuild.Online,
).
WithSBOMOutputDir(sbomDir).
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("go1.17")).OnPort(8080))

// check that all required SBOM files are present
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.cdx.json")).To(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.spdx.json")).To(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.syft.json")).To(BeARegularFile())

// check an SBOM file to make sure it contains the expected dependency
contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "targets", "sbom.cdx.json"))
Expect(err).NotTo(HaveOccurred())
Expect(string(contents)).To(ContainSubstring(`"name": "github.com/gorilla/mux"`))
})
})
})
}

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

27 changes: 27 additions & 0 deletions integration/testdata/mod/vendor/github.com/gorilla/mux/LICENSE

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

Loading