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 pull-policy flag to build/create-builder/package-buildpack/rebase commands #773

Merged
merged 12 commits into from
Aug 11, 2020

Conversation

dfreilich
Copy link
Member

@dfreilich dfreilich commented Aug 4, 2020

Summary

This deprecates the --no-pull flag, in favor of --pull-policy, which as three options at the moment:

  • always → Always pulls the images necessary (the default behavior of pack)
  • never → Never pulls the images necessary (equivalent to --no-pull)
  • if-not-present → Pulls the image only if it is not present

It also adds the possibility for future policies to be added, by centralizing the PullPolicys.

Output

$ pack build

Before

Screen Shot 2020-08-05 at 9 06 42 AM

After

Screen Shot 2020-08-05 at 9 12 23 AM

$ pack create-builder

Before

Screen Shot 2020-08-05 at 9 02 12 AM

After

Screen Shot 2020-08-05 at 9 04 40 AM

$ pack package-buildpack

Before

image

After

image

$ pack rebase

Before

Screen Shot 2020-08-05 at 9 20 24 AM

After

image

Documentation

  • Should this change be documented?
    • Yes, and it will be automatically through the generated pack documentation

Related

Resolves #686
Implements buildpacks/rfcs#80

config/pull_policy.go Outdated Show resolved Hide resolved
@dfreilich dfreilich marked this pull request as ready for review August 4, 2020 23:39
@dfreilich dfreilich requested a review from a team as a code owner August 4, 2020 23:39
@codecov
Copy link

codecov bot commented Aug 4, 2020

Codecov Report

Merging #773 into main will increase coverage by 0.42%.
The diff coverage is 99.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #773      +/-   ##
==========================================
+ Coverage   75.59%   76.00%   +0.42%     
==========================================
  Files          77       78       +1     
  Lines        5197     5290      +93     
==========================================
+ Hits         3928     4020      +92     
- Misses        972      973       +1     
  Partials      297      297              
Flag Coverage Δ
#os_linux 78.33% <99.13%> (+0.34%) ⬆️
#os_macos 74.23% <91.23%> (+0.29%) ⬆️
#os_windows 74.32% <99.29%> (+0.45%) ⬆️
#unit 76.00% <99.29%> (+0.42%) ⬆️

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

@dfreilich dfreilich force-pushed the feature/686-pull-policy branch 2 times, most recently from f168121 to 461c201 Compare August 5, 2020 01:04
Copy link
Member Author

@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.

Should we add a --pull-policy flag to pack inspect-builder and pack inspect-image?

@@ -92,7 +94,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return errors.Wrapf(err, "invalid builder '%s'", opts.Builder)
}

rawBuilderImage, err := c.imageFetcher.Fetch(ctx, builderRef.Name(), true, !opts.NoPull)
rawBuilderImage, err := c.imageFetcher.Fetch(ctx, builderRef.Name(), true, opts.PullPolicy)
Copy link
Member Author

Choose a reason for hiding this comment

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

From a code readability standpoint, I appreciate the removal of double negatives (from here, and many other place throughout the code).


const (
// PullAlways images, even if they are present
PullAlways PullPolicy = iota
Copy link
Member Author

Choose a reason for hiding this comment

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

iota is useful for defining enums. For more on iotas, see https://github.com/golang/go/wiki/Iota or https://splice.com/blog/iota-elegant-constants-golang/

On the other hand, I also debated just defining these as strings, which would've obviated the need for a secondary String() method. If people would rather change it to a string type to make it simpler, I'm happy to do that.

config/pull_policy.go Outdated Show resolved Hide resolved
@@ -64,7 +66,7 @@ func (c *Client) validateRunImageConfig(ctx context.Context, opts CreateBuilderO
var runImages []imgutil.Image
for _, i := range append([]string{opts.Config.Stack.RunImage}, opts.Config.Stack.RunImageMirrors...) {
if !opts.Publish {
img, err := c.imageFetcher.Fetch(ctx, i, true, false)
img, err := c.imageFetcher.Fetch(ctx, i, true, opts.PullPolicy)
Copy link
Member Author

Choose a reason for hiding this comment

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

There were times where we had ignored the --no-pull option, which I think we shouldn't do, once we explicitly ask people what they want to do.

}

func validateBuildFlags(flags BuildFlags, logger logging.Logger, cfg config.Config, packClient PackClient) error {
func validateBuildFlags(flags *BuildFlags, cfg config.Config, packClient PackClient, logger logging.Logger) error {
Copy link
Member Author

Choose a reason for hiding this comment

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

From a readability perspective, I found it confusing for the logger to be so early in the parameters, so I took the liberty of moving it to the end of the parameter list

Copy link
Member

@jromero jromero 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 great! Nice clean implementation! 💯

@jromero jromero added the type/enhancement Issue that requests a new feature or improvement. label Aug 11, 2020
* Adds temporary method NewFetch, to allow for gradual refactoring in adding PullPolicy

Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
* Additionally, had to change some create_builder and build lines, due
  to changing a global method.

Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
* Ensure acceptance tests are passing

Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
This reverts commit 87e69ce.

Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
* Remove ParsePolicyFromBool method. It was used in refactoring over from no-pull to PullPolicy, but is no longer necessary
* Ensure fake image fetcher implements PullIfNotPresent
* Rename imports to pubcfg
* Add tests for unknown policy

Signed-off-by: David Freilich <dfreilich@vmware.com>
Signed-off-by: David Freilich <dfreilich@vmware.com>
@dfreilich dfreilich merged commit 7047f8a into main Aug 11, 2020
@dfreilich dfreilich deleted the feature/686-pull-policy branch August 11, 2020 14:50
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.

Support pack build --pull-if-needed
2 participants