Skip to content

Commit

Permalink
Merge branch 'main' into fix/run-image-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbustamante authored May 20, 2024
2 parents 3350bc9 + 884dd18 commit 6405ff4
Show file tree
Hide file tree
Showing 97 changed files with 4,780 additions and 771 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
- name: Set up go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Set up go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
check-latest: true
- name: Set up go env for Unix
if: runner.os != 'Windows'
Expand Down Expand Up @@ -186,7 +186,7 @@ jobs:
- name: Set up go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
check-latest: true
- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Set up go
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
check-latest: true
- name: Set up go env
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ install-golangci-lint:

## mod-tidy: Tidy Go modules
mod-tidy:
$(GOCMD) mod tidy -compat=1.21
cd tools && $(GOCMD) mod tidy -compat=1.21
$(GOCMD) mod tidy -compat=1.22
cd tools && $(GOCMD) mod tidy -compat=1.22

## tidy: Tidy modules and format the code
tidy: mod-tidy format
Expand Down
163 changes: 158 additions & 5 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import (
"testing"
"time"

"github.com/buildpacks/imgutil"
"github.com/buildpacks/lifecycle/api"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/types"
"github.com/pelletier/go-toml"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
Expand Down Expand Up @@ -623,6 +626,147 @@ func testWithoutSpecificBuilderRequirement(
})
})
})

when("manifest", func() {
var (
indexRepoName string
repoName1 string
repoName2 string
indexLocalPath string
tmpDir string
err error
)

it.Before(func() {
h.SkipIf(t, !pack.SupportsFeature(invoke.ManifestCommands), "pack manifest commands are available since 0.34.0")

// local storage path
tmpDir, err = os.MkdirTemp("", "manifest-commands-test")
assert.Nil(err)
os.Setenv("XDG_RUNTIME_DIR", tmpDir)

// manifest commands are experimental
pack.EnableExperimental()

// used to avoid authentication issues with the local registry
os.Setenv("DOCKER_CONFIG", registryConfig.DockerConfigDir)
})

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

when("create", func() {
it.Before(func() {
it.Before(func() {
indexRepoName = registryConfig.RepoName(h.NewRandomIndexRepoName())

// Manifest 1
repoName1 = fmt.Sprintf("%s:%s", indexRepoName, "busybox-amd64")
h.CreateRemoteImage(t, indexRepoName, "busybox-amd64", "busybox@sha256:a236a6469768c17ca1a6ac81a35fe6fbc1efd76b0dcdf5aebb1cf5f0774ee539")

// Manifest 2
repoName2 = fmt.Sprintf("%s:%s", indexRepoName, "busybox-arm64")
h.CreateRemoteImage(t, indexRepoName, "busybox-arm64", "busybox@sha256:0bcc1b827b855c65eaf6e031e894e682b6170160b8a676e1df7527a19d51fb1a")
})
})
when("--publish", func() {
it("creates and push the index to a remote registry", func() {
output := pack.RunSuccessfully("manifest", "create", "--publish", indexRepoName, repoName1, repoName2)
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulIndexPushed(indexRepoName)
h.AssertRemoteImageIndex(t, indexRepoName, types.OCIImageIndex, 2)
})
})

when("no --publish", func() {
it("creates the index locally", func() {
output := pack.RunSuccessfully("manifest", "create", indexRepoName, repoName1, repoName2)
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulIndexLocallyCreated(indexRepoName)

indexLocalPath = filepath.Join(tmpDir, imgutil.MakeFileSafeName(indexRepoName))
index := h.ReadIndexManifest(t, indexLocalPath)
h.AssertEq(t, len(index.Manifests), 2)
h.AssertEq(t, index.MediaType, types.OCIImageIndex)
})
})
})

when("index is already created", func() {
var digest v1.Hash

it.Before(func() {
indexRepoName = registryConfig.RepoName(h.NewRandomIndexRepoName())

// Manifest 1
repoName1 = fmt.Sprintf("%s:%s", indexRepoName, "busybox-amd64")
image1 := h.CreateRemoteImage(t, indexRepoName, "busybox-amd64", "busybox@sha256:a236a6469768c17ca1a6ac81a35fe6fbc1efd76b0dcdf5aebb1cf5f0774ee539")
digest, err = image1.Digest()
assert.Nil(err)

// Manifest 2
repoName2 = fmt.Sprintf("%s:%s", indexRepoName, "busybox-arm64")
h.CreateRemoteImage(t, indexRepoName, "busybox-arm64", "busybox@sha256:0bcc1b827b855c65eaf6e031e894e682b6170160b8a676e1df7527a19d51fb1a")

// create an index locally
pack.RunSuccessfully("manifest", "create", indexRepoName, repoName1)
indexLocalPath = filepath.Join(tmpDir, imgutil.MakeFileSafeName(indexRepoName))
})

when("add", func() {
it("adds the manifest to the index", func() {
output := pack.RunSuccessfully("manifest", "add", indexRepoName, repoName2)
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulManifestAddedToIndex(repoName2)

index := h.ReadIndexManifest(t, indexLocalPath)
h.AssertEq(t, len(index.Manifests), 2)
h.AssertEq(t, index.MediaType, types.OCIImageIndex)
})
})

when("remove", func() {
it("removes the index from local storage", func() {
output := pack.RunSuccessfully("manifest", "remove", indexRepoName)
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulIndexDeleted()

h.AssertPathDoesNotExists(t, indexLocalPath)
})
})

when("annotate", func() {
it("adds annotations to the manifest in the index", func() {
output := pack.RunSuccessfully("manifest", "annotate", indexRepoName, repoName1, "--annotations", "foo=bar")
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulIndexAnnotated(repoName1, indexRepoName)

index := h.ReadIndexManifest(t, indexLocalPath)
h.AssertEq(t, len(index.Manifests), 1)
h.AssertEq(t, len(index.Manifests[0].Annotations), 1)
})
})

when("rm", func() {
it.Before(func() {
// we need to point to the manifest digest we want to delete
repoName1 = fmt.Sprintf("%s@%s", repoName1, digest.String())
})

it("removes the manifest from the index", func() {
output := pack.RunSuccessfully("manifest", "rm", indexRepoName, repoName1)
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulRemoveManifestFromIndex(indexRepoName)

index := h.ReadIndexManifest(t, indexLocalPath)
h.AssertEq(t, len(index.Manifests), 0)
})
})

when("push", func() {
it("pushes the index to a remote registry", func() {
output := pack.RunSuccessfully("manifest", "push", indexRepoName)
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulIndexPushed(indexRepoName)
h.AssertRemoteImageIndex(t, indexRepoName, types.OCIImageIndex, 1)
})
})
})
})
}

