Skip to content

Commit

Permalink
Implementing logic split flattened modules into different tar files, and
Browse files Browse the repository at this point in the history
calculate which buildpacks must be added into the ephemeral builder

Skipping pack build -b <flattened-buildpack> in windows container
because acceptance tests doesn't support it yet

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed Jun 15, 2023
1 parent 362052a commit 03808b7
Show file tree
Hide file tree
Showing 9 changed files with 691 additions and 214 deletions.
167 changes: 82 additions & 85 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,88 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ]
})
})
})

when("build --buildpack <flattened buildpack>", func() {
var (
tmpDir string
flattenedPackageName string
simplePackageConfigFixtureName = "package.toml"
)

generateAggregatePackageToml := func(buildpackURI, nestedPackageName, operatingSystem string) string {
t.Helper()
packageTomlFile, err := os.CreateTemp(tmpDir, "package_aggregate-*.toml")
assert.Nil(err)

pack.FixtureManager().TemplateFixtureToFile(
"package_aggregate.toml",
packageTomlFile,
map[string]interface{}{
"BuildpackURI": buildpackURI,
"PackageName": nestedPackageName,
"OS": operatingSystem,
},
)

assert.Nil(packageTomlFile.Close())
return packageTomlFile.Name()
}

it.Before(func() {
var err error
tmpDir, err = os.MkdirTemp("", "buildpack-package-flattened-tests")
assert.Nil(err)

buildpackManager = buildpacks.NewBuildModuleManager(t, assert)
buildpackManager.PrepareBuildModules(tmpDir, buildpacks.BpSimpleLayersParent, buildpacks.BpSimpleLayers)

// set up a flattened buildpack
packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, imageManager.HostOS())
nestedPackageName := "test/flattened-package-" + h.RandString(10)
nestedPackage := buildpacks.NewPackageImage(
t,
pack,
nestedPackageName,
packageTomlPath,
buildpacks.WithRequiredBuildpacks(buildpacks.BpSimpleLayers),
)
buildpackManager.PrepareBuildModules(tmpDir, nestedPackage)
assertImage.ExistsLocally(nestedPackageName)

aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName, imageManager.HostOS())
flattenedPackageName = "test/package-" + h.RandString(10)

_ = pack.RunSuccessfully(
"buildpack", "package", flattenedPackageName,
"-c", aggregatePackageToml,
"--flatten",
)

assertImage.ExistsLocally(flattenedPackageName)
assertImage.HasLengthLayers(flattenedPackageName, 1)
})

it.After(func() {
assert.Nil(os.RemoveAll(tmpDir))
imageManager.CleanupImages(flattenedPackageName)
})

when("--flatten", func() {
it("creates the package as a single layer and then use it to run pack build -b", func() {
h.SkipIf(t, !pack.SupportsFeature(invoke.BuildpackFlatten), "")
h.SkipIf(t, imageManager.HostOS() == "windows", "These tests are not yet compatible with Windows-based containers")

output := pack.RunSuccessfully(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--buildpack", fmt.Sprintf("docker://%s", flattenedPackageName),
"--builder", builderName,
)

h.AssertContainsMatch(t, output, "Buildpack '(simple/layers@simple-layers-version|simple/layers/parent@simple-layers-parent-version)' is a component of a flattened buildpack that will be added elsewhere, skipping...")
})
})
})
})

when("inspecting builder", func() {
Expand Down Expand Up @@ -2736,91 +2818,6 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ]
})
})
})

when("pack build --buildpack <flattened buildpack>", func() {
when("package", func() {
var (
tmpDir string
buildpackManager buildpacks.BuildModuleManager
simplePackageConfigFixtureName = "package.toml"
)

it.Before(func() {
var err error
tmpDir, err = os.MkdirTemp("", "buildpack-package-tests")
assert.Nil(err)

buildpackManager = buildpacks.NewBuildModuleManager(t, assert)
buildpackManager.PrepareBuildModules(tmpDir, buildpacks.BpSimpleLayersParent, buildpacks.BpSimpleLayers)
})

it.After(func() {
assert.Nil(os.RemoveAll(tmpDir))
})

generateAggregatePackageToml := func(buildpackURI, nestedPackageName, operatingSystem string) string {
t.Helper()
packageTomlFile, err := os.CreateTemp(tmpDir, "package_aggregate-*.toml")
assert.Nil(err)

pack.FixtureManager().TemplateFixtureToFile(
"package_aggregate.toml",
packageTomlFile,
map[string]interface{}{
"BuildpackURI": buildpackURI,
"PackageName": nestedPackageName,
"OS": operatingSystem,
},
)

assert.Nil(packageTomlFile.Close())

return packageTomlFile.Name()
}

when.Focus("--flatten", func() {
it("creates the package as a single layer", func() {
//h.SkipIf(t, !pack.SupportsFeature(invoke.BuildpackFlatten), "")

packageTomlPath := generatePackageTomlWithOS(t, assert, pack, tmpDir, simplePackageConfigFixtureName, imageManager.HostOS())
nestedPackageName := "test/package-" + h.RandString(10)

nestedPackage := buildpacks.NewPackageImage(
t,
pack,
nestedPackageName,
packageTomlPath,
buildpacks.WithRequiredBuildpacks(buildpacks.BpSimpleLayers),
)
buildpackManager.PrepareBuildModules(tmpDir, nestedPackage)
assertImage.ExistsLocally(nestedPackageName)

aggregatePackageToml := generateAggregatePackageToml("simple-layers-parent-buildpack.tgz", nestedPackageName, imageManager.HostOS())
packageName := "test/package-" + h.RandString(10)

_ = pack.RunSuccessfully(
"buildpack", "package", packageName,
"-c", aggregatePackageToml,
"--flatten",
)
defer imageManager.CleanupImages(packageName)

assertImage.ExistsLocally(packageName)
assertImage.HasLengthLayers(packageName, 1)

repoName := "some-org/" + h.RandString(10) // TODO: cleanup
output := pack.RunSuccessfully(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--buildpack", fmt.Sprintf("docker://%s", packageName),
"--builder", builderName,
)

h.AssertContains(t, output, "Buildpack 'simple/layers@simple-layers-version' is a component of a flattened buildpack that will be added elsewhere, skipping...")
})
})
})
})
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion acceptance/invoke/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
return !i.atLeast("v0.30.0")
},
BuildpackFlatten: func(i *PackInvoker) bool {
return !i.atLeast("v0.30.0")
return i.atLeast("v0.30.0")
},
}

Expand Down
Loading

0 comments on commit 03808b7

Please sign in to comment.