diff --git a/integration.json b/integration.json index b15d620..48065c2 100644 --- a/integration.json +++ b/integration.json @@ -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" } diff --git a/integration/default_test.go b/integration/default_test.go index 21c5d1d..e79277a 100644 --- a/integration/default_test.go +++ b/integration/default_test.go @@ -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() { @@ -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, + ). 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) Expect(err).NotTo(HaveOccurred()) Eventually(func() string { @@ -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):", @@ -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"`)) @@ -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( + 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", @@ -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 { @@ -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]+)+`), @@ -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()) }) }) } diff --git a/integration/init_test.go b/integration/init_test.go index 75d30af..61f6eac 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -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) diff --git a/integration/layer_reuse_test.go b/integration/layer_reuse_test.go index 3925faf..c7b2863 100644 --- a/integration/layer_reuse_test.go +++ b/integration/layer_reuse_test.go @@ -25,6 +25,8 @@ func testRebuildLayerReuse(t *testing.T, context spec.G, it spec.S) { name string source string + + pullPolicy = "never" ) it.Before(func() { @@ -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() { @@ -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) @@ -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")) @@ -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)) }) diff --git a/integration/offline_test.go b/integration/offline_test.go index cc511cc..4300b94 100644 --- a/integration/offline_test.go +++ b/integration/offline_test.go @@ -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 @@ -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) diff --git a/scripts/integration.sh b/scripts/integration.sh index 13a5635..07f6f0e 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -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