func testAcceptance(
Expand Down Expand Up @@ -834,8 +978,10 @@ func testAcceptance(
launchCacheVolume.Clear(context.TODO())
})

when("builder is untrusted", func() {
when("there are build image extensions", func() {
it("uses the 5 phases, and runs the extender (build)", func() {
origLifecycle := lifecycle.Image()

output := pack.RunSuccessfully(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
Expand All @@ -846,7 +992,7 @@ func testAcceptance(
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulImageBuild(repoName)

assertOutput := assertions.NewLifecycleOutputAssertionManager(t, output)
assertOutput.IncludesLifecycleImageTag(lifecycle.Image())
assertOutput.IncludesTagOrEphemeralLifecycle(origLifecycle)
assertOutput.IncludesSeparatePhasesWithBuildExtension()

t.Log("inspecting image")
Expand Down Expand Up @@ -885,6 +1031,8 @@ func testAcceptance(
})

it("uses the 5 phases, and runs the extender (run)", func() {
origLifecycle := lifecycle.Image()

output := pack.RunSuccessfully(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
Expand All @@ -896,7 +1044,8 @@ func testAcceptance(
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulImageBuild(repoName)

assertOutput := assertions.NewLifecycleOutputAssertionManager(t, output)
assertOutput.IncludesLifecycleImageTag(lifecycle.Image())

assertOutput.IncludesTagOrEphemeralLifecycle(origLifecycle)
assertOutput.IncludesSeparatePhasesWithRunExtension()

t.Log("inspecting image")
Expand Down Expand Up @@ -976,6 +1125,8 @@ func testAcceptance(

when("daemon", func() {
it("uses the 5 phases", func() {
origLifecycle := lifecycle.Image()

output := pack.RunSuccessfully(
"build", repoName,
"-p", filepath.Join("testdata", "mock_app"),
Expand All @@ -985,13 +1136,15 @@ func testAcceptance(
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulImageBuild(repoName)

assertOutput := assertions.NewLifecycleOutputAssertionManager(t, output)
assertOutput.IncludesLifecycleImageTag(lifecycle.Image())
assertOutput.IncludesTagOrEphemeralLifecycle(origLifecycle)
assertOutput.IncludesSeparatePhases()
})
})

when("--publish", func() {
it("uses the 5 phases", func() {
origLifecycle := lifecycle.Image()

buildArgs := []string{
repoName,
"-p", filepath.Join("testdata", "mock_app"),
Expand All @@ -1007,7 +1160,7 @@ func testAcceptance(
assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulImageBuild(repoName)

assertOutput := assertions.NewLifecycleOutputAssertionManager(t, output)
assertOutput.IncludesLifecycleImageTag(lifecycle.Image())
assertOutput.IncludesTagOrEphemeralLifecycle(origLifecycle)
assertOutput.IncludesSeparatePhases()
})
})
Expand Down
9 changes: 7 additions & 2 deletions acceptance/assertions/lifecycle_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package assertions
import (
"fmt"
"regexp"
"strings"
"testing"

h "github.com/buildpacks/pack/testhelpers"
Expand Down Expand Up @@ -85,8 +86,12 @@ func (l LifecycleOutputAssertionManager) IncludesSeparatePhasesWithRunExtension(
l.assert.ContainsAll(l.output, "[detector]", "[analyzer]", "[extender (run)]", "[exporter]")
}

func (l LifecycleOutputAssertionManager) IncludesLifecycleImageTag(tag string) {
func (l LifecycleOutputAssertionManager) IncludesTagOrEphemeralLifecycle(tag string) {
l.testObject.Helper()

l.assert.Contains(l.output, tag)
if !strings.Contains(l.output, tag) {
if !strings.Contains(l.output, "pack.local/lifecyle") {
l.testObject.Fatalf("Unable to locate reference to lifecycle image within output")
}
}
}
36 changes: 36 additions & 0 deletions acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,42 @@ func (o OutputAssertionManager) ReportsSuccessfulImageBuild(name string) {
o.assert.ContainsF(o.output, "Successfully built image '%s'", name)
}

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

o.assert.ContainsF(o.output, "Successfully created manifest list '%s'", name)
}

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

o.assert.ContainsF(o.output, "Successfully pushed manifest list '%s' to registry", name)
}

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

o.assert.ContainsF(o.output, "Successfully added image '%s' to index", name)
}

func (o OutputAssertionManager) ReportsSuccessfulIndexDeleted() {
o.testObject.Helper()

o.assert.Contains(o.output, "Successfully deleted manifest list(s) from local storage")
}

func (o OutputAssertionManager) ReportsSuccessfulIndexAnnotated(name, manifest string) {
o.testObject.Helper()

o.assert.ContainsF(o.output, "Successfully annotated image '%s' in index '%s'", name, manifest)
}

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

o.assert.ContainsF(o.output, "Successfully removed image(s) from index: '%s'", name)
}

func (o OutputAssertionManager) ReportSuccessfulQuietBuild(name string) {
o.testObject.Helper()
o.testObject.Log("quiet mode")
Expand Down
4 changes: 4 additions & 0 deletions acceptance/invoke/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const (
PlatformRetries
FlattenBuilderCreationV2
FixesRunImageMetadata
ManifestCommands
)

var featureTests = map[Feature]func(i *PackInvoker) bool{
Expand Down Expand Up @@ -274,6 +275,9 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
FixesRunImageMetadata: func(i *PackInvoker) bool {
return i.atLeast("v0.34.0")
},
ManifestCommands: func(i *PackInvoker) bool {
return i.atLeast("v0.34.0")
},
}

func (i *PackInvoker) SupportsFeature(f Feature) bool {
Expand Down
4 changes: 2 additions & 2 deletions acceptance/managers/image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (im ImageManager) ExposePortOnImage(image, containerName string) TestContai
}, nil, nil, containerName)
im.assert.Nil(err)

err = im.dockerCli.ContainerStart(ctx, ctr.ID, dockertypes.ContainerStartOptions{})
err = im.dockerCli.ContainerStart(ctx, ctr.ID, container.StartOptions{})
im.assert.Nil(err)
return TestContainer{
testObject: im.testObject,
Expand Down Expand Up @@ -137,7 +137,7 @@ func (t TestContainer) RunWithOutput() string {
func (t TestContainer) Cleanup() {
t.testObject.Helper()
t.dockerCli.ContainerKill(context.Background(), t.name, "SIGKILL")
t.dockerCli.ContainerRemove(context.Background(), t.name, dockertypes.ContainerRemoveOptions{Force: true})
t.dockerCli.ContainerRemove(context.Background(), t.name, container.RemoveOptions{Force: true})
}

func (t TestContainer) WaitForResponse(duration time.Duration) string {
Expand Down
4 changes: 2 additions & 2 deletions acceptance/testdata/pack_fixtures/report_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Pack:
Version: {{ .Version }}
OS/Arch: {{ .OS }}/{{ .Arch }}

Default Lifecycle Version: 0.18.5
Default Lifecycle Version: 0.19.6

Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12
Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13

Config:
default-builder-image = "{{ .DefaultBuilder }}"
Expand Down
Loading

0 comments on commit 6405ff4

Please sign in to comment.