-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow multiple tags in build image command #739
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
Conversation
Several tags for image can be defined by calling multiple time withTag() method of BuildImageCmd. In Netty implementation, the WebTarget class is modified to support several query parameteres with the same name. Fix #720
| private InputStream tarInputStream; | ||
|
|
||
| private String tag; | ||
| private Set<String> tags; |
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.
NO don't remove existing fields either you will break all < 1.21 users.
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.
This is a private filed - to preserve backward compatibility I've left getTag() method.
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.
Ah, first of all it Cmd in cmd we can break compatibility, but better do .Y increment in version then.
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.
I don't think this is a breaking change - previously written code will still work with all versions of Docker engine (unless you already called withTag() multiple times).
This change add some features so feel free to release it with incremented .Y in version.
| if (this.tags == null) { | ||
| this.tags = new HashSet<>(4); | ||
| } | ||
| this.tags.add(tag); |
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.
you can't be sure what target API is used to know what to put. Add version check to get conditional and default to latest behaviour.
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.
@KostyaSha is such version check already implemented somewhere in the code base or I have to write one?
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.
Check the place where Auth headers are added
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.
I was unable to find it. However, IMO there is no need to do version check. In recently added labels support we do not check Docker engine version either. Client will use this features when targeting newer version of Docker.
Codecov Report
@@ Coverage Diff @@
## master #739 +/- ##
==========================================
+ Coverage 71.61% 71.75% +0.14%
==========================================
Files 306 306
Lines 6584 6597 +13
Branches 483 488 +5
==========================================
+ Hits 4715 4734 +19
+ Misses 1582 1577 -5
+ Partials 287 286 -1
Continue to review full report at Codecov.
|
|
@KostyaSha Is there anything else I should do before it can be merged? |
| * @deprecated since docker API version 1.21 there can be multiple tags | ||
| * specified so use {@link #getTags()} | ||
| */ | ||
| @Deprecated() |
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.
Just @Deprecated
| return null; | ||
| } | ||
| // return first tag to be backward compatible | ||
| return tags.iterator().next(); |
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.
So maybe keep both fields and pick List<> and if it null or empty return getTag()?
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.
@KostyaSha ok, but then we end up with withTag(String tag) and new method withTags(Set<String> tags) - I don't think this is more elegant solution. But you decide.
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.
if i right understand witTag(String) is already existing and we can Deprecate it and remove in future and add new Set?
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.
yes
| File baseDir = fileFromBuildTestResource("labels"); | ||
|
|
||
| String imageId = dockerClient.buildImageCmd(baseDir).withNoCache(true) | ||
| .withTag("docker-java-test:tag1").withTag("docker-java-test:tag2") |
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.
imho that looks not obvious. If user wants only one tag it should call .withTag if multiple then .withTags(Set<String>) Maybe keep getTag() and add getTags() and prefer getTags with fallback to getTag()?
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.
ok, I'll do it this way 😄
| LOG.info("Image Inspect: {}", inspectImageResponse.toString()); | ||
|
|
||
| assertThat(inspectImageResponse.getRepoTags().size(), equalTo(2)); | ||
| assertThat(inspectImageResponse.getRepoTags().contains("docker-java-test:tag1"), equalTo(true)); |
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.
if inspectImageResponse.getRepoTags() it return List or collection then you need search for hamcrest matcher (probably see example at com/github/dockerjava/core/command/CreateContainerCmdImplTest.java:165 or com/github/dockerjava/core/command/CreateContainerCmdImplTest.java:191 remember that some matchers are strict ordered and docker may return in different order items (even depends on java collection types afair))
|
Looks like it was moved to #835 |
Reworked PR #739 (multiple tags)
Reworked PR docker-java#739 (multiple tags)
Several tags for image can be defined by subsequent calling
withTag()method ofBuildImageCmd.@marcuslinke please check my modifications of Netty
WebTargetclass to support several query parameters with the same name as this class is widely used.This change is