Skip to content

Commit

Permalink
Merge pull request #929 from dwillist/387-inspect-builder-output-format
Browse files Browse the repository at this point in the history
387 inspect builder output format
  • Loading branch information
dwillist authored Oct 28, 2020
2 parents 4b79fea + fc9bfec commit 5ea3d97
Show file tree
Hide file tree
Showing 41 changed files with 590 additions and 182 deletions.
4 changes: 2 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"testing"
"time"

pubcfg "github.com/buildpacks/pack/config"

"github.com/ghodss/yaml"
"github.com/pelletier/go-toml"

pubcfg "github.com/buildpacks/pack/config"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
Expand Down
11 changes: 11 additions & 0 deletions create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ func (c *Client) addBuildpacksToBuilder(ctx context.Context, opts CreateBuilderO
return errors.Wrapf(err, "extracting from registry %s", style.Symbol(b.URI))
}
case buildpack.URILocator:
if b.URI == "" {
b.URI = locator
}
c.logger.Debugf("Downloading buildpack from URI: %s", style.Symbol(b.URI))

err := ensureBPSupport(b.URI)
Expand Down Expand Up @@ -285,6 +288,14 @@ func (c *Client) addBuildpacksToBuilder(ctx context.Context, opts CreateBuilderO
return errors.Wrap(err, "invalid buildpack")
}

bpDesc := mainBP.Descriptor()
for _, deprecatedAPI := range bldr.LifecycleDescriptor().APIs.Buildpack.Deprecated {
if deprecatedAPI.Equal(bpDesc.API) {
c.logger.Warnf("Buildpack %s is using deprecated Buildpacks API version %s", style.Symbol(bpDesc.Info.FullName()), style.Symbol(bpDesc.API.String()))
break
}
}

for _, bp := range append([]dist.Buildpack{mainBP}, depBPs...) {
bldr.AddBuildpack(bp)
}
Expand Down
53 changes: 48 additions & 5 deletions create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
ifakes "github.com/buildpacks/pack/internal/fakes"
"github.com/buildpacks/pack/internal/image"
ilogging "github.com/buildpacks/pack/internal/logging"
"github.com/buildpacks/pack/internal/style"
"github.com/buildpacks/pack/logging"
h "github.com/buildpacks/pack/testhelpers"
"github.com/buildpacks/pack/testmocks"
Expand Down Expand Up @@ -60,7 +61,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
)

it.Before(func() {
logger = ilogging.NewLogWithWriters(&out, &out)
logger = ilogging.NewLogWithWriters(&out, &out, ilogging.WithVerbose())
mockController = gomock.NewController(t)
mockDownloader = testmocks.NewMockDownloader(mockController)
mockImageFetcher = testmocks.NewMockImageFetcher(mockController)
Expand Down Expand Up @@ -572,11 +573,31 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, bldr.LifecycleDescriptor().API.BuildpackVersion.String(), "0.2")
//nolint:staticcheck
h.AssertEq(t, bldr.LifecycleDescriptor().API.PlatformVersion.String(), "0.2")
h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Buildpack.Deprecated.AsStrings(), []string{})
h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Buildpack.Deprecated.AsStrings(), []string{"0.2", "0.3"})
h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Buildpack.Supported.AsStrings(), []string{"0.2", "0.3", "0.4"})
h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Platform.Deprecated.AsStrings(), []string{"0.2"})
h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Platform.Supported.AsStrings(), []string{"0.3", "0.4"})
})

it("should warn when deprecated Buildpack API version used", func() {
prepareFetcherWithBuildImage()
prepareFetcherWithRunImages()
bldr := successfullyCreateBuilder()

h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Buildpack.Deprecated.AsStrings(), []string{"0.2", "0.3"})
h.AssertContains(t, out.String(), fmt.Sprintf("Buildpack %s is using deprecated Buildpacks API version %s", style.Symbol("[email protected]"), style.Symbol("0.3")))
})

it("shouldn't warn when Buildpack API version used isn't deprecated", func() {
prepareFetcherWithBuildImage()
prepareFetcherWithRunImages()
opts.Config.Buildpacks[0].URI = "https://example.fake/bp-one-with-api-4.tgz"
mockDownloader.EXPECT().Download(gomock.Any(), "https://example.fake/bp-one-with-api-4.tgz").Return(blob.NewBlob(filepath.Join("testdata", "buildpack-api-0.4")), nil).AnyTimes()
bldr := successfullyCreateBuilder()

h.AssertEq(t, bldr.LifecycleDescriptor().APIs.Buildpack.Deprecated.AsStrings(), []string{"0.2", "0.3"})
h.AssertNotContains(t, out.String(), "is using deprecated Buildpacks API version")
})
})

when("windows", func() {
Expand Down Expand Up @@ -882,7 +903,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {

when("package image lives in docker registry", func() {
it.Before(func() {
packageImage = fakes.NewImage("some/package-"+h.RandString(12), "", nil)
packageImage = fakes.NewImage("docker.io/some/package-"+h.RandString(12), "", nil)
mockImageFactory.EXPECT().NewImage(packageImage.Name(), false).Return(packageImage, nil)

bpd := dist.BuildpackDescriptor{
Expand Down Expand Up @@ -949,6 +970,28 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
})
})

when("publish=true and pull-policy=always", func() {
it("should use remote package URI", func() {
prepareFetcherWithBuildImage()
prepareFetcherWithRunImages()
opts.BuilderName = "some/builder"

opts.Publish = true
opts.PullPolicy = config.PullAlways
opts.Config.Buildpacks = append(
opts.Config.Buildpacks,
pubbldr.BuildpackConfig{
ImageOrURI: dist.ImageOrURI{
BuildpackURI: dist.BuildpackURI{URI: packageImage.Name()},
},
},
)

shouldFetchPackageImageWith(false, config.PullAlways)
h.AssertNil(t, subject.CreateBuilder(context.TODO(), opts))
})
})

when("publish=true and pull-policy=never", func() {
it("should push to registry and not pull package image", func() {
prepareFetcherWithBuildImage()
Expand Down Expand Up @@ -1001,7 +1044,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
prepareFetcherWithRunImages()
opts.BuilderName = "some/builder"

notPackageImage := fakes.NewImage("not/package", "", nil)
notPackageImage := fakes.NewImage("docker.io/not/package", "", nil)
opts.Config.Buildpacks = append(
opts.Config.Buildpacks,
pubbldr.BuildpackConfig{
Expand All @@ -1014,7 +1057,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
mockImageFetcher.EXPECT().Fetch(gomock.Any(), notPackageImage.Name(), gomock.Any(), gomock.Any()).Return(notPackageImage, nil)
h.AssertNil(t, notPackageImage.SetLabel("io.buildpacks.buildpack.layers", ""))

h.AssertError(t, subject.CreateBuilder(context.TODO(), opts), "extracting buildpacks from 'not/package': could not find label 'io.buildpacks.buildpackage.metadata'")
h.AssertError(t, subject.CreateBuilder(context.TODO(), opts), "extracting buildpacks from 'docker.io/not/package': could not find label 'io.buildpacks.buildpackage.metadata'")
})
})
})
Expand Down
39 changes: 19 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,48 @@ module github.com/buildpacks/pack
require (
github.com/BurntSushi/toml v0.3.1
github.com/Masterminds/semver v1.5.0
github.com/Microsoft/hcsshim v0.8.7 // indirect
github.com/Microsoft/hcsshim v0.8.10 // indirect
github.com/apex/log v1.9.0
github.com/buildpacks/imgutil v0.0.0-20201015202701-6dd3ca364074
github.com/buildpacks/lifecycle v0.7.2
github.com/containerd/containerd v1.3.3 // indirect
github.com/buildpacks/imgutil v0.0.0-20201022190551-6525b8cdcdd0
github.com/buildpacks/lifecycle v0.9.2
github.com/containerd/containerd v1.4.1 // indirect
github.com/containerd/continuity v0.0.0-20200107194136-26c1120b8d41 // indirect
github.com/docker/cli v0.0.0-20200312141509-ef2f64abbd37 // indirect
github.com/docker/docker v1.4.2-0.20200221181110-62bd5a33f707
github.com/docker/go-connections v0.4.0
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/go-cmp v0.5.2
github.com/google/go-containerregistry v0.0.0-20200313165449-955bf358a3d8
github.com/google/go-containerregistry v0.1.4
github.com/google/go-github/v30 v30.1.0
github.com/heroku/color v0.0.6
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/gomega v1.10.2
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1
github.com/opencontainers/runc v0.1.1 // indirect
github.com/opencontainers/selinux v1.4.0 // indirect
github.com/opencontainers/selinux v1.6.0 // indirect
github.com/pelletier/go-toml v1.8.1
github.com/pkg/errors v0.9.1
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94
github.com/sclevine/spec v1.4.0
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/cobra v0.0.7
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/spf13/cobra v1.1.1
github.com/willf/bitset v1.1.11 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
golang.org/x/mod v0.3.0
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20200313141609-30c55424f95d // indirect
google.golang.org/grpc v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
google.golang.org/genproto v0.0.0-20201022181438-0ff5f38871d5 // indirect
google.golang.org/grpc v1.33.1 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gotest.tools/v3 v3.0.2 // indirect
)

go 1.14
Loading

0 comments on commit 5ea3d97

Please sign in to comment.