Skip to content

Commit

Permalink
Remove code for '@latest' syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Meyer <ameyer@pivotal.io>
Signed-off-by: Micah Young <myoung@pivotal.io>
  • Loading branch information
ameyer-pivotal authored and Javier Romero and Andrew Meyer committed Feb 12, 2020
1 parent 55a5121 commit 62f9bb6
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 120 deletions.
2 changes: 1 addition & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func testAcceptance(t *testing.T, when spec.G, it spec.S, packFixturesDir, packP
"--buildpack",
"noop.buildpack@noop.buildpack.version",
"--buildpack",
"read/env@latest",
"read/env",
"--env",
"DETECT_ENV_BUILDPACK=true",
))
Expand Down
17 changes: 2 additions & 15 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/buildpacks/pack/internal/archive"
"github.com/buildpacks/pack/internal/build"
"github.com/buildpacks/pack/internal/builder"
"github.com/buildpacks/pack/internal/buildpack"
"github.com/buildpacks/pack/internal/dist"
"github.com/buildpacks/pack/internal/paths"
"github.com/buildpacks/pack/internal/stack"
Expand Down Expand Up @@ -404,7 +405,7 @@ func (c *Client) processBuildpacks(ctx context.Context, builderOrder dist.Order,
order = newOrder
}
case isBuildpackID(bp):
id, version := c.parseBuildpack(bp)
id, version := buildpack.ParseIDLocator(bp)
order = appendBuildpackToOrder(order, dist.BuildpackInfo{
ID: id,
Version: version,
Expand Down Expand Up @@ -490,20 +491,6 @@ func ensureBPSupport(bpPath string) (err error) {
return nil
}

func (c *Client) parseBuildpack(bp string) (string, string) {
parts := strings.Split(strings.TrimPrefix(bp, fromBuilderPrefix+":"), "@")
if len(parts) == 2 {
if parts[1] == "latest" {
c.logger.Warn("@latest syntax is deprecated, will not work in future releases")
return parts[0], ""
}

return parts[0], parts[1]
}

return parts[0], ""
}

func (c *Client) createEphemeralBuilder(rawBuilderImage imgutil.Image, env map[string]string, order dist.Order, buildpacks []dist.Buildpack) (*builder.Builder, error) {
origBuilderName := rawBuilderImage.Name()
bldr, err := builder.New(rawBuilderImage, fmt.Sprintf("pack.local/builder/%x:latest", randString(10)))
Expand Down
39 changes: 7 additions & 32 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
Buildpacks: []builder.BuildpackMetadata{
{
BuildpackInfo: dist.BuildpackInfo{ID: "buildpack.1.id", Version: "buildpack.1.version"},
Latest: true,
},
{
BuildpackInfo: dist.BuildpackInfo{ID: "buildpack.2.id", Version: "buildpack.2.version"},
Latest: true,
},
},
Stack: builder.StackMetadata{
Expand Down Expand Up @@ -628,26 +626,6 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {

assertOrderEquals(`[[order]]
[[order.group]]
id = "buildpack.1.id"
version = "buildpack.1.version"
`)
})
})

when("id@latest", func() {
it("resolves version and prints a warning", func() {
h.AssertNil(t, subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Builder: builderName,
ClearCache: true,
Buildpacks: []string{"buildpack.1.id@latest"},
}))
h.AssertEq(t, fakeLifecycle.Opts.Builder.Name(), defaultBuilderImage.Name())
h.AssertContains(t, outBuf.String(), "Warning: @latest syntax is deprecated, will not work in future releases")

assertOrderEquals(`[[order]]
[[order.group]]
id = "buildpack.1.id"
version = "buildpack.1.version"
Expand Down Expand Up @@ -975,21 +953,18 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
ID: "buildpack.1.id",
Version: "buildpack.1.version",
},
Latest: true,
},
{
BuildpackInfo: dist.BuildpackInfo{
ID: "buildpack.2.id",
Version: "buildpack.2.version",
},
Latest: true,
},
{
BuildpackInfo: dist.BuildpackInfo{
ID: "some-other-buildpack-id",
Version: "some-other-buildpack-version",
},
Latest: true,
},
})
})
Expand Down Expand Up @@ -1030,10 +1005,10 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
}},
})
h.AssertEq(t, bldr.Buildpacks(), []builder.BuildpackMetadata{
{BuildpackInfo: buildpack1Info, Latest: true},
{BuildpackInfo: buildpack2Info, Latest: true},
{BuildpackInfo: dirBuildpackInfo, Latest: true},
{BuildpackInfo: tgzBuildpackInfo, Latest: true},
{BuildpackInfo: buildpack1Info},
{BuildpackInfo: buildpack2Info},
{BuildpackInfo: dirBuildpackInfo},
{BuildpackInfo: tgzBuildpackInfo},
})
})
})
Expand Down Expand Up @@ -1076,9 +1051,9 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
}},
})
h.AssertEq(t, bldr.Buildpacks(), []builder.BuildpackMetadata{
{BuildpackInfo: dist.BuildpackInfo{ID: "buildpack.1.id", Version: "buildpack.1.version"}, Latest: true},
{BuildpackInfo: dist.BuildpackInfo{ID: "buildpack.2.id", Version: "buildpack.2.version"}, Latest: true},
{BuildpackInfo: dist.BuildpackInfo{ID: "some-other-buildpack-id", Version: "some-other-buildpack-version"}, Latest: true},
{BuildpackInfo: dist.BuildpackInfo{ID: "buildpack.1.id", Version: "buildpack.1.version"}},
{BuildpackInfo: dist.BuildpackInfo{ID: "buildpack.2.id", Version: "buildpack.2.version"}},
{BuildpackInfo: dist.BuildpackInfo{ID: "some-other-buildpack-id", Version: "some-other-buildpack-version"}},
})
})
})
Expand Down
13 changes: 0 additions & 13 deletions builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,13 @@ func getWarningsForObsoleteFields(reader io.Reader) ([]string, error) {
var warnings []string

var obsoleteConfig = struct {
Buildpacks []struct {
Latest bool
}
Groups []interface{}
}{}

if _, err := toml.DecodeReader(reader, &obsoleteConfig); err != nil {
return nil, err
}

latestUsed := false

for _, bp := range obsoleteConfig.Buildpacks {
latestUsed = bp.Latest
}

if latestUsed {
warnings = append(warnings, fmt.Sprintf("%s field on a buildpack is obsolete and will be ignored", style.Symbol("latest")))
}

if len(obsoleteConfig.Groups) > 0 {
warnings = append(warnings, fmt.Sprintf("%s field is obsolete in favor of %s", style.Symbol("groups"), style.Symbol("order")))
}
Expand Down
25 changes: 0 additions & 25 deletions builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,6 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
})

when("detecting warnings", func() {
when("'latest' field is used on buildpack", func() {
it.Before(func() {
h.AssertNil(t, ioutil.WriteFile(builderConfigPath, []byte(`
[[buildpacks]]
id = "some.buildpack"
latest = true
[[buildpacks]]
id = "other.buildpack"
latest = true
[[order]]
[[order.group]]
id = "some.buildpack"
`), 0666))
})

it("returns a warning", func() {
_, warns, err := builder.ReadConfig(builderConfigPath)
h.AssertNil(t, err)

h.AssertSliceContainsOnly(t, warns, "'latest' field on a buildpack is obsolete and will be ignored")
})
})

when("'groups' field is used", func() {
it.Before(func() {
h.AssertNil(t, ioutil.WriteFile(builderConfigPath, []byte(`
Expand Down
2 changes: 0 additions & 2 deletions create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
}
h.AssertEq(t, bldr.Buildpacks(), []builder.BuildpackMetadata{{
BuildpackInfo: bpInfo,
Latest: true,
}})
h.AssertEq(t, bldr.Order(), dist.Order{{
Group: []dist.BuildpackRef{{
Expand Down Expand Up @@ -420,7 +419,6 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
}
h.AssertEq(t, bldr.Buildpacks(), []builder.BuildpackMetadata{{
BuildpackInfo: bpInfo,
Latest: true,
}})
h.AssertEq(t, bldr.Order(), dist.Order{{
Group: []dist.BuildpackRef{{
Expand Down
4 changes: 1 addition & 3 deletions inspect_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func testInspectBuilder(t *testing.T, when spec.G, it spec.S) {
"buildpacks": [
{
"id": "test.bp.one",
"version": "1.0.0",
"latest": true
"version": "1.0.0"
}
],
"lifecycle": {"version": "1.2.3"},
Expand Down Expand Up @@ -146,7 +145,6 @@ func testInspectBuilder(t *testing.T, when spec.G, it spec.S) {
ID: "test.bp.one",
Version: "1.0.0",
},
Latest: true,
})
})

Expand Down
2 changes: 0 additions & 2 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ func (b *Builder) Save(logger logging.Logger) error {
return errors.Wrap(err, "processing order")
}

processMetadata(&b.metadata)

tmpDir, err := ioutil.TempDir("", "create-builder-scratch")
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions internal/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,19 +709,15 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {

h.AssertEq(t, metadata.Buildpacks[0].ID, "buildpack-1-id")
h.AssertEq(t, metadata.Buildpacks[0].Version, "buildpack-1-version-1")
h.AssertEq(t, metadata.Buildpacks[0].Latest, false)

h.AssertEq(t, metadata.Buildpacks[1].ID, "buildpack-1-id")
h.AssertEq(t, metadata.Buildpacks[1].Version, "buildpack-1-version-2")
h.AssertEq(t, metadata.Buildpacks[1].Latest, false)

h.AssertEq(t, metadata.Buildpacks[2].ID, "buildpack-2-id")
h.AssertEq(t, metadata.Buildpacks[2].Version, "buildpack-2-version-1")
h.AssertEq(t, metadata.Buildpacks[2].Latest, true)

h.AssertEq(t, metadata.Buildpacks[3].ID, "order-buildpack-id")
h.AssertEq(t, metadata.Buildpacks[3].Version, "order-buildpack-version")
h.AssertEq(t, metadata.Buildpacks[3].Latest, true)
})

it("adds the buildpack layers label", func() {
Expand Down Expand Up @@ -865,7 +861,6 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
// adds new buildpack
h.AssertEq(t, metadata.Buildpacks[1].ID, "buildpack-1-id")
h.AssertEq(t, metadata.Buildpacks[1].Version, "buildpack-1-version-1")
h.AssertEq(t, metadata.Buildpacks[1].Latest, true)
})
})
})
Expand Down
16 changes: 0 additions & 16 deletions internal/builder/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type CreatorMetadata struct {

type BuildpackMetadata struct {
dist.BuildpackInfo
Latest bool `json:"latest"` // deprecated
}

type LifecycleMetadata struct {
Expand All @@ -37,18 +36,3 @@ type RunImageMetadata struct {
Image string `json:"image" toml:"image"`
Mirrors []string `json:"mirrors" toml:"mirrors"`
}

func processMetadata(md *Metadata) {
for i, bp := range md.Buildpacks {
var matchingBps []dist.BuildpackInfo
for _, bp2 := range md.Buildpacks {
if bp.ID == bp2.ID {
matchingBps = append(matchingBps, bp.BuildpackInfo)
}
}

if len(matchingBps) == 1 {
md.Buildpacks[i].Latest = true
}
}
}
2 changes: 0 additions & 2 deletions internal/commands/create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func testCreateBuilderCommand(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, ioutil.WriteFile(builderConfigPath, []byte(`
[[buildpacks]]
id = "some.buildpack"
latest = true
`), 0666))
})

Expand All @@ -71,7 +70,6 @@ func testCreateBuilderCommand(t *testing.T, when spec.G, it spec.S) {
})
h.AssertNil(t, command.Execute())

h.AssertContains(t, outBuf.String(), "Warning: builder configuration: 'latest' field on a buildpack is obsolete and will be ignored")
h.AssertContains(t, outBuf.String(), "Warning: builder configuration: empty 'order' definition")
})
})
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/inspect_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func testInspectBuilderCommand(t *testing.T, when spec.G, it spec.S) {
buildpack1Info = dist.BuildpackInfo{ID: "test.bp.one", Version: "1.0.0"}
buildpack2Info = dist.BuildpackInfo{ID: "test.bp.two", Version: "2.0.0"}
buildpacks = []builder.BuildpackMetadata{
{BuildpackInfo: buildpack1Info, Latest: true},
{BuildpackInfo: buildpack2Info, Latest: false},
{BuildpackInfo: buildpack1Info},
{BuildpackInfo: buildpack2Info},
}
remoteInfo = &pack.BuilderInfo{
Description: "Some remote description",
Expand Down
3 changes: 1 addition & 2 deletions testdata/builder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ uri = "some-path-2"

[[buildpacks]]
id = "some/bp2"
uri = "some-latest-path-2"
latest = true
uri = "some-path-3"

[[order]]
[[order.group]]
Expand Down

0 comments on commit 62f9bb6

Please sign in to comment.