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

Implement register-buildpack for github type #716

Merged
merged 4 commits into from Jul 13, 2020
Merged

Conversation

elbandito
Copy link
Member

@elbandito elbandito commented Jun 29, 2020

Summary

**NOTE: In the RFC, there is mention of 2 types to support: github and git. This PR is ONLY for supporting github.

This PR adds functionality to the pack CLI to support registering a buildpack with github. A new command (register-buildpack) was introduced (hidden behind the experimental flag)

Register the buildpack to a registry

Usage:
  pack register-buildpack <image> [flags]

Flags:
  -R, --buildpack-registry string   Buildpack Registry reference
  -h, --help                        Help for 'register-buildpack'

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

By default, if no configuration values are defined in the config.toml file, buildpacks will be registered against:
https://github.com/buildpacks/registry. In addition, user can specify their own registries. For example:

[[registries]]
name="elbandito"
type="github"
url="https://github.com/elbandito/buildpack-registry"

[[registries]]
name="joe"
type="github"
url="https://github.com/jkutner/buildpack-registry/"

When there are multiple registries, the user can specify a specific registry via buildpack-registry, -R flag.

For example:
pack register-buildpack <buildpack/image> -R elbandito

For more details:
https://github.com/buildpacks/rfcs/blob/main/text/0022-client-side-buildpack-registry.md
buildpacks/rfcs#75

Documentation

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

Related

buildpacks/rfcs#75

@elbandito elbandito force-pushed the register-buildpack branch 3 times, most recently from 2740165 to 7b4853b Compare June 30, 2020 23:40
@elbandito elbandito marked this pull request as ready for review June 30, 2020 23:41
@elbandito elbandito requested a review from a team as a code owner June 30, 2020 23:41
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, it's definitely looking good. Some broader suggestions:

  • This should probably have an acceptance test as well, given that it's a new command
  • There are quite a few sad paths (particularly in register_buildpack) that aren't tested, and should be simple to exercise
  • It would be nice if more of the errors were wrapped errors.Wrap to provide a bit more context to users in sad paths.
  • I assume one of the maintainers will need to create https://github.com/buildpacks/registry for this to work/test locally, which may be helpful.

internal/commands/register_buildpack_test.go Show resolved Hide resolved
return nil
}),
}
cmd.Flags().StringVarP(&flags.BuildpackRegistry, "buildpack-registry", "R", "", "Buildpack Registry name")
Copy link
Member

Choose a reason for hiding this comment

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

Can we use r instead of R? Seems like we only use uppercase shortened flags by pack build, when we have no other choice

Copy link
Member Author

Choose a reason for hiding this comment

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

@dfreilich I'm in support of following conventions, so happy to make the change if that is the case. 👍

Copy link
Member

Choose a reason for hiding this comment

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

@dfreilich I don't think that's the ongoing rule. At least during the initial registry PR I proposed capital R because:

A --buildpack-registry feels like it's of the same importance as --builder.

#540 (review)

Copy link
Member

Choose a reason for hiding this comment

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

I understand the importance, but as a cli user, I would find it annoying to capitalize something (a whole extra button press) which is supposed to make it easier; I find capitalized arguments to be more annoying to remember/use.

I thought the use of -B by pack build was more because we needed some way of distinguishing --buildpack from --builder, rather than to underscore the importance of the argument; and if so, we should follow that pattern in other commands (like create-builder, which only has lower case shortened ones)

Copy link
Member

Choose a reason for hiding this comment

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

@dfreilich I see your point. at the very minimum I would think we can agree that both build and register-buildpack should both use the same flag casing.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jromero @dfreilich so what's the take away here? Do we want to change -R to be -r?

Copy link
Member

Choose a reason for hiding this comment

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

I'd still vote for -r over -R

internal/commands/register_buildpack.go Outdated Show resolved Hide resolved
internal/config/config_test.go Outdated Show resolved Hide resolved
register_buildpack.go Outdated Show resolved Hide resolved
register_buildpack.go Outdated Show resolved Hide resolved
register_buildpack_test.go Outdated Show resolved Hide resolved
register_buildpack_test.go Outdated Show resolved Hide resolved
@elbandito elbandito force-pushed the register-buildpack branch 2 times, most recently from 484590a to d1a0ce4 Compare July 1, 2020 17:44
@elbandito elbandito closed this Jul 1, 2020
@elbandito elbandito reopened this Jul 1, 2020
@elbandito
Copy link
Member Author

Overall, it's definitely looking good. Some broader suggestions:

  • This should probably have an acceptance test as well, given that it's a new command
  • There are quite a few sad paths (particularly in register_buildpack) that aren't tested, and should be simple to exercise
  • It would be nice if more of the errors were wrapped errors.Wrap to provide a bit more context to users in sad paths.
  • I assume one of the maintainers will need to create https://github.com/buildpacks/registry for this to work/test locally, which may be helpful.

@dfreilich Thanks again for the feedback!

