-
Notifications
You must be signed in to change notification settings - Fork 323
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 and --no-cache options to Build/Publish Docker Image-Step #758
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR - looks like this is taking things in the right direction 👍
While I wholeheartedly approve of the addition of this capability, I do have some concerns - as-written, these code changes alter the publicly-visible API to the plugin, which could break existing pipeline code for some users, which would be a nasty shock for any existing users calling this build step (or action) from their builds.
Breaking people's builds, even for good reasons, is a Bad Thing, so we need to keep the publicly-visible method signatures (anything public
that isn't marked as @Restricted(NoExternalUse.class)
, which is a lot of code in here) as-is ... although we can deprecate existing ones and/or add new ones.
The recommended method of adding new parameters is to have @DataBoundSetter
setters that set the instance's fields. In fact,, ideally, we'd have an (nearly) empty constructor and lots of set methods (constructors should only take mandatory fields and there shouldn't be many of those) ... and if we're going to mess with constructors then we should daisy-chain them together instead of having repeated code.
So, what we need is:
- Replace the
final
keyword on each non-mandatory field with the comment/* almost final */
- Add a set method annotated with
@DataBoundSetter
for every field that isn't final anymore. - Add a constructor that only takes non-mandatory fields as arguments (that might well be "no arguments"!).
- Deprecate all existing constructors. Please add a Javadoc comment telling folks which constructor they should be using and to use the set methods.
- Chain existing constructors so they call the new mandatory-arg-only constructor
- Constructors that set non-mandatory fields should call the setter rather than setting the field directly.
- Feel free to add a constructor that takes all fields (and sets all of them) that's annotated as
@Restricted(NoExternalUse.class)
with a Javadoc comment saying it's for internal use only, and use that anytime code inside this plugin needs to construct a new instance (this way, if someone adds a new field, they'll see all the other places in the code that might be affected).
If any of what I've written isn't 100% clear I'd suggest you do this to the build step class (DockerBuilderPublisher) first and, once we're both happy with how that looks, then you can apply the same kind of changes to the other one.
If you prefer to do so, you could do the refactor in a separate PR and then re-base this one on that, or you could do it all inside this one; I don't mind which.
TL;DR: These two classes need to be refactored so that extending their functionality won't break people's builds before they can be safely extended.
src/main/java/com/nirima/jenkins/plugins/docker/action/DockerBuildImageAction.java
Outdated
Show resolved
Hide resolved
src/main/java/com/nirima/jenkins/plugins/docker/action/DockerBuildImageAction.java
Outdated
Show resolved
Hide resolved
src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java
Outdated
Show resolved
Hide resolved
src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java
Outdated
Show resolved
Hide resolved
...resources/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher/help-noCache.html
Outdated
Show resolved
Hide resolved
...in/resources/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher/help-pull.html
Outdated
Show resolved
Hide resolved
259bf29
to
ee26124
Compare
Adds the old constructors setters for new fields and an all-args-constructor for internal use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your Feedback!
I reverted the constructors back to their old signature, and added setters for the new fields. Since only DockerBuilderPublisher
used @DataBoundConstructor
, I also only added @DataBoundSetter
there. Is it enough or should I also add it to the setters in DockerBuildImageAction
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking much better - some (minor) cosmetic issues remaining.
src/main/java/com/nirima/jenkins/plugins/docker/action/DockerBuildImageAction.java
Outdated
Show resolved
Hide resolved
src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java
Show resolved
Hide resolved
...resources/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher/help-noCache.html
Outdated
Show resolved
Hide resolved
...in/resources/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher/help-pull.html
Outdated
Show resolved
Hide resolved
src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java
Outdated
Show resolved
Hide resolved
...main/resources/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher/config.jelly
Show resolved
Hide resolved
My understanding is that it's only necessary to add |
Code changes went into released of docker-plugin version 1.1.9 |
This pull request add's the --no-cache and --pull options requested in #612