Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pack config default-builder subcommand #982

Merged
merged 2 commits into from
Jan 4, 2021
Merged

Conversation

dfreilich
Copy link
Member

Signed-off-by: David Freilich dfreilich@vmware.com

Summary

This command allows users to list, set, and unset a value for a default builder in the pack config, with the command having three forms:

  • pack config default-builder → lists the current default builder, or prints a clear message if there is none
  • pack config default-builder <some-builder> → After validating the builder exists, either locally or in a remote registry, it is added to the pack config, with a success message printed
  • pack config default-builder --unset → If there is a default builder configured, it will remove that from the config, and print a success message. If not, it will print a clear message, saying that there wasn't a builder set.

As part of that, I added a deprecation warning to the existing pack set-default-builder command. I also slightly changed the behavior, so that instead of running pack suggest-builder (which has some latency) if no builder is set or the builder set isn't a valid builder, we just recommend that users can run pack suggest-builder.

Additionally, as part of this PR, I configured the rebase command to use dependency injection for the pack config path, given that my testing setup had caused issues with it in the current format.

Output

After

$  out/pack set-default-builder
Warning: Command pack set-default-builder has been deprecated, please use pack config default-builder instead
Usage:
	pack set-default-builder <builder-name> [flags]
Suggested builders:
^C	Google:                gcr.io/buildpacks/builder:v1      Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, and Python
	Heroku:                heroku/buildpacks:18              heroku-18 base image with buildpacks for Ruby, Java, Node.js, Python, Golang, & PHP
	Paketo Buildpacks:     paketobuildpacks/builder:base     Ubuntu bionic base image with buildpacks for Java, NodeJS and Golang
	Paketo Buildpacks:     paketobuildpacks/builder:full     Ubuntu bionic base image with buildpacks for Java, .NET, NodeJS, Golang, PHP, HTTPD and NGINX
	Paketo Buildpacks:     paketobuildpacks/builder:tiny     Tiny base image (bionic build image, distroless run image) with buildpacks for Golang

Tip: Learn more about a specific builder with:
	pack inspect-builder <builder-image>
 $  out/pack config
Interact with Pack's configuration

Usage:
  pack config [command]

Available Commands:
  trusted-builders  Interact with trusted builders
  run-image-mirrors Interact with run image mirrors
  default-builder   List, set and unset the default builder used by other commands

Flags:
  -h, --help   Help for 'config'

Global Flags:
      --no-color     Disable color output
  -q, --quiet        Show less output
      --timestamps   Enable timestamps in output
  -v, --verbose      Show more output

Use "pack config [command] --help" for more information about a command.
$  out/pack config default-builder -h
List, set, and unset the default builder used by other commands.

* To list your default builder, run `pack config default-builder`.
* To set your default builder, run `pack config default-builder <builder-name>`.
* To unset your default builder, run `pack config default-builder --unset`.

For suggested builders, run `pack builder suggest`.

Usage:
  pack config default-builder [flags]

Examples:
pack config default-builder cnbs/sample-builder:bionic

Flags:
  -h, --help    Help for 'config default-builder'
  -u, --unset   Unset the current default builder

Global Flags:
      --no-color     Disable color output
  -q, --quiet        Show less output
      --timestamps   Enable timestamps in output
  -v, --verbose      Show more output
$  out/pack config default-builder
No default builder is set.

For suggested builders, run `pack builder suggest`.
$  out/pack config default-builder some/builder
ERROR: validating that builder some/builder exists: builder some/builder not found
$  out/pack config default-builder paketobuildpacks/builder:tiny
Builder paketobuildpacks/builder:tiny is now the default builder
$  out/pack config default-builder
The current default builder is paketobuildpacks/builder:tiny
$  out/pack config default-builder --unset
Successfully unset default builder
$  out/pack config default-builder
No default builder is set.

For suggested builders, run `pack builder suggest`.

Documentation

  • Should this change be documented?
    • Yes, see #___

Related

Resolves #924
Relates to #597

@dfreilich dfreilich requested a review from a team as a code owner December 9, 2020 13:10
@dfreilich dfreilich force-pushed the 924-default-builder branch 2 times, most recently from d3a9e07 to d39f16f Compare December 9, 2020 14:18
cmd := &cobra.Command{
Use: "config",
Short: "Interact with Pack's configuration",
RunE: nil,
}

cmd.AddCommand(trustedBuilder(logger, cfg, cfgPath))
cmd.AddCommand(ConfigTrustedBuilder(logger, cfg, cfgPath))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though not strictly necessary for this PR, I changed this to make it easier to test alone, and require fewer mocks created in the trustedBuilder tests.

h.AssertContains(t, output, command)
}
})
})

when("trusted-builders", func() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these tests to config_trusted_builder_test.go, which made more semantic sense than testing them here, where we only need to know that the appropriate commands show up.


tempPackHome, err = ioutil.TempDir("", "pack-home")
h.AssertNil(t, err)

packConfigPath = filepath.Join(tempPackHome, "config.toml")
cmd = commands.Report(logger, testVersion, packConfigPath)
cmd.SetArgs([]string{})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure to set args was causing issues with my local tests, so I added it to ensure that it passes, and took the opportunity to do dependency injection. I can revert that if requested, though.

@dfreilich dfreilich added this to the 0.16.0 milestone Dec 9, 2020
@dfreilich dfreilich added the type/enhancement Issue that requests a new feature or improvement. label Dec 9, 2020
@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #982 (e925edf) into main (06704f6) will decrease coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #982      +/-   ##
==========================================
- Coverage   79.20%   79.07%   -0.13%     
==========================================
  Files         128      126       -2     
  Lines        5581     5540      -41     
==========================================
- Hits         4420     4380      -40     
+ Misses        748      747       -1     
  Partials      413      413              
Flag Coverage Δ
os_linux 79.07% <100.00%> (-0.04%) ⬇️
os_macos 76.34% <100.00%> (-0.15%) ⬇️
os_windows 100.00% <ø> (ø)
unit 79.07% <100.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@dfreilich dfreilich changed the title Add default-builder command to config subcommand Add pack config default-builder subcommand Dec 9, 2020
* This command allows users to list, set, and unset a value for a default builder in the pack config.

Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
@dfreilich dfreilich merged commit 6033196 into main Jan 4, 2021
@dfreilich dfreilich deleted the 924-default-builder branch January 4, 2021 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pack config default-builder subcommands
1 participant