As far as acceptance tests are concerned, I don't think it should be considered a blocker. Most of the logic for this command is centered on the ability to open a github issue via a browser. There's some parsing that takes place from the config.toml file, but we should be able to cover most of this surface area with unit tests. I did add more tests, but if there is anything else that I'm missing, please let me know. Perhaps later on we can look at doing something fancy with a headless browser to test the ability to open a new github issue.

@elbandito elbandito force-pushed the register-buildpack branch 2 times, most recently from f24e942 to d639776 Compare July 2, 2020 21:40
Co-authored-by: Joe Kutner <jpkutner@gmail.com>

Signed-off-by: Travis Longoria <longoria.public@gmail.com>
@codecov
Copy link

codecov bot commented Jul 2, 2020

Codecov Report

Merging #716 into main will increase coverage by 1.01%.
The diff coverage is 82.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #716      +/-   ##
==========================================
+ Coverage   72.51%   73.52%   +1.01%     
==========================================
  Files          67       75       +8     
  Lines        4896     5135     +239     
==========================================
+ Hits         3550     3775     +225     
- Misses       1023     1043      +20     
+ Partials      323      317       -6     
Flag Coverage Δ
#os_linux 76.02% <83.74%> (+0.88%) ⬆️
#os_macos 71.91% <71.96%> (+0.63%) ⬆️
#os_windows 71.83% <72.16%> (+0.73%) ⬆️
#unit 73.52% <82.14%> (+1.01%) ⬆️

@elbandito
Copy link
Member Author

@jromero and @dfreilich are there any more action items on this PR that you'd like resolved?

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 LGTM!

register_buildpack_test.go Outdated Show resolved Hide resolved
return nil
}),
}
cmd.Flags().StringVarP(&flags.BuildpackRegistry, "buildpack-registry", "R", "", "Buildpack Registry name")
Copy link
Member

Choose a reason for hiding this comment

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

I'd still vote for -r over -R

register_buildpack.go Outdated Show resolved Hide resolved
@elbandito
Copy link
Member Author

@jromero any final thoughts on this?

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 looking great! I've marked a few requested changes. Feel free to reach out via slack or other ways if something is unclear.

internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
register_buildpack.go Outdated Show resolved Hide resolved
register_buildpack_test.go Outdated Show resolved Hide resolved
register_buildpack.go Outdated Show resolved Hide resolved
register_buildpack_test.go Outdated Show resolved Hide resolved
cmd/cmd.go Outdated Show resolved Hide resolved
Signed-off-by: Travis Longoria <longoria.public@gmail.com>
@elbandito elbandito force-pushed the register-buildpack branch 4 times, most recently from aec5c7b to cd01c95 Compare July 10, 2020 01:09
Signed-off-by: Travis <longoria.public@gmail.com>
@jromero
Copy link
Member

jromero commented Jul 12, 2020

UA 1: TOML data format

$ ./out/pack register-buildpack cnbs/sample-package:hello-universe
Successfully registered cnbs/sample-package:hello-universe

Screen Shot 2020-07-12 at 3 30 40 PM

Feedback

It looks like the output doesn't match exactly what the RFC proposes. There is a missing field for the digest whereas this PR has the digest included as part of the addr. I can't really see the benefit of one vs the other. @jkutner do you have some insight about whether it's worth breaking out or not?

Error cases

$ ./out/pack register-buildpack cnbs/sample-package:no-exist
ERROR: image cnbs/sample-package:no-exist does not exist in registry: not found

$  ./out/pack register-buildpack gcr.io/cnbs/sample-package:no-exist
ERROR: connect to repo store 'gcr.io/cnbs/sample-package:no-exist': GET https://gcr.io/v2/token?scope=repository%3Acnbs%2Fsample-package%3Apull&service=gcr.io: UNKNOWN: Project 'project:cnbs' not found or deleted.

$ ./out/pack register-buildpack -r no-exist cnbs/sample-package:hello-universe
ERROR: registry no-exist is not defined in your config file

@elbandito
Copy link
Member Author

@jromero I spoke with @jkutner and the intention is to have the digest as part of the addr field.
https://github.com/buildpacks/rfcs/blob/main/text/0032-update-json-cnb-registry.md

@jromero jromero added this to the 0.13.0 milestone Jul 13, 2020
@jromero jromero added experimental Issue or PR refers to an experimental feature. type/enhancement Issue that requests a new feature or improvement. status/user-accepted Pull Request that has passed user acceptance. labels Jul 13, 2020
@jromero
Copy link
Member

jromero commented Jul 13, 2020

@jromero I spoke with @jkutner and the intention is to have the digest as part of the addr field.
https://github.com/buildpacks/rfcs/blob/main/text/0032-update-json-cnb-registry.md

Sounds good! ✨ Approved! ✨

@jromero jromero merged commit 90e3412 into main Jul 13, 2020
@jromero jromero deleted the register-buildpack branch July 13, 2020 16:11
@jromero jromero changed the title Register buildpack Implement register-buildpack for github type Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental Issue or PR refers to an experimental feature. status/user-accepted Pull Request that has passed user acceptance. type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants