Skip to content
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

Adds basic compatibility with buildpack/lifecycle#149 #250

Merged
merged 3 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PACK_BIN?=pack
PACKAGE_BASE=github.com/buildpack/pack
PACKAGES:=$(shell $(GOCMD) list -mod=vendor ./... | grep -v /testdata/)
SRC:=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
ARCHIVE_NAME=pack-$(PACK_VERSION)

all: clean verify test build

Expand All @@ -14,6 +15,9 @@ build:
mkdir -p ./out
$(GOENV) $(GOCMD) build -mod=vendor -ldflags "-X 'main.Version=${PACK_VERSION}'" -o ./out/$(PACK_BIN) -a ./cmd/pack

package:
tar czf ./out/$(ARCHIVE_NAME).tgz -C out/ pack

install-goimports:
@echo "> Installing goimports..."
$(GOCMD) install -mod=vendor golang.org/x/tools/cmd/goimports
Expand All @@ -31,7 +35,7 @@ test: unit acceptance
unit: format vet
@echo "> Running unit/integration tests..."
$(GOCMD) test -mod=vendor -v -count=1 -parallel=1 -timeout=0 ./...

acceptance: format vet
@echo "> Running acceptance tests..."
$(GOCMD) test -mod=vendor -v -count=1 -parallel=1 -timeout=0 -tags=acceptance ./acceptance
Expand Down
94 changes: 62 additions & 32 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
var notBuilderTgz string

it.Before(func() {
notBuilderTgz = h.CreateTgz(t, filepath.Join("testdata", "mock_buildpacks", "not-in-builder-buildpack"), "./", 0766)
notBuilderTgz = h.CreateTgz(t, filepath.Join(testBuildpacksDir(), "not-in-builder-buildpack"), "./", 0766)
})

it.After(func() {
Expand All @@ -276,21 +276,24 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
cmd := packCmd(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--buildpack", notBuilderTgz,
"--buildpack", "simple/layers@simple-layers-version",
"--buildpack", "noop.buildpack",
"--buildpack", notBuilderTgz, // tgz not in builder
"--buildpack", "simple/layers@simple-layers-version", // with version
"--buildpack", "noop.buildpack", // without version
"--buildpack", "read/env@latest", // latest (for backwards compatibility)
"--env", "DETECT_ENV_BUILDPACK=true",
)
output := h.Run(t, cmd)
h.AssertContains(t, output, "NOOP Buildpack")
h.AssertContains(t, output, "Read Env Buildpack")
h.AssertContains(t, output, fmt.Sprintf("Successfully built image '%s'", repoName))

t.Log("app is runnable")
assertMockAppRunsWithOutput(t, repoName,
"Local Buildpack Dep Contents",
"Launch Dep Contents",
"Cached Dep Contents",
)
})

})

when("the argument is directory", func() {
Expand All @@ -300,7 +303,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
cmd := packCmd(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--buildpack", filepath.Join("testdata", "mock_buildpacks", "not-in-builder-buildpack"),
"--buildpack", filepath.Join(testBuildpacksDir(), "not-in-builder-buildpack"),
)
output := h.Run(t, cmd)
h.AssertContains(t, output, fmt.Sprintf("Successfully built image '%s'", repoName))
Expand All @@ -313,7 +316,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
var otherStackBuilderTgz string

it.Before(func() {
otherStackBuilderTgz = h.CreateTgz(t, filepath.Join("testdata", "mock_buildpacks", "other-stack-buildpack"), "./", 0766)
otherStackBuilderTgz = h.CreateTgz(t, filepath.Join(testBuildpacksDir(), "other-stack-buildpack"), "./", 0766)
})

it.After(func() {
Expand All @@ -328,7 +331,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
)
txt, err := h.RunE(cmd)
h.AssertNotNil(t, err)
h.AssertContains(t, txt, "buildpack 'other/stack/bp' version 'other-stack-version' does not support stack 'pack.test.stack'")
h.AssertContains(t, txt, "buildpack 'other/stack/bp@other-stack-version' does not support stack 'pack.test.stack'")
ekcasey marked this conversation as resolved.
Show resolved Hide resolved
})
})
})
Expand Down Expand Up @@ -780,57 +783,84 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S) {
})
}

