Skip to content

Fix double-marshalling of cachefrom#1086

Merged
KostyaSha merged 2 commits intodocker-java:masterfrom
exFalso:master
Nov 26, 2018
Merged

Fix double-marshalling of cachefrom#1086
KostyaSha merged 2 commits intodocker-java:masterfrom
exFalso:master

Conversation

@exFalso
Copy link
Copy Markdown
Contributor

@exFalso exFalso commented Aug 18, 2018

The API for setting the --cache-from argument is:

BuildImageCmd withCacheFrom(Set<String> cacheFrom);

which intuitively indicates that the set of strings passed in should be the imageIds to use for the cache. However this is not the case, and instead users have to "wrap" the arguments in an additional '[]', as illustrated by an existing test BuildImageCmdIT.cacheFrom:

        String cacheImage = String.format("[\"%s\"]", imageId1);
        String imageId2 = dockerRule.getClient().buildImageCmd(baseDir2).withCacheFrom(new HashSet<>(Arrays.asList(cacheImage)))

As stated in the docker API https://docs.docker.com/engine/api/v1.37/#operation/ImageBuild
the cachefrom parameter is a

JSON array of images used for build cache resolution.

however the current implementation takes the set of strings, where each string itself is an array, and creates a "cachefrom" parameter for each. In other words it seems to require another layer of marshalling.

I think the original intention for this API was to take the set of strings where each string is an image id and serialize these into a JSON array automatically. This PR does this.


This change is Reviewable

webTarget = webTarget.queryParam("cachefrom", c);
}
if (command.getCacheFrom() != null && !command.getCacheFrom().isEmpty()) {
webTarget = webTarget.queryParam("cachefrom", "[\"" + Joiner.on("\",\"").join(command.getCacheFrom()) + "\"]");
Copy link
Copy Markdown
Member

@KostyaSha KostyaSha Aug 23, 2018

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please reuse existing helper methods, + parameter should be escaped

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@KostyaSha good point! It's not a Map, but I created a similar utility class

exFalso added a commit to exFalso/docker-java that referenced this pull request Aug 24, 2018
@codecov-io
Copy link
Copy Markdown

codecov-io commented Aug 24, 2018

Codecov Report

Merging #1086 into master will increase coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1086      +/-   ##
==========================================
+ Coverage    58.1%   58.11%   +0.01%     
==========================================
  Files         445      445              
  Lines        8819     8814       -5     
  Branches      537      536       -1     
==========================================
- Hits         5124     5122       -2     
+ Misses       3404     3401       -3     
  Partials      291      291
Impacted Files Coverage Δ
...github/dockerjava/core/exec/BuildImageCmdExec.java 60% <100%> (ø) ⬆️
...com/github/dockerjava/jaxrs/BuildImageCmdExec.java 56.45% <50%> (-2.93%) ⬇️
...va/com/github/dockerjava/api/model/AuthConfig.java 47.69% <0%> (-2.31%) ⬇️
...va/org/apache/http/impl/io/ChunkedInputStream.java 60.95% <0%> (+3.8%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 153e06a...95b6222. Read the comment docs.

exFalso added a commit to exFalso/docker-java that referenced this pull request Aug 24, 2018
exFalso added a commit to exFalso/docker-java that referenced this pull request Aug 24, 2018
@exFalso
Copy link
Copy Markdown
Contributor Author

exFalso commented Sep 7, 2018

@KostyaSha I addressed the comments


public static String jsonEncode(Collection<String> imageIds) {
try {
return OBJECT_MAPPER.writeValueAsString(imageIds);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You added new encoder, didn't existing fit that i referenced?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The existing one deals with maps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants