Skip to content

Commit

Permalink
Merge branch 'main' into 642_inspect_buildpack
Browse files Browse the repository at this point in the history
  • Loading branch information
dwillist authored Sep 22, 2020
2 parents 1cce3c7 + 1d20341 commit d3de4ae
Show file tree
Hide file tree
Showing 36 changed files with 1,401 additions and 565 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build/changelog/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 65 additions & 41 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math/rand"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -192,7 +193,7 @@ func testWithoutSpecificBuilderRequirement(

pack.JustRunSuccessfully("untrust-builder", builderName)

assert.NotContain(pack.ConfigFileContents(), builderName)
assert.NotContains(pack.ConfigFileContents(), builderName)
})
})

Expand Down Expand Up @@ -348,7 +349,7 @@ func testWithoutSpecificBuilderRequirement(
assertions.NewOutputAssertionManager(t, output).ReportsPackagePublished(packageName)

_, _, err := dockerCli.ImageInspectWithRaw(context.Background(), packageName)
h.AssertError(t, err, "No such image")
assert.ErrorContains(err, "No such image")

assert.Nil(h.PullImageWithAuth(dockerCli, packageName, registryConfig.RegistryAuth()))

Expand Down Expand Up @@ -615,8 +616,6 @@ func testAcceptance(
var untrustedBuilderName string

it.Before(func() {
h.SkipIf(t, dockerHostOS() == "windows", "untrusted builders are not yet supported for windows builds")

var err error
untrustedBuilderName, err = createBuilder(
t,
Expand All @@ -629,9 +628,6 @@ func testAcceptance(
})

it.After(func() {
if dockerHostOS() == "windows" {
return
}
h.DockerRmi(dockerCli, untrustedBuilderName)
})

Expand Down Expand Up @@ -717,7 +713,7 @@ func testAcceptance(

t.Log("add a local mirror")
localRunImageMirror := registryConfig.RepoName("pack-test/run-mirror")
assert.Nil(dockerCli.ImageTag(context.TODO(), runImage, localRunImageMirror))
assert.Succeeds(dockerCli.ImageTag(context.TODO(), runImage, localRunImageMirror))
defer h.DockerRmi(dockerCli, localRunImageMirror)
pack.JustRunSuccessfully("set-run-image-mirrors", runImage, "-m", localRunImageMirror)

Expand Down Expand Up @@ -762,7 +758,7 @@ func testAcceptance(
assertLifecycleOutput.ReportsCacheCreation(cachedLaunchLayer)

t.Log("cacher adds layers")
h.AssertContainsMatch(t, output, `(?i)Adding cache layer 'simple/layers:cached-launch-layer'`)
assert.Matches(output, regexp.MustCompile(`(?i)Adding cache layer 'simple/layers:cached-launch-layer'`))

if pack.Supports("inspect-image") {
t.Log("inspect-image")
Expand Down Expand Up @@ -812,6 +808,7 @@ func testAcceptance(
it("doesn't have color", func() {
appPath := filepath.Join("testdata", "mock_app")

//--no-color is set as a default option in our tests, and doesn't need to be explicitly provided
output := pack.RunSuccessfully("build", repoName, "-p", appPath)
imgId, err := imgIDForRepoName(repoName)
if err != nil {
Expand All @@ -826,6 +823,32 @@ func testAcceptance(
})
})

when("--quiet", func() {
it.Before(func() {
h.SkipUnless(t,
pack.SupportsFeature(invoke.QuietMode),
"pack had a bug for quiet mode until 0.13.2",
)
})

it("only logs app name and sha", func() {
appPath := filepath.Join("testdata", "mock_app")

pack.SetVerbose(false)
defer pack.SetVerbose(true)

output := pack.RunSuccessfully("build", repoName, "-p", appPath, "--quiet")
imgId, err := imgIDForRepoName(repoName)
if err != nil {
t.Fatal(err)
}
defer h.DockerRmi(dockerCli, imgId)

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportSuccessfulQuietBuild(repoName)
})
})

it("supports building app from a zip file", func() {
appPath := filepath.Join("testdata", "mock_app.zip")
output := pack.RunSuccessfully("build", repoName, "-p", appPath)
Expand All @@ -851,8 +874,8 @@ func testAcceptance(
})

it.After(func() {
assert.Nil(os.Remove(buildpackTgz))
assert.Nil(h.DockerRmi(dockerCli, repoName))
assert.Succeeds(os.Remove(buildpackTgz))
assert.Succeeds(h.DockerRmi(dockerCli, repoName))
})

when("the network mode is not provided", func() {
Expand Down Expand Up @@ -923,7 +946,7 @@ func testAcceptance(
var err error
tmpVolumeSrc, err = ioutil.TempDir("", "volume-mount-source")
assert.Nil(err)
assert.Nil(os.Chmod(tmpVolumeSrc, 0777)) // Override umask
assert.Succeeds(os.Chmod(tmpVolumeSrc, 0777)) // Override umask

// Some OSes (like macOS) use symlinks for the standard temp dir.
// Resolve it so it can be properly mounted by the Docker daemon.
Expand Down Expand Up @@ -1047,7 +1070,7 @@ func testAcceptance(
})

it.After(func() {
assert.Nil(os.Remove(localBuildpackTgz))
assert.Succeeds(os.Remove(localBuildpackTgz))
})

it("adds the buildpack to the builder and runs it", func() {
Expand Down Expand Up @@ -1158,7 +1181,7 @@ func testAcceptance(
})

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

it("adds the buildpacks to the builder and runs them", func() {
Expand Down Expand Up @@ -1189,7 +1212,7 @@ func testAcceptance(
})

it.After(func() {
assert.Nil(os.Remove(otherStackBuilderTgz))
assert.Succeeds(os.Remove(otherStackBuilderTgz))
})

it("errors", func() {
Expand Down Expand Up @@ -1226,8 +1249,8 @@ func testAcceptance(
})

it.After(func() {
assert.Nil(os.Unsetenv("ENV2_CONTENTS"))
assert.Nil(os.RemoveAll(envPath))
assert.Succeeds(os.Unsetenv("ENV2_CONTENTS"))
assert.Succeeds(os.RemoveAll(envPath))
})

it("provides the env vars to the build and detect steps", func() {
Expand All @@ -1249,11 +1272,11 @@ func testAcceptance(

when("--env", func() {
it.Before(func() {
assert.Nil(os.Setenv("ENV2_CONTENTS", "Env2 Layer Contents From Environment"))
assert.Succeeds(os.Setenv("ENV2_CONTENTS", "Env2 Layer Contents From Environment"))
})

it.After(func() {
assert.Nil(os.Unsetenv("ENV2_CONTENTS"))
assert.Succeeds(os.Unsetenv("ENV2_CONTENTS"))
})

it("provides the env vars to the build and detect steps", func() {
Expand Down Expand Up @@ -1375,7 +1398,7 @@ func testAcceptance(
t.Fatalf("Expected to see image %s in %s", repo, contents)
}

assert.Nil(h.PullImageWithAuth(dockerCli, repoName, registryConfig.RegistryAuth()))
assert.Succeeds(h.PullImageWithAuth(dockerCli, repoName, registryConfig.RegistryAuth()))
defer h.DockerRmi(dockerCli, repoName)

t.Log("app is runnable")
Expand Down Expand Up @@ -1436,7 +1459,7 @@ func testAcceptance(

err := command.Wait()
assert.NotNil(err)
assert.NotContain(buf.String(), "Successfully built image")
assert.NotContains(buf.String(), "Successfully built image")
})
})

Expand Down Expand Up @@ -1488,7 +1511,7 @@ func testAcceptance(
})

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

it("should exclude ALL specified files and directories", func() {
Expand All @@ -1511,9 +1534,9 @@ exclude = [ "*.sh", "secrets/", "media/metadata" ]
"--buildpack", buildpackTgz,
"--descriptor", excludeDescriptorPath,
)
assert.NotContain(output, "api_keys.json")
assert.NotContain(output, "user_token")
assert.NotContain(output, "test.sh")
assert.NotContains(output, "api_keys.json")
assert.NotContains(output, "user_token")
assert.NotContains(output, "test.sh")

assert.Contains(output, "cookie.jar")
assert.Contains(output, "mountain.jpg")
Expand All @@ -1540,9 +1563,9 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
"--buildpack", buildpackTgz,
"--descriptor", includeDescriptorPath,
)
assert.NotContain(output, "api_keys.json")
assert.NotContain(output, "user_token")
assert.NotContain(output, "test.sh")
assert.NotContains(output, "api_keys.json")
assert.NotContains(output, "user_token")
assert.NotContains(output, "test.sh")

assert.Contains(output, "cookie.jar")
assert.Contains(output, "mountain.jpg")
Expand Down Expand Up @@ -1583,7 +1606,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
runImageMirror,
)
})
h.AssertNil(t, err)
assert.Nil(err)

// register task to be run to 'clean up' a task
suiteManager.RegisterCleanUp("clean-"+key, func() error {
Expand All @@ -1596,7 +1619,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
output := pack.RunSuccessfully(
"set-run-image-mirrors", "pack-test/run", "--mirror", "some-registry.com/pack-test/run1",
)
h.AssertEq(t, output, "Run Image 'pack-test/run' configured with mirror 'some-registry.com/pack-test/run1'\n")
assert.Equal(output, "Run Image 'pack-test/run' configured with mirror 'some-registry.com/pack-test/run1'\n")

output = pack.RunSuccessfully("inspect-builder", builderName)

Expand Down Expand Up @@ -1796,8 +1819,8 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
assert.Nil(err)
buildCacheVolume := cache.NewVolumeCache(ref, "build", dockerCli)
launchCacheVolume := cache.NewVolumeCache(ref, "launch", dockerCli)
assert.Nil(buildCacheVolume.Clear(context.TODO()))
assert.Nil(launchCacheVolume.Clear(context.TODO()))
assert.Succeeds(buildCacheVolume.Clear(context.TODO()))
assert.Succeeds(launchCacheVolume.Clear(context.TODO()))
})

when("daemon", func() {
Expand All @@ -1810,7 +1833,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
})

it.After(func() {
assert.Nil(h.DockerRmi(dockerCli, runAfter))
assert.Succeeds(h.DockerRmi(dockerCli, runAfter))
})

it("uses provided run image", func() {
Expand Down Expand Up @@ -1841,7 +1864,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
})

it.After(func() {
assert.Nil(h.DockerRmi(dockerCli, localRunImageMirror))
assert.Succeeds(h.DockerRmi(dockerCli, localRunImageMirror))
})

it("prefers the local mirror", func() {
Expand All @@ -1863,7 +1886,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
when("image metadata has a mirror", func() {
it.Before(func() {
// clean up existing mirror first to avoid leaking images
assert.Nil(h.DockerRmi(dockerCli, runImageMirror))
assert.Succeeds(h.DockerRmi(dockerCli, runImageMirror))

buildRunImage(runImageMirror, "mirror-after-1", "mirror-after-2")
})
Expand All @@ -1887,7 +1910,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]

when("--publish", func() {
it.Before(func() {
assert.Nil(h.PushImage(dockerCli, repoName, registryConfig))
assert.Succeeds(h.PushImage(dockerCli, repoName, registryConfig))
})

when("--run-image", func() {
Expand All @@ -1896,7 +1919,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
it.Before(func() {
runAfter = registryConfig.RepoName("run-after/" + h.RandString(10))
buildRunImage(runAfter, "contents-after-1", "contents-after-2")
assert.Nil(h.PushImage(dockerCli, runAfter, registryConfig))
assert.Succeeds(h.PushImage(dockerCli, runAfter, registryConfig))
})

it.After(func() {
Expand All @@ -1907,7 +1930,7 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
output := pack.RunSuccessfully("rebase", repoName, "--publish", "--run-image", runAfter)

assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulRebase(repoName)
assert.Nil(h.PullImageWithAuth(dockerCli, repoName, registryConfig.RegistryAuth()))
assert.Succeeds(h.PullImageWithAuth(dockerCli, repoName, registryConfig.RegistryAuth()))
assertMockAppRunsWithOutput(t,
assert,
repoName,
Expand Down Expand Up @@ -2149,7 +2172,7 @@ func createComplexBuilder(t *testing.T,
}

assert.Contains(output, fmt.Sprintf("Successfully created builder image '%s'", bldr))
assert.Nil(h.PushImage(dockerCli, bldr, registryConfig))
assert.Succeeds(h.PushImage(dockerCli, bldr, registryConfig))

return bldr, nil
}
Expand Down Expand Up @@ -2269,7 +2292,7 @@ func createBuilder(
return "", errors.Wrapf(err, "pack failed with output %s", output)
}
assert.Contains(output, fmt.Sprintf("Successfully created builder image '%s'", bldr))
assert.Nil(h.PushImage(dockerCli, bldr, registryConfig))
assert.Succeeds(h.PushImage(dockerCli, bldr, registryConfig))

return bldr, nil
}
Expand Down Expand Up @@ -2429,12 +2452,13 @@ func assertMockAppRunsWithOutput(t *testing.T, assert h.AssertionManager, repoNa
ctrID := runDockerImageExposePort(t, assert, containerName, repoName)
defer dockerCli.ContainerKill(context.TODO(), containerName, "SIGKILL")
defer dockerCli.ContainerRemove(context.TODO(), containerName, dockertypes.ContainerRemoveOptions{Force: true})

logs, err := dockerCli.ContainerLogs(context.TODO(), ctrID, dockertypes.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
})
h.AssertNil(t, err)
assert.Nil(err)

copyErr := make(chan error)
go func() {
Expand Down
8 changes: 8 additions & 0 deletions acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package assertions
import (
"fmt"
"regexp"
"strings"
"testing"

h "github.com/buildpacks/pack/testhelpers"
Expand All @@ -30,6 +31,13 @@ func (o OutputAssertionManager) ReportsSuccessfulImageBuild(name string) {
o.assert.ContainsF(o.output, "Successfully built image '%s'", name)
}

func (o OutputAssertionManager) ReportSuccessfulQuietBuild(name string) {
o.testObject.Helper()
o.testObject.Log("quiet mode")

o.assert.Matches(strings.TrimSpace(o.output), regexp.MustCompile(name+`@sha256:[\w]{12}`))
}

func (o OutputAssertionManager) ReportsSuccessfulRebase(name string) {
o.testObject.Helper()

Expand Down
Loading

0 comments on commit d3de4ae

Please sign in to comment.