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

Adding builder-ubi-buildpackless-base on integration tests #448

Merged
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
6 changes: 4 additions & 2 deletions integration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"builders": [
"index.docker.io/paketobuildpacks/builder:buildpackless-base",
"index.docker.io/paketobuildpacks/builder-jammy-buildpackless-base:latest"
"index.docker.io/paketobuildpacks/builder-jammy-buildpackless-base:latest",
"index.docker.io/paketocommunity/builder-ubi-buildpackless-base:latest"
],
"buildplan": "github.com/ForestEckhardt/build-plan"
"buildplan": "github.com/paketo-community/build-plan",
"ubi-nodejs-extension": "github.com/paketo-community/ubi-nodejs-extension"
}
50 changes: 33 additions & 17 deletions integration/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {

pack occam.Pack
docker occam.Docker

pullPolicy = "never"
)

it.Before(func() {
pack = occam.NewPack().WithVerbose()
docker = occam.NewDocker()

if settings.Extensions.UbiNodejsExtension.Online != "" {
pullPolicy = "always"
}
})

context("when the buildpack is run with pack build", func() {
Expand Down Expand Up @@ -68,16 +74,21 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
)

image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(buildpack, buildPlanBuildpack).
WithExtensions(
settings.Extensions.UbiNodejsExtension.Online,
).
WithBuildpacks(
settings.Buildpacks.Yarn.Online,
settings.Buildpacks.BuildPlan.Online,
).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asked @pacostas about this change, it was done to be consistent with all of the other buildpack integration tests.

WithSBOMOutputDir(sbomDir).
WithEnv(map[string]string{"BP_LOG_LEVEL": "DEBUG"}).
WithPullPolicy(pullPolicy).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

// Ensure yarn is installed correctly

container, err = docker.Container.Run.WithCommand("which yarn").Execute(image.ID)
container, err = docker.Container.Run.WithCommand("command -v yarn").Execute(image.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked @pacostas about this, we don't install which by default in the ubi stack, this allows the test to run for both ubi and jammy

Expect(err).NotTo(HaveOccurred())

Eventually(func() string {
Expand All @@ -87,12 +98,12 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
}).Should(ContainSubstring("yarn"))

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, buildpackInfo.Buildpack.Name)),
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Executing build process",
MatchRegexp(` Installing Yarn`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
"",
fmt.Sprintf(" Generating SBOM for /layers/%s/yarn", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
fmt.Sprintf(" Generating SBOM for /layers/%s/yarn", strings.ReplaceAll(settings.Buildpack.ID, "/", "_")),
MatchRegexp(` Completed in \d+(\.?\d+)*`),
"",
" Writing SBOM in the following format(s):",
Expand All @@ -103,12 +114,12 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
))

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

// check an SBOM file to make sure it has an entry for yarn
contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json"))
contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json"))
Expect(err).NotTo(HaveOccurred())

Expect(string(contents)).To(ContainSubstring(`"name": "Yarn"`))
Expand Down Expand Up @@ -155,8 +166,13 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
)

image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(buildpack, buildPlanBuildpack).
WithExtensions(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar change to previous for consistenccy with other buildpack integration tests.

settings.Extensions.UbiNodejsExtension.Online,
).
WithPullPolicy(pullPolicy).
WithBuildpacks(
settings.Buildpacks.Yarn.Online,
settings.Buildpacks.BuildPlan.Online).
WithSBOMOutputDir(sbomDir).
WithEnv(map[string]string{
"BP_LOG_LEVEL": "DEBUG",
Expand All @@ -166,7 +182,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
Expect(err).ToNot(HaveOccurred(), logs.String)

// Ensure yarn is installed correctly
container, err = docker.Container.Run.WithCommand("which yarn").Execute(image.ID)
container, err = docker.Container.Run.WithCommand("command -v yarn").Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(func() string {
Expand All @@ -176,7 +192,7 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
}).Should(ContainSubstring("yarn"))

Expect(logs).To(ContainLines(
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, buildpackInfo.Buildpack.Name)),
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Executing build process",
MatchRegexp(` Installing Yarn`),
MatchRegexp(` Completed in ([0-9]*(\.[0-9]*)?[a-z]+)+`),
Expand All @@ -185,9 +201,9 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
))

// check that SBOM files were not generated
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")).ToNot(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.spdx.json")).ToNot(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "yarn", "sbom.syft.json")).ToNot(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.cdx.json")).ToNot(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.spdx.json")).ToNot(BeARegularFile())
Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"), "yarn", "sbom.syft.json")).ToNot(BeARegularFile())
})
})
}
62 changes: 40 additions & 22 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,77 @@ import (
. "github.com/onsi/gomega"
)

