From dc94db0228e2d75a312d7f7e111f93f4caf2dba8 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Mon, 22 Mar 2021 23:18:09 +0000 Subject: [PATCH 1/7] Add builder to project descriptor Signed-off-by: Sambhav Kothari --- internal/commands/build.go | 25 +++++++++++------ internal/commands/build_test.go | 50 +++++++++++++++++++++++++++++++++ project/project.go | 1 + 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/internal/commands/build.go b/internal/commands/build.go index d46266de6..ceea73d74 100644 --- a/internal/commands/build.go +++ b/internal/commands/build.go @@ -72,6 +72,18 @@ func Build(logger logging.Logger, cfg config.Config, packClient PackClient) *cob logger.Debugf("Using project descriptor located at %s", style.Symbol(actualDescriptorPath)) } + builder := flags.Builder + // We only override the builder to the one in the project descriptor + // if it was not explicitly set by the user + if !cmd.Flags().Changed("builder") && descriptor.Build.Builder != "" { + builder = descriptor.Build.Builder + } + + if builder == "" { + suggestSettingBuilder(logger, packClient) + return pack.NewSoftError() + } + buildpacks := flags.Buildpacks env, err := parseEnv(flags.EnvFiles, flags.Env) @@ -79,11 +91,11 @@ func Build(logger logging.Logger, cfg config.Config, packClient PackClient) *cob return err } - trustBuilder := isTrustedBuilder(cfg, flags.Builder) || flags.TrustBuilder + trustBuilder := isTrustedBuilder(cfg, builder) || flags.TrustBuilder if trustBuilder { - logger.Debugf("Builder %s is trusted", style.Symbol(flags.Builder)) + logger.Debugf("Builder %s is trusted", style.Symbol(builder)) } else { - logger.Debugf("Builder %s is untrusted", style.Symbol(flags.Builder)) + logger.Debugf("Builder %s is untrusted", style.Symbol(builder)) logger.Debug("As a result, the phases of the lifecycle which require root access will be run in separate trusted ephemeral containers.") logger.Debug("For more information, see https://medium.com/buildpacks/faster-more-secure-builds-with-pack-0-11-0-4d0c633ca619") } @@ -110,7 +122,7 @@ func Build(logger logging.Logger, cfg config.Config, packClient PackClient) *cob } if err := packClient.Build(cmd.Context(), pack.BuildOptions{ AppPath: flags.AppPath, - Builder: flags.Builder, + Builder: builder, Registry: flags.Registry, AdditionalMirrors: getMirrors(cfg), AdditionalTags: flags.AdditionalTags, @@ -172,11 +184,6 @@ This option may set DOCKER_HOST environment variable for the build container if } func validateBuildFlags(flags *BuildFlags, cfg config.Config, packClient PackClient, logger logging.Logger) error { - if flags.Builder == "" { - suggestSettingBuilder(logger, packClient) - return pack.NewSoftError() - } - if flags.Registry != "" && !cfg.Experimental { return pack.NewExperimentError("Support for buildpack registries is currently experimental.") } diff --git a/internal/commands/build_test.go b/internal/commands/build_test.go index 9fa932b63..9cc6457eb 100644 --- a/internal/commands/build_test.go +++ b/internal/commands/build_test.go @@ -517,7 +517,48 @@ version = "1.0" h.AssertNil(t, command.Execute()) }) }) + when("file has a builder specified", func() { + var projectTomlPath string + + it.Before(func() { + projectToml, err := ioutil.TempFile("", "project.toml") + h.AssertNil(t, err) + defer projectToml.Close() + + projectToml.WriteString(` +[project] +name = "Sample" + +[build] +builder = "my-builder" +`) + projectTomlPath = projectToml.Name() + }) + + it.After(func() { + h.AssertNil(t, os.RemoveAll(projectTomlPath)) + }) + when("a builder is not explicitly passed by the user", func() { + it("should build an image with configuration in descriptor", func() { + mockClient.EXPECT(). + Build(gomock.Any(), EqBuildOptionsWithBuilder("my-builder")). + Return(nil) + command.SetArgs([]string{"--descriptor", projectTomlPath, "image"}) + h.AssertNil(t, command.Execute()) + }) + }) + when("a builder is explicitly passed by the user", func() { + it("should build an image with the passed builder flag", func() { + mockClient.EXPECT(). + Build(gomock.Any(), EqBuildOptionsWithBuilder("flag-builder")). + Return(nil) + + command.SetArgs([]string{"--builder", "flag-builder", "--descriptor", projectTomlPath, "image"}) + h.AssertNil(t, command.Execute()) + }) + }) + }) when("file is invalid", func() { var projectTomlPath string @@ -694,6 +735,15 @@ func EqBuildOptionsWithNetwork(network string) gomock.Matcher { } } +func EqBuildOptionsWithBuilder(builder string) gomock.Matcher { + return buildOptionsMatcher{ + description: fmt.Sprintf("Builder=%s", builder), + equals: func(o pack.BuildOptions) bool { + return o.Builder == builder + }, + } +} + func EqBuildOptionsWithTrustedBuilder(trustBuilder bool) gomock.Matcher { return buildOptionsMatcher{ description: fmt.Sprintf("Trust Builder=%t", trustBuilder), diff --git a/project/project.go b/project/project.go index 82e68af4c..7efa1afa7 100644 --- a/project/project.go +++ b/project/project.go @@ -25,6 +25,7 @@ type Build struct { Exclude []string `toml:"exclude"` Buildpacks []Buildpack `toml:"buildpacks"` Env []EnvVar `toml:"env"` + Builder string `toml:"builder"` } type Project struct { From 787d4aa018540751d7975e8f9b0d102e1c129bcf Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Tue, 30 Mar 2021 15:31:16 +0100 Subject: [PATCH 2/7] Add Heroku-20 to suggested stacks list Heroku-20 is now Heroku's default stack, and was previously added to the suggested builders list in #1052, however was was not yet listed in the suggested stacks list. See: https://github.com/heroku/pack-images#heroku-pack-base-images Signed-off-by: Ed Morley <501702+edmorley@users.noreply.github.com> --- internal/commands/stack_suggest.go | 7 +++++++ internal/commands/stack_suggest_test.go | 6 ++++++ internal/commands/suggest_stacks_test.go | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/internal/commands/stack_suggest.go b/internal/commands/stack_suggest.go index aab8526c1..e90bf316c 100644 --- a/internal/commands/stack_suggest.go +++ b/internal/commands/stack_suggest.go @@ -26,6 +26,13 @@ var suggestedStacks = []suggestedStack{ BuildImage: "heroku/pack:18-build", RunImage: "heroku/pack:18", }, + { + ID: "heroku-20", + Description: "The official Heroku stack based on Ubuntu 20.04", + Maintainer: "Heroku", + BuildImage: "heroku/pack:20-build", + RunImage: "heroku/pack:20", + }, { ID: "io.buildpacks.stacks.bionic", Description: "A minimal Paketo stack based on Ubuntu 18.04", diff --git a/internal/commands/stack_suggest_test.go b/internal/commands/stack_suggest_test.go index 6876d1b70..a2e408650 100644 --- a/internal/commands/stack_suggest_test.go +++ b/internal/commands/stack_suggest_test.go @@ -38,6 +38,12 @@ func testStacksSuggestCommand(t *testing.T, when spec.G, it spec.S) { Build Image: heroku/pack:18-build Run Image: heroku/pack:18 + Stack ID: heroku-20 + Description: The official Heroku stack based on Ubuntu 20.04 + Maintainer: Heroku + Build Image: heroku/pack:20-build + Run Image: heroku/pack:20 + Stack ID: io.buildpacks.stacks.bionic Description: A minimal Paketo stack based on Ubuntu 18.04 Maintainer: Paketo Project diff --git a/internal/commands/suggest_stacks_test.go b/internal/commands/suggest_stacks_test.go index 015bc4f11..8cd03c811 100644 --- a/internal/commands/suggest_stacks_test.go +++ b/internal/commands/suggest_stacks_test.go @@ -43,6 +43,12 @@ Stacks maintained by the community: Build Image: heroku/pack:18-build Run Image: heroku/pack:18 + Stack ID: heroku-20 + Description: The official Heroku stack based on Ubuntu 20.04 + Maintainer: Heroku + Build Image: heroku/pack:20-build + Run Image: heroku/pack:20 + Stack ID: io.buildpacks.stacks.bionic Description: A minimal Paketo stack based on Ubuntu 18.04 Maintainer: Paketo Project From 6e25fd1c03e103b4ac4cc738b8a4d8ca1b429e4d Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Mon, 29 Mar 2021 20:58:06 +0100 Subject: [PATCH 3/7] Add buildpack name to buildpack and builder metadata Signed-off-by: Sambhav Kothari --- .../inspect_builder_nested_depth_2_output.txt | 28 +++++++++---------- .../inspect_builder_nested_output.txt | 28 +++++++++---------- .../inspect_builder_nested_output_json.txt | 6 ++++ .../inspect_builder_nested_output_toml.txt | 6 ++++ .../inspect_builder_nested_output_yaml.txt | 6 ++++ .../pack_fixtures/inspect_builder_output.txt | 20 ++++++------- .../inspect_buildpack_output.txt | 6 ++-- inspect_builder_test.go | 8 ++++-- inspect_buildpack.go | 1 + inspect_buildpack_test.go | 8 +++++- internal/builder/writer/human_readable.go | 4 +-- .../builder/writer/human_readable_test.go | 24 ++++++++-------- internal/buildpackage/builder_test.go | 2 ++ internal/commands/buildpack_inspect_test.go | 23 +++++++++------ internal/commands/inspect_buildpack.go | 4 +-- internal/commands/inspect_buildpack_test.go | 2 ++ internal/dist/buildpack.go | 1 + internal/dist/dist.go | 2 ++ 18 files changed, 111 insertions(+), 68 deletions(-) diff --git a/acceptance/testdata/pack_fixtures/inspect_builder_nested_depth_2_output.txt b/acceptance/testdata/pack_fixtures/inspect_builder_nested_depth_2_output.txt index 91c7ab5ea..438fa03fe 100644 --- a/acceptance/testdata/pack_fixtures/inspect_builder_nested_depth_2_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_builder_nested_depth_2_output.txt @@ -31,13 +31,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack NOOP Buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack NOOP Buildpack noop.buildpack.version - + read/env Read Env Buildpack read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: @@ -77,13 +77,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack NOOP Buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack NOOP Buildpack noop.buildpack.version - + read/env Read Env Buildpack read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: diff --git a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output.txt b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output.txt index 704e14cda..7756ed690 100644 --- a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output.txt @@ -31,13 +31,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack NOOP Buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack NOOP Buildpack noop.buildpack.version - + read/env Read Env Buildpack read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: @@ -79,13 +79,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack NOOP Buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack NOOP Buildpack noop.buildpack.version - + read/env Read Env Buildpack read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: diff --git a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_json.txt b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_json.txt index 7b7d2a966..b85b9f4f1 100644 --- a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_json.txt +++ b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_json.txt @@ -42,15 +42,18 @@ "buildpacks": [ { "id": "noop.buildpack", + "name": "NOOP Buildpack", "version": "noop.buildpack.later-version", "homepage": "http://geocities.com/cool-bp" }, { "id": "noop.buildpack", + "name": "NOOP Buildpack", "version": "noop.buildpack.version" }, { "id": "read/env", + "name": "Read Env Buildpack", "version": "read-env-version" }, { @@ -133,15 +136,18 @@ "buildpacks": [ { "id": "noop.buildpack", + "name": "NOOP Buildpack", "version": "noop.buildpack.later-version", "homepage": "http://geocities.com/cool-bp" }, { "id": "noop.buildpack", + "name": "NOOP Buildpack", "version": "noop.buildpack.version" }, { "id": "read/env", + "name": "Read Env Buildpack", "version": "read-env-version" }, { diff --git a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_toml.txt b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_toml.txt index 9f7064b02..cd7795316 100644 --- a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_toml.txt +++ b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_toml.txt @@ -35,15 +35,18 @@ default = false [[remote_info.buildpacks]] id = "noop.buildpack" + name = "NOOP Buildpack" version = "noop.buildpack.later-version" homepage = "http://geocities.com/cool-bp" [[remote_info.buildpacks]] id = "noop.buildpack" + name = "NOOP Buildpack" version = "noop.buildpack.version" [[remote_info.buildpacks]] id = "read/env" + name = "Read Env Buildpack" version = "read-env-version" [[remote_info.buildpacks]] @@ -109,15 +112,18 @@ default = false [[local_info.buildpacks]] id = "noop.buildpack" + name = "NOOP Buildpack" version = "noop.buildpack.later-version" homepage = "http://geocities.com/cool-bp" [[local_info.buildpacks]] id = "noop.buildpack" + name = "NOOP Buildpack" version = "noop.buildpack.version" [[local_info.buildpacks]] id = "read/env" + name = "Read Env Buildpack" version = "read-env-version" [[local_info.buildpacks]] diff --git a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_yaml.txt b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_yaml.txt index 45cb4f06e..0692fec05 100644 --- a/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_yaml.txt +++ b/acceptance/testdata/pack_fixtures/inspect_builder_nested_output_yaml.txt @@ -28,11 +28,14 @@ remote_info: - name: {{.run_image_mirror}} buildpacks: - id: noop.buildpack + name: NOOP Buildpack version: noop.buildpack.later-version homepage: http://geocities.com/cool-bp - id: noop.buildpack + name: NOOP Buildpack version: noop.buildpack.version - id: read/env + name: Read Env Buildpack version: read-env-version - id: simple/layers version: simple-layers-version @@ -78,11 +81,14 @@ local_info: - name: {{.run_image_mirror}} buildpacks: - id: noop.buildpack + name: NOOP Buildpack version: noop.buildpack.later-version homepage: http://geocities.com/cool-bp - id: noop.buildpack + name: NOOP Buildpack version: noop.buildpack.version - id: read/env + name: Read Env Buildpack version: read-env-version - id: simple/layers version: simple-layers-version diff --git a/acceptance/testdata/pack_fixtures/inspect_builder_output.txt b/acceptance/testdata/pack_fixtures/inspect_builder_output.txt index fefa49715..1e48d1a4c 100644 --- a/acceptance/testdata/pack_fixtures/inspect_builder_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_builder_output.txt @@ -31,11 +31,11 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - + ID NAME VERSION HOMEPAGE + noop.buildpack NOOP Buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack NOOP Buildpack noop.buildpack.version - + read/env Read Env Buildpack read-env-version - + simple/layers - simple-layers-version - Detection Order: └ Group #1: @@ -73,11 +73,11 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - + ID NAME VERSION HOMEPAGE + noop.buildpack NOOP Buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack NOOP Buildpack noop.buildpack.version - + read/env Read Env Buildpack read-env-version - + simple/layers - simple-layers-version - Detection Order: └ Group #1: diff --git a/acceptance/testdata/pack_fixtures/inspect_buildpack_output.txt b/acceptance/testdata/pack_fixtures/inspect_buildpack_output.txt index 3352d49dc..f032e971a 100644 --- a/acceptance/testdata/pack_fixtures/inspect_buildpack_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_buildpack_output.txt @@ -8,9 +8,9 @@ Stacks: (none) Buildpacks: - ID VERSION HOMEPAGE - simple/layers simple-layers-version - - simple/layers/parent simple-layers-parent-version - + ID NAME VERSION HOMEPAGE + simple/layers Simple Layers Buildpack simple-layers-version - + simple/layers/parent Simple Layers Parent Buildpack simple-layers-parent-version - Detection Order: └ Group #1: diff --git a/inspect_builder_test.go b/inspect_builder_test.go index 754f46bcc..09bad8a8c 100644 --- a/inspect_builder_test.go +++ b/inspect_builder_test.go @@ -126,7 +126,8 @@ func testInspectBuilder(t *testing.T, when spec.G, it spec.S) { { "id": "test.bp.one", "version": "test.bp.one.version", - "homepage": "http://geocities.com/cool-bp" + "homepage": "http://geocities.com/cool-bp", + "name": "one" }, { "id": "test.bp.two", @@ -197,7 +198,8 @@ func testInspectBuilder(t *testing.T, when spec.G, it spec.S) { } ], "layerDiffID": "sha256:test.bp.one.sha256", - "homepage": "http://geocities.com/cool-bp" + "homepage": "http://geocities.com/cool-bp", + "name": "one" } }, "test.bp.two": { @@ -230,6 +232,7 @@ func testInspectBuilder(t *testing.T, when spec.G, it spec.S) { { ID: "test.bp.one", Version: "test.bp.one.version", + Name: "one", Homepage: "http://geocities.com/cool-bp", }, { @@ -298,6 +301,7 @@ func testInspectBuilder(t *testing.T, when spec.G, it spec.S) { }, LayerDiffID: "sha256:test.bp.one.sha256", Homepage: "http://geocities.com/cool-bp", + Name: "one", }, }, "test.bp.two": { diff --git a/inspect_buildpack.go b/inspect_buildpack.go index dd1b366d3..7e3371fde 100644 --- a/inspect_buildpack.go +++ b/inspect_buildpack.go @@ -143,6 +143,7 @@ func extractBuildpacks(layersMd dist.BuildpackLayers) []dist.BuildpackInfo { for version, layerInfo := range buildpackMap { bp := dist.BuildpackInfo{ ID: buildpackID, + Name: layerInfo.Name, Version: version, Homepage: layerInfo.Homepage, } diff --git a/inspect_buildpack_test.go b/inspect_buildpack_test.go index ffcca698e..6d93d373a 100644 --- a/inspect_buildpack_test.go +++ b/inspect_buildpack_test.go @@ -41,6 +41,7 @@ import ( const buildpackageMetadataTag = `{ "id": "some/top-buildpack", "version": "0.0.1", + "name": "top", "homepage": "top-buildpack-homepage", "stacks": [ { @@ -144,7 +145,8 @@ const buildpackLayersTag = `{ } ], "layerDiffID":"sha256:top-buildpack-diff-id", - "homepage":"top-buildpack-homepage" + "homepage":"top-buildpack-homepage", + "name": "top" } } }` @@ -198,6 +200,7 @@ func testInspectBuildpack(t *testing.T, when spec.G, it spec.S) { BuildpackInfo: dist.BuildpackInfo{ ID: "some/top-buildpack", Version: "0.0.1", + Name: "top", Homepage: "top-buildpack-homepage", }, Stacks: []dist.Stack{ @@ -224,6 +227,7 @@ func testInspectBuildpack(t *testing.T, when spec.G, it spec.S) { { ID: "some/top-buildpack", Version: "0.0.1", + Name: "top", Homepage: "top-buildpack-homepage", }, }, @@ -234,6 +238,7 @@ func testInspectBuildpack(t *testing.T, when spec.G, it spec.S) { BuildpackInfo: dist.BuildpackInfo{ ID: "some/top-buildpack", Version: "0.0.1", + Name: "top", Homepage: "top-buildpack-homepage", }, Optional: false, @@ -340,6 +345,7 @@ func testInspectBuildpack(t *testing.T, when spec.G, it spec.S) { }, LayerDiffID: "sha256:top-buildpack-diff-id", Homepage: "top-buildpack-homepage", + Name: "top", }, }, }, diff --git a/internal/builder/writer/human_readable.go b/internal/builder/writer/human_readable.go index 81b8bbeba..8edf515c2 100644 --- a/internal/builder/writer/human_readable.go +++ b/internal/builder/writer/human_readable.go @@ -293,13 +293,13 @@ func buildpacksOutput(buildpacks []dist.BuildpackInfo, builderName string) (stri buildpacksTabWriter = tabwriter.NewWriter(spaceStrippingWriter, writerMinWidth, writerPadChar, buildpacksTabWidth, writerPadChar, writerFlags) ) - _, err := fmt.Fprint(buildpacksTabWriter, " ID\tVERSION\tHOMEPAGE\n") + _, err := fmt.Fprint(buildpacksTabWriter, " ID\tNAME\tVERSION\tHOMEPAGE\n") if err != nil { return "", []string{}, fmt.Errorf("writing to tab writer: %w", err) } for _, b := range buildpacks { - _, err = fmt.Fprintf(buildpacksTabWriter, " %s\t%s\t%s\n", b.ID, b.Version, strs.ValueOrDefault(b.Homepage, "-")) + _, err = fmt.Fprintf(buildpacksTabWriter, " %s\t%s\t%s\t%s\n", b.ID, strs.ValueOrDefault(b.Name, "-"), b.Version, strs.ValueOrDefault(b.Homepage, "-")) if err != nil { return "", []string{}, fmt.Errorf("writing to tab writer: %w", err) } diff --git a/internal/builder/writer/human_readable_test.go b/internal/builder/writer/human_readable_test.go index 044845701..89930b332 100644 --- a/internal/builder/writer/human_readable_test.go +++ b/internal/builder/writer/human_readable_test.go @@ -67,12 +67,12 @@ Run Images: second/default Buildpacks: - ID VERSION HOMEPAGE - test.top.nested test.top.nested.version - - test.nested http://geocities.com/top-bp - test.bp.one test.bp.one.version http://geocities.com/cool-bp - test.bp.two test.bp.two.version - - test.bp.three test.bp.three.version - + ID NAME VERSION HOMEPAGE + test.top.nested - test.top.nested.version - + test.nested - http://geocities.com/top-bp + test.bp.one - test.bp.one.version http://geocities.com/cool-bp + test.bp.two - test.bp.two.version - + test.bp.three - test.bp.three.version - Detection Order: ├ Group #1: @@ -120,12 +120,12 @@ Run Images: second/local-default Buildpacks: - ID VERSION HOMEPAGE - test.top.nested test.top.nested.version - - test.nested http://geocities.com/top-bp - test.bp.one test.bp.one.version http://geocities.com/cool-bp - test.bp.two test.bp.two.version - - test.bp.three test.bp.three.version - + ID NAME VERSION HOMEPAGE + test.top.nested - test.top.nested.version - + test.nested - http://geocities.com/top-bp + test.bp.one - test.bp.one.version http://geocities.com/cool-bp + test.bp.two - test.bp.two.version - + test.bp.three - test.bp.three.version - Detection Order: ├ Group #1: diff --git a/internal/buildpackage/builder_test.go b/internal/buildpackage/builder_test.go index 7fa1578cd..71cec12e1 100644 --- a/internal/buildpackage/builder_test.go +++ b/internal/buildpackage/builder_test.go @@ -418,6 +418,7 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) { Info: dist.BuildpackInfo{ ID: "bp.1.id", Version: "bp.1.version", + Name: "One", Description: "some description", Homepage: "https://example.com/homepage", Keywords: []string{"some-keyword"}, @@ -453,6 +454,7 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) { h.AssertEq(t, md.Stacks[1].ID, "stack.id.2") h.AssertEq(t, md.Keywords[0], "some-keyword") h.AssertEq(t, md.Homepage, "https://example.com/homepage") + h.AssertEq(t, md.Name, "One") h.AssertEq(t, md.Description, "some description") h.AssertEq(t, md.Licenses[0].Type, "MIT") h.AssertEq(t, md.Licenses[0].URI, "https://example.com/license") diff --git a/internal/commands/buildpack_inspect_test.go b/internal/commands/buildpack_inspect_test.go index eceaabf91..b8cb6b5f7 100644 --- a/internal/commands/buildpack_inspect_test.go +++ b/internal/commands/buildpack_inspect_test.go @@ -37,11 +37,11 @@ const complexOutputSection = `Stacks: (omitted) Buildpacks: - ID VERSION HOMEPAGE - some/first-inner-buildpack 1.0.0 first-inner-buildpack-homepage - some/second-inner-buildpack 2.0.0 second-inner-buildpack-homepage - some/third-inner-buildpack 3.0.0 third-inner-buildpack-homepage - some/top-buildpack 0.0.1 top-buildpack-homepage + ID NAME VERSION HOMEPAGE + some/first-inner-buildpack - 1.0.0 first-inner-buildpack-homepage + some/second-inner-buildpack - 2.0.0 second-inner-buildpack-homepage + some/third-inner-buildpack - 3.0.0 third-inner-buildpack-homepage + some/top-buildpack top 0.0.1 top-buildpack-homepage Detection Order: └ Group #1: @@ -71,9 +71,9 @@ const simpleOutputSection = `Stacks: (omitted) Buildpacks: - ID VERSION HOMEPAGE - some/single-buildpack 0.0.1 single-buildpack-homepage - some/buildpack-no-homepage 0.0.2 - + ID NAME VERSION HOMEPAGE + some/single-buildpack some 0.0.1 single-buildpack-homepage + some/buildpack-no-homepage - 0.0.2 - Detection Order: └ Group #1: @@ -147,6 +147,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { ID: "some/top-buildpack", Version: "0.0.1", Homepage: "top-buildpack-homepage", + Name: "top", }, Stacks: []dist.Stack{ {ID: "io.buildpacks.stacks.first-stack", Mixins: []string{"mixin1", "mixin2", "build:mixin3", "build:mixin4"}}, @@ -173,6 +174,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { ID: "some/top-buildpack", Version: "0.0.1", Homepage: "top-buildpack-homepage", + Name: "top", }, }, Order: dist.Order{ @@ -183,6 +185,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { ID: "some/top-buildpack", Version: "0.0.1", Homepage: "top-buildpack-homepage", + Name: "top", }, Optional: false, }, @@ -290,6 +293,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { }, LayerDiffID: "sha256:top-buildpack-diff-id", Homepage: "top-buildpack-homepage", + Name: "top", }, }, }, @@ -301,6 +305,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { ID: "some/single-buildpack", Version: "0.0.1", Homepage: "single-homepage-homepace", + Name: "some", }, Stacks: []dist.Stack{ {ID: "io.buildpacks.stacks.first-stack", Mixins: []string{"mixin1", "mixin2", "build:mixin3", "build:mixin4"}}, @@ -311,6 +316,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { { ID: "some/single-buildpack", Version: "0.0.1", + Name: "some", Homepage: "single-buildpack-homepage", }, { @@ -342,6 +348,7 @@ func testBuildpackInspectCommand(t *testing.T, when spec.G, it spec.S) { }, LayerDiffID: "sha256:single-buildpack-diff-id", Homepage: "single-buildpack-homepage", + Name: "some", }, }, }, diff --git a/internal/commands/inspect_buildpack.go b/internal/commands/inspect_buildpack.go index 98ea129cb..f46a30965 100644 --- a/internal/commands/inspect_buildpack.go +++ b/internal/commands/inspect_buildpack.go @@ -177,12 +177,12 @@ func buildpacksOutput(bps []dist.BuildpackInfo) (string, error) { buf := &bytes.Buffer{} tabWriter := new(tabwriter.Writer).Init(buf, writerMinWidth, writerPadChar, buildpacksTabWidth, writerPadChar, writerFlags) - if _, err := fmt.Fprint(tabWriter, " ID\tVERSION\tHOMEPAGE\n"); err != nil { + if _, err := fmt.Fprint(tabWriter, " ID\tNAME\tVERSION\tHOMEPAGE\n"); err != nil { return "", err } for _, bp := range bps { - if _, err := fmt.Fprintf(tabWriter, " %s\t%s\t%s\n", bp.ID, bp.Version, strs.ValueOrDefault(bp.Homepage, "-")); err != nil { + if _, err := fmt.Fprintf(tabWriter, " %s\t%s\t%s\t%s\n", bp.ID, strs.ValueOrDefault(bp.Name, "-"), bp.Version, strs.ValueOrDefault(bp.Homepage, "-")); err != nil { return "", err } } diff --git a/internal/commands/inspect_buildpack_test.go b/internal/commands/inspect_buildpack_test.go index 0808e7f7c..34d572280 100644 --- a/internal/commands/inspect_buildpack_test.go +++ b/internal/commands/inspect_buildpack_test.go @@ -93,6 +93,7 @@ func testInspectBuildpackCommand(t *testing.T, when spec.G, it spec.S) { ID: "some/top-buildpack", Version: "0.0.1", Homepage: "top-buildpack-homepage", + Name: "top", }, }, Order: dist.Order{ @@ -232,6 +233,7 @@ func testInspectBuildpackCommand(t *testing.T, when spec.G, it spec.S) { ID: "some/single-buildpack", Version: "0.0.1", Homepage: "single-buildpack-homepage", + Name: "some", }, { ID: "some/buildpack-no-homepage", diff --git a/internal/dist/buildpack.go b/internal/dist/buildpack.go index 2244a9edd..a6f25b4cf 100644 --- a/internal/dist/buildpack.go +++ b/internal/dist/buildpack.go @@ -41,6 +41,7 @@ type Buildpack interface { type BuildpackInfo struct { ID string `toml:"id,omitempty" json:"id,omitempty" yaml:"id,omitempty"` + Name string `toml:"name,omitempty" json:"name,omitempty" yaml:"name,omitempty"` Version string `toml:"version,omitempty" json:"version,omitempty" yaml:"version,omitempty"` Description string `toml:"description,omitempty" json:"description,omitempty" yaml:"description,omitempty"` Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty" yaml:"homepage,omitempty"` diff --git a/internal/dist/dist.go b/internal/dist/dist.go index 0965148ce..4a09277a2 100644 --- a/internal/dist/dist.go +++ b/internal/dist/dist.go @@ -50,6 +50,7 @@ type BuildpackLayerInfo struct { Order Order `json:"order,omitempty"` LayerDiffID string `json:"layerDiffID"` Homepage string `json:"homepage,omitempty"` + Name string `json:"name,omitempty"` } func (b BuildpackLayers) Get(id, version string) (BuildpackLayerInfo, bool) { @@ -78,5 +79,6 @@ func AddBuildpackToLayersMD(layerMD BuildpackLayers, descriptor BuildpackDescrip Order: descriptor.Order, LayerDiffID: diffID, Homepage: bpInfo.Homepage, + Name: bpInfo.Name, } } From d6e561a86e354137df7238bbce82493ba0268ed4 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Tue, 30 Mar 2021 23:54:09 +0100 Subject: [PATCH 4/7] Add inspect builder output for previous version of pack Signed-off-by: Sambhav Kothari --- ...t_0.18.0_builder_nested_depth_2_output.txt | 93 +++++++++ .../inspect_0.18.0_builder_nested_output.txt | 97 +++++++++ ...pect_0.18.0_builder_nested_output_json.txt | 187 ++++++++++++++++++ ...pect_0.18.0_builder_nested_output_toml.txt | 151 ++++++++++++++ ...pect_0.18.0_builder_nested_output_yaml.txt | 104 ++++++++++ .../inspect_0.18.0_builder_output.txt | 85 ++++++++ 6 files changed, 717 insertions(+) create mode 100644 acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt create mode 100644 acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt create mode 100644 acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_json.txt create mode 100644 acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_toml.txt create mode 100644 acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_yaml.txt create mode 100644 acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt new file mode 100644 index 000000000..91c7ab5ea --- /dev/null +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt @@ -0,0 +1,93 @@ +Inspecting builder: '{{.builder_name}}' + +REMOTE: + +Created By: + Name: Pack CLI + Version: {{.pack_version}} + +Trusted: {{.trusted}} + +Stack: + ID: pack.test.stack + Mixins: + mixinA + netcat + mixin3 + build:mixinTwo + +Lifecycle: + Version: {{.lifecycle_version}} + Buildpack APIs: + Deprecated: {{ .deprecated_buildpack_apis }} + Supported: {{ .supported_buildpack_apis }} + Platform APIs: + Deprecated: {{ .deprecated_platform_apis }} + Supported: {{ .supported_platform_apis }} + +Run Images: + some-registry.com/pack-test/run1 (user-configured) + pack-test/run + {{.run_image_mirror}} + +Buildpacks: + ID VERSION HOMEPAGE + noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack noop.buildpack.version - + read/env read-env-version - + simple/layers simple-layers-version - + simple/nested-level-1 nested-l1-version - + simple/nested-level-2 nested-l2-version - + +Detection Order: + └ Group #1: + ├ simple/nested-level-1 + │ └ Group #1: + │ └ simple/nested-level-2@nested-l2-version + └ read/env@read-env-version (optional) + +LOCAL: + +Created By: + Name: Pack CLI + Version: {{.pack_version}} + +Trusted: {{.trusted}} + +Stack: + ID: pack.test.stack + Mixins: + mixinA + netcat + mixin3 + build:mixinTwo + +Lifecycle: + Version: {{.lifecycle_version}} + Buildpack APIs: + Deprecated: {{ .deprecated_buildpack_apis }} + Supported: {{ .supported_buildpack_apis }} + Platform APIs: + Deprecated: {{ .deprecated_platform_apis }} + Supported: {{ .supported_platform_apis }} + +Run Images: + some-registry.com/pack-test/run1 (user-configured) + pack-test/run + {{.run_image_mirror}} + +Buildpacks: + ID VERSION HOMEPAGE + noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack noop.buildpack.version - + read/env read-env-version - + simple/layers simple-layers-version - + simple/nested-level-1 nested-l1-version - + simple/nested-level-2 nested-l2-version - + +Detection Order: + └ Group #1: + ├ simple/nested-level-1 + │ └ Group #1: + │ └ simple/nested-level-2@nested-l2-version + └ read/env@read-env-version (optional) diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt new file mode 100644 index 000000000..704e14cda --- /dev/null +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt @@ -0,0 +1,97 @@ +Inspecting builder: '{{.builder_name}}' + +REMOTE: + +Created By: + Name: Pack CLI + Version: {{.pack_version}} + +Trusted: {{.trusted}} + +Stack: + ID: pack.test.stack + Mixins: + mixinA + netcat + mixin3 + build:mixinTwo + +Lifecycle: + Version: {{.lifecycle_version}} + Buildpack APIs: + Deprecated: {{ .deprecated_buildpack_apis }} + Supported: {{ .supported_buildpack_apis }} + Platform APIs: + Deprecated: {{ .deprecated_platform_apis }} + Supported: {{ .supported_platform_apis }} + +Run Images: + some-registry.com/pack-test/run1 (user-configured) + pack-test/run + {{.run_image_mirror}} + +Buildpacks: + ID VERSION HOMEPAGE + noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack noop.buildpack.version - + read/env read-env-version - + simple/layers simple-layers-version - + simple/nested-level-1 nested-l1-version - + simple/nested-level-2 nested-l2-version - + +Detection Order: + └ Group #1: + ├ simple/nested-level-1 + │ └ Group #1: + │ └ simple/nested-level-2@nested-l2-version + │ └ Group #1: + │ └ simple/layers@simple-layers-version + └ read/env@read-env-version (optional) + +LOCAL: + +Created By: + Name: Pack CLI + Version: {{.pack_version}} + +Trusted: {{.trusted}} + +Stack: + ID: pack.test.stack + Mixins: + mixinA + netcat + mixin3 + build:mixinTwo + +Lifecycle: + Version: {{.lifecycle_version}} + Buildpack APIs: + Deprecated: {{ .deprecated_buildpack_apis }} + Supported: {{ .supported_buildpack_apis }} + Platform APIs: + Deprecated: {{ .deprecated_platform_apis }} + Supported: {{ .supported_platform_apis }} + +Run Images: + some-registry.com/pack-test/run1 (user-configured) + pack-test/run + {{.run_image_mirror}} + +Buildpacks: + ID VERSION HOMEPAGE + noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack noop.buildpack.version - + read/env read-env-version - + simple/layers simple-layers-version - + simple/nested-level-1 nested-l1-version - + simple/nested-level-2 nested-l2-version - + +Detection Order: + └ Group #1: + ├ simple/nested-level-1 + │ └ Group #1: + │ └ simple/nested-level-2@nested-l2-version + │ └ Group #1: + │ └ simple/layers@simple-layers-version + └ read/env@read-env-version (optional) diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_json.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_json.txt new file mode 100644 index 000000000..7b7d2a966 --- /dev/null +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_json.txt @@ -0,0 +1,187 @@ +{ + "builder_name": "{{.builder_name}}", + "trusted": false, + "default": false, + "remote_info": { + "created_by": { + "name": "Pack CLI", + "version": "{{.pack_version}}" + }, + "stack": { + "id": "pack.test.stack", + "mixins": [ + "mixinA", + "netcat", + "mixin3", + "build:mixinTwo" + ] + }, + "lifecycle": { + "version": "{{.lifecycle_version}}", + "buildpack_apis": { + "deprecated": {{.deprecated_buildpack_apis}}, + "supported": {{.supported_buildpack_apis}} + }, + "platform_apis": { + "deprecated": {{.deprecated_platform_apis}}, + "supported": {{.supported_platform_apis}} + } + }, + "run_images": [ + { + "name": "some-registry.com/pack-test/run1", + "user_configured": true + }, + { + "name": "pack-test/run" + }, + { + "name": "{{.run_image_mirror}}" + } + ], + "buildpacks": [ + { + "id": "noop.buildpack", + "version": "noop.buildpack.later-version", + "homepage": "http://geocities.com/cool-bp" + }, + { + "id": "noop.buildpack", + "version": "noop.buildpack.version" + }, + { + "id": "read/env", + "version": "read-env-version" + }, + { + "id": "simple/layers", + "version": "simple-layers-version" + }, + { + "id": "simple/nested-level-1", + "version": "nested-l1-version" + }, + { + "id": "simple/nested-level-2", + "version": "nested-l2-version" + } + ], + "detection_order": [ + { + "buildpacks": [ + { + "id": "simple/nested-level-1", + "buildpacks": [ + { + "id": "simple/nested-level-2", + "version": "nested-l2-version", + "buildpacks": [ + { + "id": "simple/layers", + "version": "simple-layers-version" + } + ] + } + ] + }, + { + "id": "read/env", + "version": "read-env-version", + "optional": true + } + ] + } + ] + }, + "local_info": { + "created_by": { + "name": "Pack CLI", + "version": "{{.pack_version}}" + }, + "stack": { + "id": "pack.test.stack", + "mixins": [ + "mixinA", + "netcat", + "mixin3", + "build:mixinTwo" + ] + }, + "lifecycle": { + "version": "{{.lifecycle_version}}", + "buildpack_apis": { + "deprecated": {{.deprecated_buildpack_apis}}, + "supported": {{.supported_buildpack_apis}} + }, + "platform_apis": { + "deprecated": {{.deprecated_platform_apis}}, + "supported": {{.supported_platform_apis}} + } + }, + "run_images": [ + { + "name": "some-registry.com/pack-test/run1", + "user_configured": true + }, + { + "name": "pack-test/run" + }, + { + "name": "{{.run_image_mirror}}" + } + ], + "buildpacks": [ + { + "id": "noop.buildpack", + "version": "noop.buildpack.later-version", + "homepage": "http://geocities.com/cool-bp" + }, + { + "id": "noop.buildpack", + "version": "noop.buildpack.version" + }, + { + "id": "read/env", + "version": "read-env-version" + }, + { + "id": "simple/layers", + "version": "simple-layers-version" + }, + { + "id": "simple/nested-level-1", + "version": "nested-l1-version" + }, + { + "id": "simple/nested-level-2", + "version": "nested-l2-version" + } + ], + "detection_order": [ + { + "buildpacks": [ + { + "id": "simple/nested-level-1", + "buildpacks": [ + { + "id": "simple/nested-level-2", + "version": "nested-l2-version", + "buildpacks": [ + { + "id": "simple/layers", + "version": "simple-layers-version" + } + ] + } + ] + }, + { + "id": "read/env", + "version": "read-env-version", + "optional": true + } + ] + } + ] + } +} diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_toml.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_toml.txt new file mode 100644 index 000000000..9f7064b02 --- /dev/null +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_toml.txt @@ -0,0 +1,151 @@ +builder_name = "{{.builder_name}}" +trusted = false +default = false + +[remote_info] + + [remote_info.created_by] + Name = "Pack CLI" + Version = "{{.pack_version}}" + + [remote_info.stack] + id = "pack.test.stack" + mixins = ["mixinA", "netcat", "mixin3", "build:mixinTwo"] + + [remote_info.lifecycle] + version = "{{.lifecycle_version}}" + + [remote_info.lifecycle.buildpack_apis] + deprecated = {{.deprecated_buildpack_apis}} + supported = {{.supported_buildpack_apis}} + + [remote_info.lifecycle.platform_apis] + deprecated = {{.deprecated_platform_apis}} + supported = {{.supported_platform_apis}} + + [[remote_info.run_images]] + name = "some-registry.com/pack-test/run1" + user_configured = true + + [[remote_info.run_images]] + name = "pack-test/run" + + [[remote_info.run_images]] + name = "{{.run_image_mirror}}" + + [[remote_info.buildpacks]] + id = "noop.buildpack" + version = "noop.buildpack.later-version" + homepage = "http://geocities.com/cool-bp" + + [[remote_info.buildpacks]] + id = "noop.buildpack" + version = "noop.buildpack.version" + + [[remote_info.buildpacks]] + id = "read/env" + version = "read-env-version" + + [[remote_info.buildpacks]] + id = "simple/layers" + version = "simple-layers-version" + + [[remote_info.buildpacks]] + id = "simple/nested-level-1" + version = "nested-l1-version" + + [[remote_info.buildpacks]] + id = "simple/nested-level-2" + version = "nested-l2-version" + + [[remote_info.detection_order]] + + [[remote_info.detection_order.buildpacks]] + id = "simple/nested-level-1" + + [[remote_info.detection_order.buildpacks.buildpacks]] + id = "simple/nested-level-2" + version = "nested-l2-version" + + [[remote_info.detection_order.buildpacks.buildpacks.buildpacks]] + id = "simple/layers" + version = "simple-layers-version" + + [[remote_info.detection_order.buildpacks]] + id = "read/env" + version = "read-env-version" + optional = true + +[local_info] + + [local_info.created_by] + Name = "Pack CLI" + Version = "{{.pack_version}}" + + [local_info.stack] + id = "pack.test.stack" + mixins = ["mixinA", "netcat", "mixin3", "build:mixinTwo"] + + [local_info.lifecycle] + version = "{{.lifecycle_version}}" + + [local_info.lifecycle.buildpack_apis] + deprecated = {{.deprecated_buildpack_apis}} + supported = {{.supported_buildpack_apis}} + + [local_info.lifecycle.platform_apis] + deprecated = {{.deprecated_platform_apis}} + supported = {{.supported_platform_apis}} + + [[local_info.run_images]] + name = "some-registry.com/pack-test/run1" + user_configured = true + + [[local_info.run_images]] + name = "pack-test/run" + + [[local_info.run_images]] + name = "{{.run_image_mirror}}" + + [[local_info.buildpacks]] + id = "noop.buildpack" + version = "noop.buildpack.later-version" + homepage = "http://geocities.com/cool-bp" + + [[local_info.buildpacks]] + id = "noop.buildpack" + version = "noop.buildpack.version" + + [[local_info.buildpacks]] + id = "read/env" + version = "read-env-version" + + [[local_info.buildpacks]] + id = "simple/layers" + version = "simple-layers-version" + + [[local_info.buildpacks]] + id = "simple/nested-level-1" + version = "nested-l1-version" + + [[local_info.buildpacks]] + id = "simple/nested-level-2" + version = "nested-l2-version" + + [[local_info.detection_order]] + + [[local_info.detection_order.buildpacks]] + id = "simple/nested-level-1" + + [[local_info.detection_order.buildpacks.buildpacks]] + id = "simple/nested-level-2" + version = "nested-l2-version" + + [[local_info.detection_order.buildpacks.buildpacks.buildpacks]] + id = "simple/layers" + version = "simple-layers-version" + + [[local_info.detection_order.buildpacks]] + id = "read/env" + version = "read-env-version" + optional = true diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_yaml.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_yaml.txt new file mode 100644 index 000000000..45cb4f06e --- /dev/null +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output_yaml.txt @@ -0,0 +1,104 @@ +sharedbuilderinfo: + builder_name: {{.builder_name}} + trusted: false + default: false +remote_info: + created_by: + name: Pack CLI + version: {{.pack_version}} + stack: + id: pack.test.stack + mixins: + - mixinA + - netcat + - mixin3 + - build:mixinTwo + lifecycle: + version: {{.lifecycle_version}} + buildpack_apis: + deprecated: {{.deprecated_buildpack_apis}} + supported: {{.supported_buildpack_apis}} + platform_apis: + deprecated: {{.deprecated_platform_apis}} + supported: {{.supported_platform_apis}} + run_images: + - name: some-registry.com/pack-test/run1 + user_configured: true + - name: pack-test/run + - name: {{.run_image_mirror}} + buildpacks: + - id: noop.buildpack + version: noop.buildpack.later-version + homepage: http://geocities.com/cool-bp + - id: noop.buildpack + version: noop.buildpack.version + - id: read/env + version: read-env-version + - id: simple/layers + version: simple-layers-version + - id: simple/nested-level-1 + version: nested-l1-version + - id: simple/nested-level-2 + version: nested-l2-version + detection_order: + - buildpacks: + - id: simple/nested-level-1 + buildpacks: + - id: simple/nested-level-2 + version: nested-l2-version + buildpacks: + - id: simple/layers + version: simple-layers-version + - id: read/env + version: read-env-version + optional: true +local_info: + created_by: + name: Pack CLI + version: {{.pack_version}} + stack: + id: pack.test.stack + mixins: + - mixinA + - netcat + - mixin3 + - build:mixinTwo + lifecycle: + version: {{.lifecycle_version}} + buildpack_apis: + deprecated: {{.deprecated_buildpack_apis}} + supported: {{.supported_buildpack_apis}} + platform_apis: + deprecated: {{.deprecated_platform_apis}} + supported: {{.supported_platform_apis}} + run_images: + - name: some-registry.com/pack-test/run1 + user_configured: true + - name: pack-test/run + - name: {{.run_image_mirror}} + buildpacks: + - id: noop.buildpack + version: noop.buildpack.later-version + homepage: http://geocities.com/cool-bp + - id: noop.buildpack + version: noop.buildpack.version + - id: read/env + version: read-env-version + - id: simple/layers + version: simple-layers-version + - id: simple/nested-level-1 + version: nested-l1-version + - id: simple/nested-level-2 + version: nested-l2-version + detection_order: + - buildpacks: + - id: simple/nested-level-1 + buildpacks: + - id: simple/nested-level-2 + version: nested-l2-version + buildpacks: + - id: simple/layers + version: simple-layers-version + - id: read/env + version: read-env-version + optional: true diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt new file mode 100644 index 000000000..fefa49715 --- /dev/null +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt @@ -0,0 +1,85 @@ +Inspecting builder: '{{.builder_name}}' + +REMOTE: + +Created By: + Name: Pack CLI + Version: {{.pack_version}} + +Trusted: {{.trusted}} + +Stack: + ID: pack.test.stack + Mixins: + mixinA + netcat + mixin3 + build:mixinTwo + +Lifecycle: + Version: {{.lifecycle_version}} + Buildpack APIs: + Deprecated: {{ .deprecated_buildpack_apis }} + Supported: {{ .supported_buildpack_apis }} + Platform APIs: + Deprecated: {{ .deprecated_platform_apis }} + Supported: {{ .supported_platform_apis }} + +Run Images: + some-registry.com/pack-test/run1 (user-configured) + pack-test/run + {{.run_image_mirror}} + +Buildpacks: + ID VERSION HOMEPAGE + noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack noop.buildpack.version - + read/env read-env-version - + simple/layers simple-layers-version - + +Detection Order: + └ Group #1: + ├ simple/layers + └ read/env@read-env-version (optional) + +LOCAL: + +Created By: + Name: Pack CLI + Version: {{.pack_version}} + +Trusted: {{.trusted}} + +Stack: + ID: pack.test.stack + Mixins: + mixinA + netcat + mixin3 + build:mixinTwo + +Lifecycle: + Version: {{.lifecycle_version}} + Buildpack APIs: + Deprecated: {{ .deprecated_buildpack_apis }} + Supported: {{ .supported_buildpack_apis }} + Platform APIs: + Deprecated: {{ .deprecated_platform_apis }} + Supported: {{ .supported_platform_apis }} + +Run Images: + some-registry.com/pack-test/run1 (user-configured) + pack-test/run + {{.run_image_mirror}} + +Buildpacks: + ID VERSION HOMEPAGE + noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack noop.buildpack.version - + read/env read-env-version - + simple/layers simple-layers-version - + +Detection Order: + └ Group #1: + ├ simple/layers + └ read/env@read-env-version (optional) From ca4764dad6635d8a5ebbb6ce9188114576bb0d12 Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Wed, 31 Mar 2021 00:34:37 +0100 Subject: [PATCH 5/7] Fix acceptance tests for builders created by previous pack versions Signed-off-by: Sambhav Kothari --- acceptance/acceptance_test.go | 14 +++++----- acceptance/invoke/pack.go | 11 ++++++-- acceptance/invoke/pack_fixtures.go | 1 - ...t_0.18.0_builder_nested_depth_2_output.txt | 28 +++++++++---------- .../inspect_0.18.0_builder_nested_output.txt | 28 +++++++++---------- .../inspect_0.18.0_builder_output.txt | 20 ++++++------- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 681167f31..3100eb293 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -1993,7 +1993,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_nested_output.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_nested_output.txt", map[string]interface{}{ "builder_name": builderName, @@ -2031,7 +2031,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_nested_depth_2_output.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_nested_depth_2_output.txt", map[string]interface{}{ "builder_name": builderName, @@ -2072,7 +2072,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_nested_output_toml.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_nested_output_toml.txt", map[string]interface{}{ "builder_name": builderName, @@ -2109,7 +2109,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_nested_output_yaml.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_nested_output_yaml.txt", map[string]interface{}{ "builder_name": builderName, @@ -2150,7 +2150,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_nested_output_json.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_nested_output_json.txt", map[string]interface{}{ "builder_name": builderName, @@ -2189,7 +2189,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_output.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_output.txt", map[string]interface{}{ "builder_name": builderName, @@ -2229,7 +2229,7 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] expectedOutput := pack.FixtureManager().TemplateVersionedFixture( "inspect_%s_builder_output.txt", - createBuilderPack.Version(), + createBuilderPack.SanitizedVersion(), "inspect_builder_output.txt", map[string]interface{}{ "builder_name": builderName, diff --git a/acceptance/invoke/pack.go b/acceptance/invoke/pack.go index d69f465c7..08c22a9bd 100644 --- a/acceptance/invoke/pack.go +++ b/acceptance/invoke/pack.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strings" "sync" "testing" @@ -167,10 +168,14 @@ func (c *InterruptCmd) Wait() error { func (i *PackInvoker) Version() string { i.testObject.Helper() + return strings.TrimSpace(i.RunSuccessfully("version")) +} - output := i.RunSuccessfully("version") - - return strings.TrimSpace(output) +func (i *PackInvoker) SanitizedVersion() string { + i.testObject.Helper() + // Sanitizing any git commit sha and build number from the version output + re := regexp.MustCompile(`\d+\.\d+\.\d+`) + return re.FindString(strings.TrimSpace(i.RunSuccessfully("version"))) } func (i *PackInvoker) EnableExperimental() { diff --git a/acceptance/invoke/pack_fixtures.go b/acceptance/invoke/pack_fixtures.go index 65d7ea44d..00dc458f7 100644 --- a/acceptance/invoke/pack_fixtures.go +++ b/acceptance/invoke/pack_fixtures.go @@ -68,7 +68,6 @@ func (m PackFixtureManager) TemplateVersionedFixture( templateData map[string]interface{}, ) string { m.testObject.Helper() - outputTemplate, err := ioutil.ReadFile(m.VersionedFixtureOrFallbackLocation(versionedPattern, version, fallback)) m.assert.Nil(err) diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt index 91c7ab5ea..298381171 100644 --- a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_depth_2_output.txt @@ -31,13 +31,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack - noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack - noop.buildpack.version - + read/env - read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: @@ -77,13 +77,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack - noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack - noop.buildpack.version - + read/env - read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt index 704e14cda..7d8985606 100644 --- a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_nested_output.txt @@ -31,13 +31,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack - noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack - noop.buildpack.version - + read/env - read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: @@ -79,13 +79,13 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - - simple/nested-level-1 nested-l1-version - - simple/nested-level-2 nested-l2-version - + ID NAME VERSION HOMEPAGE + noop.buildpack - noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack - noop.buildpack.version - + read/env - read-env-version - + simple/layers - simple-layers-version - + simple/nested-level-1 - nested-l1-version - + simple/nested-level-2 - nested-l2-version - Detection Order: └ Group #1: diff --git a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt index fefa49715..7590eaee9 100644 --- a/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt +++ b/acceptance/testdata/pack_fixtures/inspect_0.18.0_builder_output.txt @@ -31,11 +31,11 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - + ID NAME VERSION HOMEPAGE + noop.buildpack - noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack - noop.buildpack.version - + read/env - read-env-version - + simple/layers - simple-layers-version - Detection Order: └ Group #1: @@ -73,11 +73,11 @@ Run Images: {{.run_image_mirror}} Buildpacks: - ID VERSION HOMEPAGE - noop.buildpack noop.buildpack.later-version http://geocities.com/cool-bp - noop.buildpack noop.buildpack.version - - read/env read-env-version - - simple/layers simple-layers-version - + ID NAME VERSION HOMEPAGE + noop.buildpack - noop.buildpack.later-version http://geocities.com/cool-bp + noop.buildpack - noop.buildpack.version - + read/env - read-env-version - + simple/layers - simple-layers-version - Detection Order: └ Group #1: From 07f42bbae36c7a7f31bb587d55d06319ea5e238e Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Thu, 1 Apr 2021 12:35:21 +0100 Subject: [PATCH 6/7] Add unit tests for AddBuildpackToLayersMD Signed-off-by: Sambhav Kothari --- internal/dist/dist_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/dist/dist_test.go b/internal/dist/dist_test.go index 5edba3347..1283f5e95 100644 --- a/internal/dist/dist_test.go +++ b/internal/dist/dist_test.go @@ -86,5 +86,18 @@ func testDist(t *testing.T, when spec.G, it spec.S) { }) }) }) + when("Add", func() { + when("a new buildpack is added", func() { + it("succeeds", func() { + layers := dist.BuildpackLayers{} + apiVersion, _ := api.NewVersion("0.0") + descriptor := dist.BuildpackDescriptor{API: apiVersion, Info: dist.BuildpackInfo{ID: "test", Name: "test", Version: "1.0"}} + dist.AddBuildpackToLayersMD(layers, descriptor, "") + layerInfo, ok := layers.Get(descriptor.Info.ID, descriptor.Info.Version) + h.AssertEq(t, ok, true) + h.AssertEq(t, layerInfo.Name, descriptor.Info.Name) + }) + }) + }) }) } From 66af9bf68992ebd8e2b301f6d73e1aeeda2f1dbb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Apr 2021 08:40:12 +0000 Subject: [PATCH 7/7] Bump github.com/pelletier/go-toml from 1.8.1 to 1.9.0 Bumps [github.com/pelletier/go-toml](https://github.com/pelletier/go-toml) from 1.8.1 to 1.9.0. - [Release notes](https://github.com/pelletier/go-toml/releases) - [Commits](https://github.com/pelletier/go-toml/compare/v1.8.1...v1.9.0) Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8054bb6c5..6df6d1cb5 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/opencontainers/image-spec v1.0.1 github.com/opencontainers/runc v0.1.1 // indirect github.com/opencontainers/selinux v1.6.0 // indirect - github.com/pelletier/go-toml v1.8.1 + github.com/pelletier/go-toml v1.9.0 github.com/pkg/errors v0.9.1 github.com/sabhiram/go-gitignore v0.0.0-20201211074657-223ce5d391b0 github.com/sclevine/spec v1.4.0 diff --git a/go.sum b/go.sum index 49ba6cac6..5649628f0 100644 --- a/go.sum +++ b/go.sum @@ -449,8 +449,8 @@ github.com/opencontainers/selinux v1.6.0/go.mod h1:VVGKuOLlE7v4PJyT6h7mNWvq1rzqi github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= -github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= +github.com/pelletier/go-toml v1.9.0 h1:NOd0BRdOKpPf0SxkL3HxSQOG7rNh+4kl6PHcBPFs7Q0= +github.com/pelletier/go-toml v1.9.0/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=