Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* TODO: http://docs.docker.com/reference/builder/#dockerignore
*
* @see <a
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.20/#build-image-from-a-dockerfile">build-image-from-a-dockerfile</a>
* href="https://docs.docker.com/reference/api/docker_remote_api_v1.20/#build-image-from-a-dockerfile">build-image-from-a-dockerfile</a>
*/
public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildResponseItem> {

Expand All @@ -45,6 +45,7 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon

/**
* Multple "t" tags.
*
* @since {@link RemoteApiVersion#VERSION_1_21}
*/
@CheckForNull
Expand Down Expand Up @@ -114,7 +115,7 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon
Map<String, String> getBuildArgs();

/**
*@since {@link RemoteApiVersion#VERSION_1_22}
* @since {@link RemoteApiVersion#VERSION_1_22}
*/
@CheckForNull
Long getShmsize();
Expand All @@ -135,7 +136,7 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon

/**
* @deprecated since docker API version 1.21 there can be multiple tags
* specified so use {@link #withTags(Set<String>)}
* specified so use {@link BuildImageCmd#withTags(java.util.Set)}
*/
@Deprecated
BuildImageCmd withTag(String tag);
Expand Down Expand Up @@ -185,17 +186,17 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon
BuildImageCmd withTarInputStream(@Nonnull InputStream tarInputStream);

/**
*@since {@link RemoteApiVersion#VERSION_1_22}
*/
* @since {@link RemoteApiVersion#VERSION_1_22}
*/
BuildImageCmd withShmsize(Long shmsize);

/**
*@since {@link RemoteApiVersion#VERSION_1_23}
*/
* @since {@link RemoteApiVersion#VERSION_1_23}
*/
BuildImageCmd withLabels(Map<String, String> labels);

/**
*@since {@link RemoteApiVersion#VERSION_1_25}
* @since {@link RemoteApiVersion#VERSION_1_25}
*/
BuildImageCmd withNetworkMode(String networkMode);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.github.dockerjava.core.exec;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.BuildImageCmd;
Expand All @@ -12,7 +9,10 @@
import com.github.dockerjava.core.InvocationBuilder;
import com.github.dockerjava.core.MediaType;
import com.github.dockerjava.core.WebTarget;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.github.dockerjava.core.util.CacheFromEncoder.jsonEncode;
import static org.apache.commons.lang.StringUtils.isNotBlank;

public class BuildImageCmdExec extends AbstrAsyncDockerCmdExec<BuildImageCmd, BuildResponseItem> implements
Expand Down Expand Up @@ -59,7 +59,7 @@ protected Void execute0(BuildImageCmd command, ResultCallback<BuildResponseItem>
}

if (command.getCacheFrom() != null && !command.getCacheFrom().isEmpty()) {
webTarget = webTarget.queryParamsSet("cachefrom", command.getCacheFrom());
webTarget = webTarget.queryParam("cachefrom", jsonEncode(command.getCacheFrom()));
}

if (command.getRemote() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.dockerjava.core.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

import javax.ws.rs.core.MediaType;
import java.util.Collection;

/**
* JSON Encoder for the docker --cache-from parameter.
*/
public class CacheFromEncoder {

private CacheFromEncoder() {
}

private static final ObjectMapper MAPPER = new JacksonJaxbJsonProvider().locateMapper(Collection.class,
MediaType.APPLICATION_JSON_TYPE);

public static String jsonEncode(Collection<String> imageIds) {
try {
return MAPPER.writeValueAsString(imageIds);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
* JSON Encoder for docker filters.
*
* @author Carlos Sanchez <carlos@apache.org>
*
*/
public class FiltersEncoder {

private FiltersEncoder() {
}

private static final ObjectMapper OBJECT_MAPPER = new JacksonJaxbJsonProvider().locateMapper(Map.class,
MediaType.APPLICATION_JSON_TYPE);
private static final ObjectMapper MAPPER = new JacksonJaxbJsonProvider().locateMapper(Map.class, MediaType.APPLICATION_JSON_TYPE);

public static String jsonEncode(Map<String, List<String>> filters) {
public static String jsonEncode(Map<String, List<String>> mapStringListString) {
try {
return OBJECT_MAPPER.writeValueAsString(filters);
return MAPPER.writeValueAsString(mapStringListString);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;

import com.github.dockerjava.core.util.CacheFromEncoder;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.RequestEntityProcessing;
import org.slf4j.Logger;
Expand Down Expand Up @@ -75,10 +76,8 @@ protected AbstractCallbackNotifier<BuildResponseItem> callbackNotifier(BuildImag
webTarget = webTarget.queryParam("t", command.getTag());
}

if (command.getCacheFrom() != null) {
for (String c: command.getCacheFrom()) {
webTarget = webTarget.queryParam("cachefrom", c);
}
if (command.getCacheFrom() != null && !command.getCacheFrom().isEmpty()) {
webTarget = webTarget.queryParam("cachefrom", CacheFromEncoder.jsonEncode(command.getCacheFrom()));
}

if (command.getRemote() != null) {
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/github/dockerjava/cmd/BuildImageCmdIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ public void cacheFrom() throws Exception {
assertThat(inspectImageResponse1, not(nullValue()));

File baseDir2 = fileFromBuildTestResource("CacheFrom/test2");
String cacheImage = String.format("[\"%s\"]", imageId1);
String imageId2 = dockerRule.getClient().buildImageCmd(baseDir2).withCacheFrom(new HashSet<>(Arrays.asList(cacheImage)))
String imageId2 = dockerRule.getClient().buildImageCmd(baseDir2).withCacheFrom(new HashSet<>(Arrays.asList(imageId1)))
.exec(new BuildImageResultCallback())
.awaitImageId();
InspectImageResponse inspectImageResponse2 = dockerRule.getClient().inspectImageCmd(imageId2).exec();
Expand Down