Skip to content

Commit

Permalink
Merge pull request #459 from buildpacks/fix/430-dedup-buildpacks
Browse files Browse the repository at this point in the history
Fix create-builder with multiple buildpacks of same id
  • Loading branch information
jromero authored Jan 18, 2020
2 parents 75dbbc6 + 0708021 commit 589d997
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 540 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
30 changes: 24 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 All @@ -84,11 +89,19 @@ func TestAcceptance(t *testing.T) {
}

previousPackFixturesPath := os.Getenv(envPreviousPackFixturesPath)
var tmpPreviousPackFixturesPath string
if previousPackFixturesPath != "" {
previousPackFixturesPath, err = filepath.Abs(previousPackFixturesPath)
if err != nil {
t.Fatal(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)
}

lifecycleDescriptor := builder.LifecycleDescriptor{
Expand Down Expand Up @@ -141,7 +154,7 @@ func TestAcceptance(t *testing.T) {
combos,
packPath,
previousPackPath,
previousPackFixturesPath,
tmpPreviousPackFixturesPath,
lifecyclePath,
lifecycleDescriptor,
previousLifecyclePath,
Expand Down Expand Up @@ -514,7 +527,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 +1355,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 +1367,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 +1401,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
2 changes: 1 addition & 1 deletion internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
phase, err := subject.NewPhase("phase", build.WithArgs("some", "args"))
h.AssertNil(t, err)
assertRunSucceeds(t, phase, &outBuf, &errBuf)
h.AssertContains(t, outBuf.String(), `received args [/lifecycle/phase some args]`)
h.AssertContains(t, outBuf.String(), `received args [/cnb/lifecycle/phase some args]`)
})
})

Expand Down
11 changes: 2 additions & 9 deletions internal/build/testdata/fake-lifecycle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ FROM golang
RUN mkdir /lifecycle
WORKDIR /go/src/step
COPY . .
RUN GO111MODULE=on go build -mod=vendor -o /lifecycle/phase ./phase.go

RUN mkdir -p /buildpacks
RUN echo '[[groups]]\n\
[[groups.buildpacks]]\n\
id = orig.buildpack.id\n\
version = orig.buildpack.version\n'\
> /buildpacks/order.toml
RUN GO111MODULE=on go build -mod=vendor -o /cnb/lifecycle/phase ./phase.go

ENV CNB_USER_ID 111
ENV CNB_GROUP_ID 222

LABEL io.buildpacks.stack.id="test.stack"
LABEL io.buildpacks.builder.metadata="{\"buildpacks\":[{\"id\":\"just/buildpack.id\",\"version\":\"1.2.3\"}],\"groups\":[{\"buildpacks\":[{\"id\":\"orig.buildpack.id\",\"version\":\"orig.buildpack.version\"}]}],\"lifecycle\":{\"version\":\"0.5.0\",\"api\":{\"buildpack\":\"0.2\",\"platform\":\"0.1\"}}}"
LABEL io.buildpacks.builder.metadata="{\"buildpacks\":[{\"id\":\"just/buildpack.id\",\"version\":\"1.2.3\"}],\"lifecycle\":{\"version\":\"0.5.0\",\"api\":{\"buildpack\":\"0.2\",\"platform\":\"0.1\"}}}"
Loading

0 comments on commit 589d997

Please sign in to comment.