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 global pull policy configuration command #1008

Merged
merged 8 commits into from
Jan 11, 2021

Conversation

nkuik
Copy link
Contributor

@nkuik nkuik commented Jan 6, 2021

Summary

Adds the following commands to set, list, or unset a global container pull policy:

  • pack config pull-policy (lists the configured policy--default is "always")
  • pack config pull-policy <if-not-present | always | never> (set the default pull-policy)
  • pack config pull-policy --unset (unset a configured global policy and reset to default--"always)

The changes still allow --pull-policy to be provided as an option in the command line. If --pull-policy is provided, it takes precedence to any globally configured pull-policy

Output

Before

These commands did not exist, so I can't think of any output to show.

After

pack config -h

$  out/pack config -h
Interact with Pack's configuration

Usage:
  pack config [command]

Available Commands:
  default-builder   List, set and unset the default builder used by other commands
  experimental      Print and set the current 'experimental' value from the config
  trusted-builders  Interact with trusted builders
  run-image-mirrors Interact with run image mirrors
  pull-policy       List, set and unset the global pull policy used by other commands
  registries        (experimental) Interact with registries

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.

pack config pull-policy -h

$ out/pack config pull-policy -h
A Buildpack Registry is a (still experimental) place to publish, store, and discover buildpacks.

You can use this command to list, set, and unset the default pull policy that will be used when working with containers:
* To list your pull policy, run `pack config pull-policy`.
* To set your pull policy, run `pack config pull-policy <pull-policy>`.
* To unset your pull policy, run `pack config pull-policy --unset`.
Unsetting the pull policy will reset the policy to the default, which is always

Usage:
  pack config pull-policy <if-not-present | always | never> [flags]

Aliases:
  pull-policy, pull-policy

Flags:
  -h, --help    Help for 'pull-policy'
  -u, --unset   Unset pull policy, and set it back to the default pull-policy, which is always

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

pack config pull-policy

When no other policy has been configured.

$ out/pack config pull-policy
The current pull policy is always

pack config pull-policy never

When no other policy has been configured.

$ out/pack config pull-policy never
Successfully set never as the pull policy

pack config pull-policy if-not-present

When no other policy has been configured.

$ out/pack config pull-policy if-not-present
Successfully set if-not-present as the pull policy

pack config pull-policy always

When no other policy has been configured.

$ out/pack config pull-policy always
Successfully set always as the pull policy

pack config pull-policy never

When never was already the configured policy.

$ out/pack config pull-policy always
Pull policy is already set to never

pack config pull-policy invalid-policy

When never was already the configured policy.

$ out/pack config pull-policy invalid-policy
ERROR: invalid pull policy invalid-policy

pack config pull-policy --unset

$ out/pack config pull-policy --unset
Successfully unset pull policy never
Pull policy has been set to always

pack config pull-policy never --unset (invalid command)

$ out/pack config pull-policy never --unset
ERROR: pull policy and --unset cannot be specified simultaneously

Documentation

Related

Resolves #991

@nkuik nkuik force-pushed the 991-global-pull-policy-configuration branch from 7488370 to 677b1e9 Compare January 6, 2021 16:43
@codecov
Copy link

codecov bot commented Jan 6, 2021

Codecov Report

Merging #1008 (5f84486) into main (55ae0ac) will increase coverage by 0.15%.
The diff coverage is 94.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1008      +/-   ##
==========================================
+ Coverage   79.47%   79.61%   +0.15%     
==========================================
  Files         129      130       +1     
  Lines        5716     5777      +61     
==========================================
+ Hits         4542     4599      +57     
- Misses        755      757       +2     
- Partials      419      421       +2     
Flag Coverage Δ
os_linux 79.56% <94.60%> (+0.15%) ⬆️
os_macos 76.97% <94.60%> (+0.18%) ⬆️
os_windows 100.00% <ø> (ø)
unit 79.61% <94.60%> (+0.15%) ⬆️

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

}

pullPolicy, err := pubcfg.ParsePullPolicy(cfg.PullPolicy)
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't necessarily need to check for error here, as the pull policy has been set to one (line 34 this file) that we know is valid. But there could easily be more succinct ways to do this.

