diff --git a/src/main/java/com/kpelykh/docker/client/DockerClient.java b/src/main/java/com/kpelykh/docker/client/DockerClient.java index 101d7209d..9a38222df 100644 --- a/src/main/java/com/kpelykh/docker/client/DockerClient.java +++ b/src/main/java/com/kpelykh/docker/client/DockerClient.java @@ -870,15 +870,6 @@ public ClientResponse build(File dockerFolder, String tag, boolean noCache) thro Preconditions.checkArgument(dockerFolder.exists(), "Folder %s doesn't exist", dockerFolder); Preconditions.checkState(new File(dockerFolder, "Dockerfile").exists(), "Dockerfile doesn't exist in " + dockerFolder); - //We need to use Jersey HttpClient here, since ApacheHttpClient4 will not add boundary filed to - //Content-Type: multipart/form-data; boundary=Boundary_1_372491238_1372806136625 - - MultivaluedMap params = new MultivaluedMapImpl(); - params.add("t", tag); - if (noCache) { - params.add("nocache", "true"); - } - // ARCHIVE TAR String archiveNameWithOutExtension = UUID.randomUUID().toString(); @@ -931,6 +922,25 @@ public ClientResponse build(File dockerFolder, String tag, boolean noCache) thro throw new DockerException("Error occurred while preparing Docker context folder.", ex); } + try { + return build(FileUtils.openInputStream(dockerFolderTar), tag, noCache); + } catch (IOException e) { + throw new DockerException(e); + } finally { + FileUtils.deleteQuietly(dockerFolderTar); + } + } + + public ClientResponse build(InputStream tarStream, String tag, boolean noCache) throws DockerException { + //We need to use Jersey HttpClient here, since ApacheHttpClient4 will not add boundary filed to + //Content-Type: multipart/form-data; boundary=Boundary_1_372491238_1372806136625 + + MultivaluedMap params = new MultivaluedMapImpl(); + params.add("t", tag); + if (noCache) { + params.add("nocache", "true"); + } + WebResource webResource = client.resource(restEndpointUrl + "/build").queryParams(params); try { @@ -938,17 +948,13 @@ public ClientResponse build(File dockerFolder, String tag, boolean noCache) thro return webResource .type("application/tar") .accept(MediaType.TEXT_PLAIN) - .post(ClientResponse.class, FileUtils.openInputStream(dockerFolderTar)); + .post(ClientResponse.class, tarStream); } catch (UniformInterfaceException exception) { if (exception.getResponse().getStatus() == 500) { throw new DockerException("Server error", exception); } else { throw new DockerException(exception); } - } catch (IOException e) { - throw new DockerException(e); - } finally { - FileUtils.deleteQuietly(dockerFolderTar); } } } diff --git a/src/main/java/com/kpelykh/docker/client/model/ContainerInspectResponse.java b/src/main/java/com/kpelykh/docker/client/model/ContainerInspectResponse.java index d686f9ebf..8a2946301 100644 --- a/src/main/java/com/kpelykh/docker/client/model/ContainerInspectResponse.java +++ b/src/main/java/com/kpelykh/docker/client/model/ContainerInspectResponse.java @@ -249,6 +249,7 @@ public class ContainerState { @JsonProperty("Running") public boolean running; @JsonProperty("Pid") public int pid; + @JsonProperty("Paused") public boolean paused; @JsonProperty("ExitCode") public int exitCode; @JsonProperty("StartedAt") public String startedAt; @JsonProperty("Ghost") public boolean ghost; @@ -259,6 +260,7 @@ public String toString() { return "ContainerState{" + "running=" + running + ", pid=" + pid + + ", paused=" + paused + ", exitCode=" + exitCode + ", startedAt='" + startedAt + '\'' + ", ghost=" + ghost +