var (
buildpack string
buildPlanBuildpack string
offlineBuildpack string
root string

buildpackInfo struct {
Buildpack struct {
ID string
Name string
var settings struct {
Buildpacks struct {
BuildPlan struct {
Online string
}
Yarn struct {
Online string
Offline string
}
}
)
Extensions struct {
UbiNodejsExtension struct {
Online string
}
}
Config struct {
BuildPlan string `json:"buildplan"`
UbiNodejsExtension string `json:"ubi-nodejs-extension"`
}
Buildpack struct {
ID string
Name string
}
}

func TestIntegration(t *testing.T) {
var err error

Expect := NewWithT(t).Expect

var config struct {
BuildPlan string `json:"buildplan"`
}

file, err := os.Open("../integration.json")
Expect(err).NotTo(HaveOccurred())
defer file.Close()

Expect(json.NewDecoder(file).Decode(&config)).To(Succeed())
Expect(json.NewDecoder(file).Decode(&settings.Config)).To(Succeed())

file, err = os.Open("../buildpack.toml")
Expect(err).NotTo(HaveOccurred())

_, err = toml.NewDecoder(file).Decode(&buildpackInfo)
_, err = toml.NewDecoder(file).Decode(&settings)
Expect(err).NotTo(HaveOccurred())

root, err = filepath.Abs("./..")
root, err := filepath.Abs("./..")
Expect(err).ToNot(HaveOccurred())

buildpackStore := occam.NewBuildpackStore()

buildpack, err = buildpackStore.Get.
pack := occam.NewPack()

builder, err := pack.Builder.Inspect.Execute()
Expect(err).NotTo(HaveOccurred())

if builder.BuilderName == "index.docker.io/paketocommunity/builder-ubi-buildpackless-base:latest" {
settings.Extensions.UbiNodejsExtension.Online, err = buildpackStore.Get.
Execute(settings.Config.UbiNodejsExtension)
Expect(err).ToNot(HaveOccurred())
}

settings.Buildpacks.Yarn.Online, err = buildpackStore.Get.
WithVersion("1.2.3").
Execute(root)
Expect(err).NotTo(HaveOccurred())

offlineBuildpack, err = buildpackStore.Get.
settings.Buildpacks.Yarn.Offline, err = buildpackStore.Get.
WithOfflineDependencies().
WithVersion("1.2.3").
Execute(root)
Expect(err).NotTo(HaveOccurred())

buildPlanBuildpack, err = buildpackStore.Get.
Execute(config.BuildPlan)
settings.Buildpacks.BuildPlan.Online, err = buildpackStore.Get.
Execute(settings.Config.BuildPlan)
Expect(err).NotTo(HaveOccurred())

SetDefaultEventuallyTimeout(10 * time.Second)
Expand Down
21 changes: 15 additions & 6 deletions integration/layer_reuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) {

name string
source string

pullPolicy = "never"
)

it.Before(func() {
Expand All @@ -36,6 +38,10 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) {
pack = occam.NewPack()
imageIDs = map[string]struct{}{}
containerIDs = map[string]struct{}{}

if settings.Extensions.UbiNodejsExtension.Online != "" {
pullPolicy = "always"
}
})

it.After(func() {
Expand Down Expand Up @@ -64,10 +70,13 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) {
Expect(err).NotTo(HaveOccurred())

build := pack.WithNoColor().Build.
WithPullPolicy("never").
WithExtensions(
settings.Extensions.UbiNodejsExtension.Online,
).
WithPullPolicy(pullPolicy).
WithBuildpacks(
buildpack,
buildPlanBuildpack,
settings.Buildpacks.Yarn.Online,
settings.Buildpacks.BuildPlan.Online,
)

firstImage, logs, err = build.Execute(name, source)
Expand All @@ -77,7 +86,7 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) {

Expect(firstImage.Buildpacks).To(HaveLen(2))

Expect(firstImage.Buildpacks[0].Key).To(Equal(buildpackInfo.Buildpack.ID))
Expect(firstImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID))
Expect(firstImage.Buildpacks[0].Layers).To(HaveKey("yarn"))

Expect(logs.String()).To(ContainSubstring(" Executing build process"))
Expand All @@ -90,11 +99,11 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) {

Expect(secondImage.Buildpacks).To(HaveLen(2))

Expect(secondImage.Buildpacks[0].Key).To(Equal(buildpackInfo.Buildpack.ID))
Expect(secondImage.Buildpacks[0].Key).To(Equal(settings.Buildpack.ID))
Expect(secondImage.Buildpacks[0].Layers).To(HaveKey("yarn"))

Expect(logs.String()).NotTo(ContainSubstring(" Executing build process"))
Expect(logs.String()).To(ContainSubstring(fmt.Sprintf(" Reusing cached layer /layers/%s/yarn", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))))
Expect(logs.String()).To(ContainSubstring(fmt.Sprintf(" Reusing cached layer /layers/%s/yarn", strings.ReplaceAll(settings.Buildpack.ID, "/", "_"))))

Expect(secondImage.Buildpacks[0].Layers["yarn"].SHA).To(Equal(firstImage.Buildpacks[0].Layers["yarn"].SHA))
})
Expand Down
15 changes: 12 additions & 3 deletions integration/offline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func testOffline(t *testing.T, context spec.G, it spec.S) {
})

context("when offline", func() {
//UBI does not support offline installation at the moment,
//so we are skipping it.
if settings.Extensions.UbiNodejsExtension.Online != "" {
return
}

var (
image occam.Image
container occam.Container
Expand Down Expand Up @@ -54,10 +60,13 @@ func testOffline(t *testing.T, context spec.G, it spec.S) {

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithExtensions(
settings.Extensions.UbiNodejsExtension.Online,
).
WithBuildpacks(
offlineBuildpack,
buildPlanBuildpack).
settings.Buildpacks.Yarn.Offline,
settings.Buildpacks.BuildPlan.Online,
).
WithNetwork("none").
Execute(name, source)

Expand Down
1 change: 1 addition & 0 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function tests::run() {
util::print::title "Run Buildpack Runtime Integration Tests"
util::print::info "Using ${1} as builder..."

pack config experimental true
export CGO_ENABLED=0
pushd "${BUILDPACKDIR}" > /dev/null
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${2}"; then
Expand Down
Loading