Nathan Kuik added 5 commits January 7, 2021 08:31
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
@nkuik nkuik changed the title 991 global pull policy configuration Global pull policy configuration Jan 7, 2021
@nkuik nkuik force-pushed the 991-global-pull-policy-configuration branch from 677b1e9 to 6c780b2 Compare January 7, 2021 07:43
@nkuik nkuik marked this pull request as ready for review January 7, 2021 07:54
@nkuik nkuik requested a review from a team as a code owner January 7, 2021 07:54
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

Overall, this is phenomenal, and really helpful. I had a bunch of nit suggestions, mostly stylistic, but this is super helpful.

One addition location to make this change is in internal/commands/package_buildpack.go
Also, one additional location that I'd add a test in is in internal/commands/confg_test.go, specifically here, just to provide assurance that the command is displayed as we would expect.

Thanks

internal/commands/buildpack.go Outdated Show resolved Hide resolved
Comment on lines 54 to 55
var err error
pullPolicy, err := pubcfg.ParsePullPolicy(flags.Policy)
var pullPolicy pubcfg.PullPolicy
Copy link
Member

Choose a reason for hiding this comment

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

nit: In this particular case, you should be able to remove both of these lines, and just do:

pullPolicy, err := pubcfg.ParsePullPolicy(stringPolicy)

below

internal/commands/buildpack_package.go Outdated Show resolved Hide resolved
internal/commands/config.go Show resolved Hide resolved
internal/commands/config_pull_policy.go Show resolved Hide resolved
internal/commands/config_pull_policy.go Show resolved Hide resolved
internal/commands/config_pull_policy.go Outdated Show resolved Hide resolved
internal/commands/config_pull_policy_test.go Show resolved Hide resolved
internal/commands/config_pull_policy_test.go Outdated Show resolved Hide resolved
internal/commands/config_pull_policy_test.go Outdated Show resolved Hide resolved
@nkuik nkuik force-pushed the 991-global-pull-policy-configuration branch from aa61e55 to 14fb1a1 Compare January 8, 2021 08:09
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
@nkuik nkuik force-pushed the 991-global-pull-policy-configuration branch from 14fb1a1 to 82d792e Compare January 8, 2021 08:10
@nkuik nkuik requested a review from dfreilich January 8, 2021 09:37
@dfreilich dfreilich added this to the 0.17.0 milestone Jan 8, 2021
@dfreilich dfreilich added the type/enhancement Issue that requests a new feature or improvement. label Jan 8, 2021
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

This is super close. Just a few more small changes I'd like to see, if you have the time.

internal/commands/config.go Show resolved Hide resolved
Args: cobra.MaximumNArgs(1),
Short: "List, set and unset the global pull policy used by other commands",
Aliases: []string{"pull-policy"},
Long: bpRegistryExplanation + "\n\nYou can use this command to list, set, and unset the default pull policy that will be used when working with containers:\n" +
Copy link
Member

Choose a reason for hiding this comment

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

This is still relevant, bpRegistryExplanataion isn't relevant for understanding pull-policies

internal/commands/config_pull_policy.go Outdated Show resolved Hide resolved
internal/commands/config_pull_policy.go Outdated Show resolved Hide resolved
internal/commands/config_pull_policy_test.go Outdated Show resolved Hide resolved
internal/commands/config_pull_policy.go Outdated Show resolved Hide resolved
Signed-off-by: Nathan Kuik <nkuik@toogoodtogo.com>
@nkuik nkuik force-pushed the 991-global-pull-policy-configuration branch from 14fb55b to c62a8f3 Compare January 8, 2021 13:30
@nkuik nkuik requested a review from dfreilich January 8, 2021 13:44
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

fantastic

This should go out in the release (0.17.0), not the immediately upcoming release (0.16.0), to give us a bit more time to test it and make sure no 🐛 are slipping by us. Thanks again for the help!

@dfreilich dfreilich changed the title Global pull policy configuration Add global pull policy configuration command Jan 11, 2021
@dfreilich dfreilich merged commit 99ada47 into buildpacks:main Jan 11, 2021
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.

Allow global configuration of default pull-policy
2 participants