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

hooks: include plugin name in hook data #5030

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

laurazard
Copy link
Collaborator

@laurazard laurazard commented Apr 19, 2024

- What I did

Before, for plugin commands, only the plugin name (such as buildx) would be included in RootCmd when passed to the hook plugin, which isn't enough information for a plugin to decide whether to execute a hook or not since plugins implement multiple varied commands (buildx build, buildx prune, etc.).

- How I did it

This commit changes the hook logic to account for this situation, so that both the plugin name and base command will get passed (separated by a SPACE, such as buildx prune).

This logic works for aliased commands too, so whether docker build ... or docker buildx build is executed (unless Buildx is disabled) the hook will be invoked with buildx build.

- A picture of a cute animal (not mandatory but encouraged)

image

@laurazard laurazard added this to the 26.1.0 milestone Apr 19, 2024
@laurazard laurazard self-assigned this Apr 19, 2024
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2024

Codecov Report

Merging #5030 (9d8320d) into master (b982833) will increase coverage by 0.05%.
Report is 9 commits behind head on master.
The diff coverage is 45.45%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5030      +/-   ##
==========================================
+ Coverage   61.05%   61.10%   +0.05%     
==========================================
  Files         295      295              
  Lines       20647    20656       +9     
==========================================
+ Hits        12605    12621      +16     
+ Misses       7146     7138       -8     
- Partials      896      897       +1     

@thaJeztah
Copy link
Member

I yet have to dive into the changes in this PR, but wondering if there's cases where "global" flags could cause issues, e.g. docker buildx --builder somebuilder build etc. (I think we already handle global flags like docker -H .. and docker --debug .. etc?)

@vvoland
Copy link
Collaborator

vvoland commented Apr 22, 2024

It operates on the args already processed by cobra, so it also works fine with global flags.

Before, for plugin commands, only the plugin name (such as `buildx`)
would be both included as `RootCmd` when passed to the hook plugin,
which isn't enough information for a plugin to decide whether to execute
a hook or not since plugins implement multiple varied commands (`buildx
build`, `buildx prune`, etc.).

This commit changes the hook logic to account for this situation, so
that the the entire configured hook is passed, i.e., if a user has a
hook configured for `buildx imagetools inspect` and the command
`docker buildx imagetools inspect alpine` is called, then the plugin
hooks will be passed `buildx imagetools inspect`.

This logic works for aliased commands too, so whether `docker build ...`
or `docker buildx build` is executed (unless Buildx is disabled) the
hook will be invoked with `buildx build`.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>

hooks: include full match when invoking plugins

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
Copy link
Collaborator

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

LGTM

@vvoland vvoland merged commit d8fc76e into docker:master Apr 22, 2024
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants