-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Install main dependency group only by default #182
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| package integration_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/paketo-buildpacks/occam" | ||
| "github.com/sclevine/spec" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| . "github.com/paketo-buildpacks/occam/matchers" | ||
| ) | ||
|
|
||
| func testWithDependencyGroup(t *testing.T, context spec.G, it spec.S) { | ||
| var ( | ||
| Expect = NewWithT(t).Expect | ||
| Eventually = NewWithT(t).Eventually | ||
|
|
||
| pack occam.Pack | ||
| docker occam.Docker | ||
| ) | ||
|
|
||
| it.Before(func() { | ||
| pack = occam.NewPack() | ||
| docker = occam.NewDocker() | ||
| }) | ||
|
|
||
| context("when the buildpack is run with pack build", func() { | ||
| var ( | ||
| image occam.Image | ||
| container occam.Container | ||
| name string | ||
| source string | ||
| ) | ||
|
|
||
| it.Before(func() { | ||
| var err error | ||
| name, err = occam.RandomName() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| source, err = occam.Source(filepath.Join("testdata", "app_with_dependency_group")) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
|
|
||
| it.After(func() { | ||
| Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed()) | ||
| Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed()) | ||
| Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed()) | ||
| Expect(os.RemoveAll(source)).To(Succeed()) | ||
| }) | ||
|
|
||
| it("builds and runs successfully with dev dependency group", func() { | ||
| var err error | ||
| var logs fmt.Stringer | ||
|
|
||
| image, logs, err = pack.WithNoColor().Build. | ||
| WithPullPolicy("never"). | ||
| WithBuildpacks( | ||
| settings.Buildpacks.CPython.Online, | ||
| settings.Buildpacks.Pip.Online, | ||
| settings.Buildpacks.Poetry.Online, | ||
| settings.Buildpacks.PoetryInstall.Online, | ||
| settings.Buildpacks.BuildPlan.Online, | ||
| ). | ||
| WithEnv(map[string]string{"BP_POETRY_INSTALL_WITH": "dev"}). | ||
| Execute(name, source) | ||
| Expect(err).ToNot(HaveOccurred(), logs.String) | ||
|
|
||
| Expect(logs).To(ContainLines( | ||
| MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, buildpackInfo.Buildpack.Name)), | ||
| " Executing build process", | ||
| MatchRegexp(fmt.Sprintf( | ||
| " Running 'POETRY_CACHE_DIR=/layers/%s/cache POETRY_VIRTUALENVS_PATH=/layers/%s/poetry-venv poetry install --with dev'", | ||
| strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), | ||
| strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), | ||
| )), | ||
| )) | ||
|
|
||
| aDependencyFromMainGroup := "Installing flask" | ||
| aDependencyFromDevGroup := "Installing pytest" | ||
| Expect(logs).To(ContainSubstring(aDependencyFromMainGroup)) | ||
| Expect(logs).To(ContainSubstring(aDependencyFromDevGroup)) | ||
|
|
||
| Expect(logs).To(ContainLines(MatchRegexp(` Completed in \d+\.\d+`))) | ||
| Expect(logs).To(ContainLines( | ||
| " Configuring build environment", | ||
| MatchRegexp(fmt.Sprintf(` PATH -> "/layers/%s/poetry-venv/default-app-.*-py\d+\.\d+/bin:\$PATH"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))), | ||
| MatchRegexp(fmt.Sprintf(` POETRY_VIRTUALENVS_PATH -> "/layers/%s/poetry-venv"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))), | ||
| MatchRegexp(fmt.Sprintf(` PYTHONPATH -> "/layers/%s/poetry-venv/default-app-.*-py\d+\.\d+/lib/python\d+\.\d+/site-packages:\$PYTHONPATH"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))), | ||
| "", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove the We've found that asserting on empty log lines is brittle, because sometimes extra lines get inserted due to environment issues (deprecation warnings, etc). A second invocation of |
||
| " Configuring launch environment", | ||
| MatchRegexp(fmt.Sprintf(` PATH -> "/layers/%s/poetry-venv/default-app-.*-py\d+\.\d+/bin:\$PATH"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))), | ||
| MatchRegexp(fmt.Sprintf(` POETRY_VIRTUALENVS_PATH -> "/layers/%s/poetry-venv"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))), | ||
| MatchRegexp(fmt.Sprintf(` PYTHONPATH -> "/layers/%s/poetry-venv/default-app-.*-py\d+\.\d+/lib/python\d+\.\d+/site-packages:\$PYTHONPATH"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))), | ||
| )) | ||
|
|
||
| container, err = docker.Container.Run. | ||
| WithCommand("gunicorn server:app"). | ||
| WithEnv(map[string]string{"PORT": "8080"}). | ||
| WithPublish("8080"). | ||
| Execute(image.ID) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| Eventually(container).Should(BeAvailable()) | ||
| Eventually(container).Should(Serve(ContainSubstring("Hello, World!")).OnPort(8080)) | ||
| }) | ||
|
|
||
| context("validating SBOM", func() { | ||
| var ( | ||
| sbomDir string | ||
| ) | ||
|
|
||
| it.Before(func() { | ||
| var err error | ||
| sbomDir, err = os.MkdirTemp("", "sbom") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(os.Chmod(sbomDir, os.ModePerm)).To(Succeed()) | ||
| }) | ||
|
|
||
| it.After(func() { | ||
| Expect(os.RemoveAll(sbomDir)).To(Succeed()) | ||
| }) | ||
|
|
||
| it("writes SBOM files to the layer and label metadata", func() { | ||
| var err error | ||
| var logs fmt.Stringer | ||
| image, logs, err = pack.WithNoColor().Build. | ||
| WithPullPolicy("never"). | ||
| WithBuildpacks( | ||
| settings.Buildpacks.CPython.Online, | ||
| settings.Buildpacks.Pip.Online, | ||
| settings.Buildpacks.Poetry.Online, | ||
| settings.Buildpacks.PoetryInstall.Online, | ||
| settings.Buildpacks.BuildPlan.Online, | ||
| ). | ||
| WithEnv(map[string]string{ | ||
| "BP_LOG_LEVEL": "DEBUG", | ||
| }). | ||
| WithSBOMOutputDir(sbomDir). | ||
| Execute(name, source) | ||
| Expect(err).ToNot(HaveOccurred(), logs.String) | ||
|
|
||
| container, err = docker.Container.Run. | ||
| WithCommand("gunicorn server:app"). | ||
| WithEnv(map[string]string{"PORT": "8080"}). | ||
| WithPublish("8080"). | ||
| Execute(image.ID) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| Eventually(container).Should(BeAvailable()) | ||
| Eventually(container).Should(Serve(ContainSubstring("Hello, World!")).OnPort(8080)) | ||
|
|
||
| Expect(logs).To(ContainLines( | ||
| fmt.Sprintf(" Generating SBOM for /layers/%s/poetry-venv", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")), | ||
| MatchRegexp(` Completed in \d+(\.?\d+)*`), | ||
| )) | ||
| Expect(logs).To(ContainLines( | ||
| " Writing SBOM in the following format(s):", | ||
| " application/vnd.cyclonedx+json", | ||
| " application/spdx+json", | ||
| " application/vnd.syft+json", | ||
| )) | ||
|
|
||
| // check that all required SBOM files are present | ||
| Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "poetry-venv", "sbom.cdx.json")).To(BeARegularFile()) | ||
| Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "poetry-venv", "sbom.spdx.json")).To(BeARegularFile()) | ||
| Expect(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "poetry-venv", "sbom.syft.json")).To(BeARegularFile()) | ||
|
|
||
| // check an SBOM file to make sure it has an entry for a poetry dependency | ||
| contents, err := os.ReadFile(filepath.Join(sbomDir, "sbom", "launch", strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"), "poetry-venv", "sbom.cdx.json")) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(string(contents)).To(ContainSubstring(`"name": "flask"`)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this test, could you also add the environment variable: Similarly, could you add an assertion to the |
||
| }) | ||
| }) | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ func TestIntegration(t *testing.T) { | |
| SetDefaultEventuallyTimeout(30 * time.Second) | ||
|
|
||
| suite := spec.New("Integration", spec.Report(report.Terminal{})) | ||
| suite("Default", testDefault, spec.Parallel()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we removed the |
||
| suite("Default", testDefault) | ||
| suite("WithDependencyGroup", testWithDependencyGroup) | ||
| suite.Run(t) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [[requires]] | ||
| name = "poetry-venv" | ||
|
|
||
| [requires.metadata] | ||
| launch = true | ||
|
|
||
| [[requires]] | ||
| name = "cpython" | ||
|
|
||
| [requires.metadata] | ||
| launch = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this
strings.ReplaceAlltwice - the second invocation should be redundant.