func testBuildpacksDir() string {
d := "v1"
if lifecycleVersion.GreaterThan(lifecycleV030) {
d = "v2"
}
return filepath.Join("testdata", "mock_buildpacks", d)
}

func createBuilder(t *testing.T, runImageMirror string) string {
t.Log("create builder image")
t.Log("Creating builder image...")

// CREATE TEMP WORKING DIR
tmpDir, err := ioutil.TempDir("", "create-test-builder")
h.AssertNil(t, err)
defer os.RemoveAll(tmpDir)

h.RecursiveCopy(t, filepath.Join("testdata", "mock_buildpacks"), tmpDir)
// DETERMINE LIFECYCLE
lifecyclePath, hasLifecyclePath := os.LookupEnv("LIFECYCLE_PATH")
if hasLifecyclePath {
lifecycleVersion = semver.MustParse("0.0.0")

buildpacks := []string{
"noop-buildpack",
"not-in-builder-buildpack",
"other-stack-buildpack",
"read-env-buildpack",
"simple-layers-buildpack",
if !filepath.IsAbs(lifecyclePath) {
lifecyclePath, err = filepath.Abs(lifecyclePath)
h.AssertNil(t, err)
}
}

for _, v := range buildpacks {
tgz := h.CreateTgz(t, filepath.Join("testdata", "mock_buildpacks", v), "./", 0766)
err := os.Rename(tgz, filepath.Join(tmpDir, v+".tgz"))
h.AssertNil(t, err)
if v, ok := os.LookupEnv("LIFECYCLE_VERSION"); ok {
lifecycleVersion = semver.MustParse(v)
}

// DETERMINE TEST DATA
t.Log("Using buildpacks from: ", testBuildpacksDir())
h.RecursiveCopy(t, testBuildpacksDir(), tmpDir)

// AMEND builder.toml
builderConfigFile, err := os.OpenFile(filepath.Join(tmpDir, "builder.toml"), os.O_RDWR|os.O_APPEND, 0666)
h.AssertNil(t, err)

// ADD run-image-mirrors
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("run-image-mirrors = [\"%s\"]\n", runImageMirror)))
h.AssertNil(t, err)

// ADD lifecycle
_, err = builderConfigFile.Write([]byte("[lifecycle]\n"))
h.AssertNil(t, err)
if lifecyclePath, ok := os.LookupEnv("LIFECYCLE_PATH"); ok {
lifecycleVersion = semver.MustParse("0.0.0")
if !filepath.IsAbs(lifecyclePath) {
t.Fatal("LIFECYCLE_PATH must be an absolute path")
}

if hasLifecyclePath {
t.Logf("Adding lifecycle path '%s' to builder config", lifecyclePath)
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("uri = \"%s\"\n", strings.ReplaceAll(lifecyclePath, `\`, `\\`))))
h.AssertNil(t, err)
}
if lcver, ok := os.LookupEnv("LIFECYCLE_VERSION"); ok {
lifecycleVersion = semver.MustParse(lcver)
t.Logf("Adding lifecycle version '%s' to builder config", lifecycleVersion)
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("version = \"%s\"\n", lifecycleVersion.String())))
h.AssertNil(t, err)
}

t.Logf("Adding lifecycle version '%s' to builder config", lifecycleVersion)
_, err = builderConfigFile.Write([]byte(fmt.Sprintf("version = \"%s\"\n", lifecycleVersion.String())))
h.AssertNil(t, err)

builderConfigFile.Close()

// PACKAGE BUILDPACKS
buildpacks := []string{
"noop-buildpack",
"not-in-builder-buildpack",
"other-stack-buildpack",
ekcasey marked this conversation as resolved.
Show resolved Hide resolved
"read-env-buildpack",
"simple-layers-buildpack",
}

for _, v := range buildpacks {
tgz := h.CreateTgz(t, filepath.Join(testBuildpacksDir(), v), "./", 0766)
err := os.Rename(tgz, filepath.Join(tmpDir, v+".tgz"))
h.AssertNil(t, err)
}

// NAME BUILDER
builder := registryConfig.RepoName("some-org/" + h.RandString(10))

// CREATE BUILDER
t.Logf("Creating builder. Lifecycle version '%s' will be used.", lifecycleVersion)
cmd := exec.Command(packPath, "create-builder", "--no-color", builder, "-b", filepath.Join(tmpDir, "builder.toml"))
output := h.Run(t, cmd)
Expand All @@ -841,7 +871,7 @@ func createBuilder(t *testing.T, runImageMirror string) string {
}

func createStack(t *testing.T, dockerCli *client.Client) {
t.Log("create stack images")
t.Log("Creating stack images...")
createStackImage(t, dockerCli, runImage, filepath.Join("testdata", "mock_stack"))
h.AssertNil(t, dockerCli.ImageTag(context.Background(), runImage, buildImage))
h.AssertNil(t, dockerCli.ImageTag(context.Background(), runImage, runImageMirror))
Expand Down
16 changes: 8 additions & 8 deletions acceptance/testdata/inspect_builder_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Run Images:
%s

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

Detection Order:
Group #1:
Expand All @@ -36,10 +36,10 @@ Run Images:
%s

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

Detection Order:
Group #1:
Expand Down
3 changes: 0 additions & 3 deletions acceptance/testdata/mock_buildpacks/noop-buildpack/bin/build

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
uri = "read-env-buildpack.tgz"

[[buildpacks]]
id = "noop.buildpack"
version = "noop.buildpack.version"
# intentionally missing id/version as they are optional
uri = "noop-buildpack.tgz"
latest = true

[[groups]]
[[groups.buildpacks]]
id = "simple/layers"
version = "simple-layers-version"
[[groups.buildpacks]]
id = "read/env"
version = "read-env-version"
optional = true
[[order]]
[[order.group]]
id = "simple/layers"
# intentionlly missing version to test support

[[order.group]]
id = "read/env"
version = "read-env-version"
optional = true

[stack]
id = "pack.test.stack"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "---> NOOP Buildpack"
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

#!/usr/bin/env bash

echo "---> Read Env Buildpack"

set -o errexit
Expand Down
30 changes: 30 additions & 0 deletions acceptance/testdata/mock_buildpacks/v2/builder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[[buildpacks]]
id = "simple/layers"
version = "simple-layers-version"
uri = "simple-layers-buildpack.tgz"

[[buildpacks]]
id = "read/env"
version = "read-env-version"
uri = "read-env-buildpack.tgz"

[[buildpacks]]
# intentionally missing id/version as they are optional
ekcasey marked this conversation as resolved.
Show resolved Hide resolved
uri = "noop-buildpack.tgz"

[[order]]
[[order.group]]
id = "simple/layers"
# intentionlly missing version to test support

[[order.group]]
id = "read/env"
version = "read-env-version"
optional = true

[stack]
id = "pack.test.stack"
build-image = "pack-test/build"
run-image = "pack-test/run"

# run-image-mirror and lifecycle are appended by acceptance tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "---> NOOP 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,7 @@
[buildpack]
id = "noop.buildpack"
version = "noop.buildpack.version"
name = "NOOP Buildpack"

[[stacks]]
id = "pack.test.stack"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

echo "---> Simple mock buildpack"

set -o errexit
set -o nounset
set -o pipefail

launch_dir=$1

## makes a launch layer
echo "making launch layer"
mkdir "$launch_dir/launch-layer"
echo "Local Buildpack Dep Contents" > "$launch_dir/launch-layer/local-dep"
ln -snf "$launch_dir/launch-layer/local-dep" local-dep
echo "launch = true" > "$launch_dir/launch-layer.toml"

## adds a process
echo 'processes = [{ type = "web", command = "./run"}]' > "$launch_dir/launch.toml"

echo "---> Done"
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,7 @@
[buildpack]
id = "local/bp"
version = "local-bp-version"
name = "Not in Builder Buildpack"

[[stacks]]
id = "pack.test.stack"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[buildpack]
id = "other/stack/bp"
version = "other-stack-version"
name = "Other Stack Buildpack"

[[stacks]]
id = "other.stack"
Loading