Skip to content

Commit

Permalink
Fix create-builder with multiple buildpacks of same id
Browse files Browse the repository at this point in the history
- Remove comptability layer (except for lifecycle symlink)
- Introduce COMPILE_PACK_WITH_VERSION env variable for running acceptance tests
- Add pack_previous_fixtures_overrides directory to enable overriding fixtures used
  for previous pack versions

Signed-off-by: Andrew Meyer <ameyer@pivotal.io>
Signed-off-by: Natalie Arellano <narellano@pivotal.io>
  • Loading branch information
ameyer-pivotal authored and natalieparellano committed Jan 16, 2020
1 parent 0e9b6c9 commit 44eedd5
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ unit: format lint

acceptance: format lint
@echo "> Running acceptance tests..."
$(GOCMD) test -v -count=1 -parallel=1 -timeout=0 -tags=acceptance ./acceptance
COMPILE_PACK_WITH_VERSION=$(or ${COMPILE_PACK_WITH_VERSION}, 0.0.0) $(GOCMD) test -v -count=1 -parallel=1 -timeout=0 -tags=acceptance ./acceptance

acceptance-all: format lint
@echo "> Running acceptance tests..."
Expand Down
29 changes: 23 additions & 6 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

const (
envPackPath = "PACK_PATH"
envCompilePackWithVersion = "COMPILE_PACK_WITH_VERSION"
envPreviousPackPath = "PREVIOUS_PACK_PATH"
envPreviousPackFixturesPath = "PREVIOUS_PACK_FIXTURES_PATH"
envLifecyclePath = "LIFECYCLE_PATH"
Expand Down Expand Up @@ -72,7 +73,11 @@ func TestAcceptance(t *testing.T) {

packPath := os.Getenv(envPackPath)
if packPath == "" {
packPath = buildPack(t)
compileVersion := os.Getenv(envCompilePackWithVersion)
if compileVersion == "" {
t.Fatalf("%s must be set if %s is empty", envCompilePackWithVersion, envPackPath)
}
packPath = buildPack(t, compileVersion)
}

previousPackPath := os.Getenv(envPreviousPackPath)
Expand Down Expand Up @@ -137,11 +142,18 @@ func TestAcceptance(t *testing.T) {
h.AssertNil(t, err)
}

tmpPreviousPackFixturesPath, err := ioutil.TempDir("", "previous-pack-fixtures")
h.AssertNil(t, err)
defer os.RemoveAll(tmpPreviousPackFixturesPath)

h.RecursiveCopy(t, previousPackFixturesPath, tmpPreviousPackFixturesPath)
h.RecursiveCopy(t, filepath.Join("testdata", "pack_previous_fixtures_overrides"), tmpPreviousPackFixturesPath)

resolvedCombos, err := resolveRunCombinations(
combos,
packPath,
previousPackPath,
previousPackFixturesPath,
tmpPreviousPackFixturesPath,
lifecyclePath,
lifecycleDescriptor,
previousLifecyclePath,
Expand Down Expand Up @@ -514,7 +526,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S, packFixturesDir, packP
"--buildpack",
"simple/layers@simple-layers-version",
"--buildpack",
"noop.buildpack",
"noop.buildpack@noop.buildpack.version",
"--buildpack",
"read/env@latest",
"--env",
Expand Down Expand Up @@ -1342,7 +1354,7 @@ func buildpacksDir(bpAPIVersion api.Version) string {
return filepath.Join("testdata", "mock_buildpacks", bpAPIVersion.String())
}

func buildPack(t *testing.T) string {
func buildPack(t *testing.T, compileVersion string) string {
packTmpDir, err := ioutil.TempDir("", "pack.acceptance.binary.")
h.AssertNil(t, err)

Expand All @@ -1354,7 +1366,12 @@ func buildPack(t *testing.T) string {
cwd, err := os.Getwd()
h.AssertNil(t, err)

cmd := exec.Command("go", "build", "-mod=vendor", "-o", packPath, "./cmd/pack")
cmd := exec.Command("go", "build",
"-ldflags", fmt.Sprintf("-X 'github.com/buildpacks/pack/cmd.Version=%s'", compileVersion),
"-mod=vendor",
"-o", packPath,
"./cmd/pack",
)
if filepath.Base(cwd) == "acceptance" {
cmd.Dir = filepath.Dir(cwd)
}
Expand Down Expand Up @@ -1383,7 +1400,7 @@ func createBuilder(t *testing.T, runImageMirror, configDir, packPath, lifecycleP
// ARCHIVE BUILDPACKS
buildpacks := []string{
"noop-buildpack",
"not-in-builder-buildpack",
"noop-buildpack-2",
"other-stack-buildpack",
"read-env-buildpack",
"simple-layers-buildpack", // from package
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "---> NOOP (later version) Buildpack"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

## always detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
api = "0.2"

[buildpack]
id = "noop.buildpack"
version = "noop.buildpack.later-version"
name = "NOOP Buildpack"

[[stacks]]
id = "pack.test.stack"
4 changes: 4 additions & 0 deletions acceptance/testdata/pack_fixtures/builder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# intentionally missing id/version as they are optional
uri = "noop-buildpack.tgz"

[[buildpacks]]
# noop-buildpack-2 has the same id but a different version compared to noop-buildpack
uri = "noop-buildpack-2.tgz"

[[packages]]
image = "{{ .package_name }}"

Expand Down
71 changes: 71 additions & 0 deletions acceptance/testdata/pack_fixtures/inspect_0.6.0_builder_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Inspecting builder: '{{.builder_name}}'

REMOTE:

Created By:
Name: Pack CLI
Version: {{.pack_version}}

Stack:
ID: pack.test.stack
Mixins:
mixinA
netcat
mixin3
build:mixinTwo

Lifecycle:
Version: {{.lifecycle_version}}
Buildpack API: {{.buildpack_api_version}}
Platform API: {{.platform_api_version}}

Run Images:
some-registry.com/pack-test/run1 (user-configured)
pack-test/run
{{.run_image_mirror}}

Buildpacks:
ID VERSION
read/env read-env-version
noop.buildpack noop.buildpack.version
simple/layers simple-layers-version

Detection Order:
Group #1:
simple/layers
read/env@read-env-version (optional)

LOCAL:

Created By:
Name: Pack CLI
Version: {{.pack_version}}

Stack:
ID: pack.test.stack
Mixins:
mixinA
netcat
mixin3
build:mixinTwo

Lifecycle:
Version: {{.lifecycle_version}}
Buildpack API: {{.buildpack_api_version}}
Platform API: {{.platform_api_version}}

Run Images:
some-registry.com/pack-test/run1 (user-configured)
pack-test/run
{{.run_image_mirror}}

Buildpacks:
ID VERSION
read/env read-env-version
noop.buildpack noop.buildpack.version
simple/layers simple-layers-version

Detection Order:
Group #1:
simple/layers
read/env@read-env-version (optional)
2 changes: 2 additions & 0 deletions acceptance/testdata/pack_fixtures/inspect_builder_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Buildpacks:
ID VERSION
read/env read-env-version
noop.buildpack noop.buildpack.version
noop.buildpack noop.buildpack.later-version
simple/layers simple-layers-version

Detection Order:
Expand Down Expand Up @@ -63,6 +64,7 @@ Buildpacks:
ID VERSION
read/env read-env-version
noop.buildpack noop.buildpack.version
noop.buildpack noop.buildpack.later-version
simple/layers simple-layers-version

Detection Order:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Inspecting builder: '{{.builder_name}}'

REMOTE:

Created By:
Name: Pack CLI
Version: {{.pack_version}}

Stack:
ID: pack.test.stack
Mixins:
mixinA
netcat
mixin3
build:mixinTwo

Lifecycle:
Version: {{.lifecycle_version}}
Buildpack API: {{.buildpack_api_version}}
Platform API: {{.platform_api_version}}

Run Images:
some-registry.com/pack-test/run1 (user-configured)
pack-test/run
{{.run_image_mirror}}

Buildpacks:
ID VERSION
read/env read-env-version
noop.buildpack noop.buildpack.version
noop.buildpack noop.buildpack.later-version
simple/layers simple-layers-version

Detection Order:
Group #1:
simple/layers
read/env@read-env-version (optional)

LOCAL:

Created By:
Name: Pack CLI
Version: {{.pack_version}}

Stack:
ID: pack.test.stack
Mixins:
mixinA
netcat
mixin3
build:mixinTwo

Lifecycle:
Version: {{.lifecycle_version}}
Buildpack API: {{.buildpack_api_version}}
Platform API: {{.platform_api_version}}

Run Images:
some-registry.com/pack-test/run1 (user-configured)
pack-test/run
{{.run_image_mirror}}

Buildpacks:
ID VERSION
read/env read-env-version
noop.buildpack noop.buildpack.version
noop.buildpack noop.buildpack.later-version
simple/layers simple-layers-version

Detection Order:
Group #1:
simple/layers
read/env@read-env-version (optional)
2 changes: 1 addition & 1 deletion internal/build/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (l *Lifecycle) NewPhase(name string, ops ...func(*Phase) (*Phase, error)) (
fmt.Sprintf("%s:%s", l.AppVolume, appDir),
},
}
ctrConf.Cmd = []string{"/lifecycle/" + name}
ctrConf.Cmd = []string{"/cnb/lifecycle/" + name}
phase := &Phase{
ctrConf: ctrConf,
hostConf: hostConf,
Expand Down
5 changes: 1 addition & 4 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ func constructBuilder(img imgutil.Image, newName string, metadata Metadata) (*Bu
}

var order dist.Order
if ok, err := dist.GetLabel(img, OrderLabel, &order); err != nil {
if _, err := dist.GetLabel(img, OrderLabel, &order); err != nil {
return nil, err
} else if !ok {
order = metadata.Groups.ToOrder()
}

return &Builder{
Expand Down Expand Up @@ -229,7 +227,6 @@ func (b *Builder) Save(logger logging.Logger) error {
return errors.Wrap(err, "processing order")
}

b.metadata.Groups = orderToV1Order(resolvedOrder)
processMetadata(&b.metadata)

tmpDir, err := ioutil.TempDir("", "create-builder-scratch")
Expand Down
Loading

0 comments on commit 44eedd5

Please sign in to comment.