Skip to content

Commit

Permalink
Merge pull request #900 from buildpacks/feature/windows-package-build…
Browse files Browse the repository at this point in the history
…pack-172289412

Polish #840
  • Loading branch information
jromero authored Oct 20, 2020
2 parents 31b6359 + 9d84840 commit 52eb22c
Show file tree
Hide file tree
Showing 23 changed files with 815 additions and 464 deletions.
195 changes: 89 additions & 106 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func testWithoutSpecificBuilderRequirement(

it.Before(func() {
pack = invoke.NewPackInvoker(t, assert, packConfig, registryConfig.DockerConfigDir)
pack.EnableExperimental()
buildpackManager = buildpacks.NewBuildpackManager(t, assert)
})

Expand Down Expand Up @@ -242,8 +243,6 @@ func testWithoutSpecificBuilderRequirement(
"pack does not support 'package-buildpack'",
)

h.SkipIf(t, dockerHostOS() == "windows", "These tests are not yet compatible with Windows-based containers")

var err error
tmpDir, err = ioutil.TempDir("", "package-buildpack-tests")
assert.Nil(err)
Expand Down Expand Up @@ -329,15 +328,18 @@ func testWithoutSpecificBuilderRequirement(

when("--publish", func() {
it("publishes image to registry", func() {
h.SkipIf(t, !pack.Supports("package-buildpack --os"), "os not supported")

nestedPackageName := registryConfig.RepoName("test/package-" + h.RandString(10))

nestedPackage := buildpacks.NewPackageImage(
t,
pack,
nestedPackageName,
simplePackageConfigPath,
buildpacks.WithPublish(),
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers),
buildpacks.WithPublish(),
buildpacks.WithOS(dockerHostOS()),
)
buildpackManager.PrepareBuildpacks(tmpDir, nestedPackage)
defer h.DockerRmi(dockerCli, nestedPackageName)
Expand All @@ -348,6 +350,7 @@ func testWithoutSpecificBuilderRequirement(
"package-buildpack", packageName,
"-c", aggregatePackageToml,
"--publish",
"--os", dockerHostOS(),
)
defer h.DockerRmi(dockerCli, packageName)
assertions.NewOutputAssertionManager(t, output).ReportsPackagePublished(packageName)
Expand Down Expand Up @@ -537,8 +540,11 @@ func testWithoutSpecificBuilderRequirement(
pack,
packageFileLocation,
pack.FixtureManager().FixtureLocation("package_for_build_cmd.toml"),
buildpacks.FolderSimpleLayersParent,
buildpacks.FolderSimpleLayers,
buildpacks.WithRequiredBuildpacks(
buildpacks.FolderSimpleLayersParent,
buildpacks.FolderSimpleLayers,
),
buildpacks.WithOS(dockerHostOS()),
)

buildpackManager.PrepareBuildpacks(tmpDir, packageFile)
Expand All @@ -559,10 +565,6 @@ func testWithoutSpecificBuilderRequirement(
})

when("buildpack image", func() {
it.Before(func() {
h.SkipIf(t, dockerHostOS() == "windows", "These tests are not yet compatible with Windows-based containers")
})

when("inspect-buildpack", func() {
it("succeeds", func() {
packageImageName := registryConfig.RepoName("buildpack-" + h.RandString(8))
Expand Down Expand Up @@ -1244,12 +1246,8 @@ func testAcceptance(

it.Before(func() {
h.SkipUnless(t,
pack.Supports("package-buildpack"),
"--buildpack does not accept buildpackage unless package-buildpack is supported",
)
h.SkipIf(t,
dockerHostOS() == "windows",
"These tests are not yet compatible with Windows-based containers",
pack.Supports("package-buildpack --os"),
"--buildpack does not accept buildpackage unless package-buildpack --os is supported",
)
})

Expand Down Expand Up @@ -1297,11 +1295,10 @@ func testAcceptance(
var tmpDir string

it.Before(func() {
h.SkipIf(t,
!pack.Supports("package-buildpack --format"),
"--buildpack does not accept buildpackage file unless package-buildpack with --format is supported",
h.SkipUnless(t,
pack.Supports("package-buildpack --os"),
"--buildpack does not accept buildpackage unless package-buildpack --os is supported",
)
h.SkipIf(t, dockerHostOS() == "windows", "These tests are not yet compatible with Windows-based containers")

var err error
tmpDir, err = ioutil.TempDir("", "package-file")
Expand All @@ -1323,8 +1320,11 @@ func testAcceptance(
pack,
packageFileLocation,
pack.FixtureManager().FixtureLocation("package_for_build_cmd.toml"),
buildpacks.FolderSimpleLayersParent,
buildpacks.FolderSimpleLayers,
buildpacks.WithRequiredBuildpacks(
buildpacks.FolderSimpleLayersParent,
buildpacks.FolderSimpleLayers,
),
buildpacks.WithOS(dockerHostOS()),
)

buildpackManager.PrepareBuildpacks(tmpDir, packageFile)
Expand Down Expand Up @@ -2119,70 +2119,68 @@ func createComplexBuilder(t *testing.T,
"run_image_mirror": runImageMirror,
}

if dockerHostOS() != "windows" {
packageImageName := registryConfig.RepoName("nested-level-1-buildpack-" + h.RandString(8))
nestedLevelTwoBuildpackName := registryConfig.RepoName("nested-level-2-buildpack-" + h.RandString(8))
simpleLayersBuildpackName := registryConfig.RepoName("simple-layers-buildpack-" + h.RandString(8))

templateMapping["package_id"] = "simple/nested-level-1"
templateMapping["package_image_name"] = packageImageName
templateMapping["nested_level_1_buildpack"] = packageImageName
templateMapping["nested_level_2_buildpack"] = nestedLevelTwoBuildpackName
templateMapping["simple_layers_buildpack"] = simpleLayersBuildpackName

fixtureManager := pack.FixtureManager()

nestedLevelOneConfigFile, err := ioutil.TempFile(tmpDir, "nested-level-1-package.toml")
assert.Nil(err)
fixtureManager.TemplateFixtureToFile(
"nested-level-1-buildpack_package.toml",
nestedLevelOneConfigFile,
templateMapping,
)
err = nestedLevelOneConfigFile.Close()
assert.Nil(err)

nestedLevelTwoConfigFile, err := ioutil.TempFile(tmpDir, "nested-level-2-package.toml")
assert.Nil(err)
fixtureManager.TemplateFixtureToFile(
"nested-level-2-buildpack_package.toml",
nestedLevelTwoConfigFile,
templateMapping,
)
err = nestedLevelTwoConfigFile.Close()
assert.Nil(err)
packageImageName := registryConfig.RepoName("nested-level-1-buildpack-" + h.RandString(8))
nestedLevelTwoBuildpackName := registryConfig.RepoName("nested-level-2-buildpack-" + h.RandString(8))
simpleLayersBuildpackName := registryConfig.RepoName("simple-layers-buildpack-" + h.RandString(8))

packageImageBuildpack := buildpacks.NewPackageImage(
t,
pack,
packageImageName,
nestedLevelOneConfigFile.Name(),
buildpacks.WithRequiredBuildpacks(
buildpacks.NestedLevelOne,
buildpacks.NewPackageImage(
t,
pack,
nestedLevelTwoBuildpackName,
nestedLevelTwoConfigFile.Name(),
buildpacks.WithRequiredBuildpacks(
buildpacks.NestedLevelTwo,
buildpacks.NewPackageImage(
t,
pack,
simpleLayersBuildpackName,
fixtureManager.FixtureLocation("simple-layers-buildpack_package.toml"),
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers),
),
templateMapping["package_id"] = "simple/nested-level-1"
templateMapping["package_image_name"] = packageImageName
templateMapping["nested_level_1_buildpack"] = packageImageName
templateMapping["nested_level_2_buildpack"] = nestedLevelTwoBuildpackName
templateMapping["simple_layers_buildpack"] = simpleLayersBuildpackName

fixtureManager := pack.FixtureManager()

nestedLevelOneConfigFile, err := ioutil.TempFile(tmpDir, "nested-level-1-package.toml")
assert.Nil(err)
fixtureManager.TemplateFixtureToFile(
"nested-level-1-buildpack_package.toml",
nestedLevelOneConfigFile,
templateMapping,
)
err = nestedLevelOneConfigFile.Close()
assert.Nil(err)

nestedLevelTwoConfigFile, err := ioutil.TempFile(tmpDir, "nested-level-2-package.toml")
assert.Nil(err)
fixtureManager.TemplateFixtureToFile(
"nested-level-2-buildpack_package.toml",
nestedLevelTwoConfigFile,
templateMapping,
)
err = nestedLevelTwoConfigFile.Close()
assert.Nil(err)

packageImageBuildpack := buildpacks.NewPackageImage(
t,
pack,
packageImageName,
nestedLevelOneConfigFile.Name(),
buildpacks.WithRequiredBuildpacks(
buildpacks.NestedLevelOne,
buildpacks.NewPackageImage(
t,
pack,
nestedLevelTwoBuildpackName,
nestedLevelTwoConfigFile.Name(),
buildpacks.WithRequiredBuildpacks(
buildpacks.NestedLevelTwo,
buildpacks.NewPackageImage(
t,
pack,
simpleLayersBuildpackName,
fixtureManager.FixtureLocation("simple-layers-buildpack_package.toml"),
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers),
),
),
),
)
),
)

builderBuildpacks = append(
builderBuildpacks,
packageImageBuildpack,
)
}
builderBuildpacks = append(
builderBuildpacks,
packageImageBuildpack,
)

buildpackManager.PrepareBuildpacks(tmpDir, builderBuildpacks...)

Expand Down Expand Up @@ -2253,30 +2251,20 @@ func createBuilder(
buildpacks.ReadEnv,
}

// NOTE: Windows-based packages are not yet supported, so we'll add this buildpack in the usual way for now.
// Remove this block once Windows-based packages are supported.
if dockerHostOS() == "windows" {
builderBuildpacks = append(builderBuildpacks, buildpacks.SimpleLayers)
}

// NOTE: Windows-based packages are not yet supported, so we'll add this buildpack in the usual way for now (see above).
// Remove this guard once Windows-based packages are supported.
if dockerHostOS() != "windows" {
packageImageName := registryConfig.RepoName("simple-layers-package-image-buildpack-" + h.RandString(8))
packageImageName := registryConfig.RepoName("simple-layers-package-image-buildpack-" + h.RandString(8))

packageImageBuildpack := buildpacks.NewPackageImage(
t,
pack,
packageImageName,
pack.FixtureManager().FixtureLocation("package.toml"),
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers),
)
packageImageBuildpack := buildpacks.NewPackageImage(
t,
pack,
packageImageName,
pack.FixtureManager().FixtureLocation("package.toml"),
buildpacks.WithRequiredBuildpacks(buildpacks.SimpleLayers),
)

builderBuildpacks = append(builderBuildpacks, packageImageBuildpack)
builderBuildpacks = append(builderBuildpacks, packageImageBuildpack)

templateMapping["package_image_name"] = packageImageName
templateMapping["package_id"] = "simple/layers"
}
templateMapping["package_image_name"] = packageImageName
templateMapping["package_id"] = "simple/layers"

buildpackManager.PrepareBuildpacks(tmpDir, builderBuildpacks...)

Expand All @@ -2296,11 +2284,6 @@ func createBuilder(
// RENDER builder.toml
configFileName := "builder.toml"

// NOTE: Remove when Windows-based packages are supported (can use same toml at that point)
if dockerHostOS() == "windows" {
configFileName = "builder-windows.toml"
}

builderConfigFile, err := ioutil.TempFile(tmpDir, "builder.toml")
assert.Nil(err)

Expand Down
25 changes: 25 additions & 0 deletions acceptance/buildpacks/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@ func (b BuildpackManager) PrepareBuildpacks(destination string, buildpacks ...Te
b.assert.Nil(err)
}
}

type Modifiable interface {
SetOS(string)
SetPublish()
SetBuildpacks([]TestBuildpack)
}
type PackageModifier func(p Modifiable)

func WithRequiredBuildpacks(buildpacks ...TestBuildpack) PackageModifier {
return func(p Modifiable) {
p.SetBuildpacks(buildpacks)
}
}

func WithPublish() PackageModifier {
return func(p Modifiable) {
p.SetPublish()
}
}

func WithOS(osVal string) PackageModifier {
return func(p Modifiable) {
p.SetOS(osVal)
}
}
32 changes: 26 additions & 6 deletions acceptance/buildpacks/package_file_buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,37 @@ type PackageFile struct {
destination string
sourceConfigLocation string
buildpacks []TestBuildpack
os string
}

func (p *PackageFile) SetOS(os string) {
p.os = os
}

func (p *PackageFile) SetBuildpacks(buildpacks []TestBuildpack) {
p.buildpacks = buildpacks
}

func (p *PackageFile) SetPublish() {}

func NewPackageFile(
t *testing.T,
pack *invoke.PackInvoker,
destination, configLocation string,
buildpacks ...TestBuildpack,
modifiers ...PackageModifier,
) PackageFile {

return PackageFile{
p := PackageFile{
testObject: t,
pack: pack,
destination: destination,
sourceConfigLocation: configLocation,
buildpacks: buildpacks,
}
for _, mod := range modifiers {
mod(&p)
}

return p
}

func (p PackageFile) Prepare(sourceDir, _ string) error {
Expand All @@ -59,13 +74,18 @@ func (p PackageFile) Prepare(sourceDir, _ string) error {
configLocation := filepath.Join(tmpDir, "package.toml")
h.CopyFile(p.testObject, p.sourceConfigLocation, configLocation)

output := p.pack.RunSuccessfully(
"package-buildpack",
packArgs := []string{
p.destination,
"--no-color",
"-c", configLocation,
"--format", "file",
)
}

if p.os != "" {
packArgs = append(packArgs, "--os", p.os)
}

output := p.pack.RunSuccessfully("package-buildpack", packArgs...)

if !strings.Contains(output, fmt.Sprintf("Successfully created package '%s'", p.destination)) {
return errors.New("failed to create package")
Expand Down
Loading

0 comments on commit 52eb22c

Please sign in to comment.