X Tutup
Skip to content
Closed
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
34 changes: 20 additions & 14 deletions src/main/java/com/kpelykh/docker/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> params = new MultivaluedMapImpl();
params.add("t", tag);
if (noCache) {
params.add("nocache", "true");
}

// ARCHIVE TAR
String archiveNameWithOutExtension = UUID.randomUUID().toString();

Expand Down Expand Up @@ -931,24 +922,39 @@ 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<String, String> params = new MultivaluedMapImpl();
params.add("t", tag);
if (noCache) {
params.add("nocache", "true");
}

WebResource webResource = client.resource(restEndpointUrl + "/build").queryParams(params);

try {
LOGGER.trace("POST: {}", webResource);
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -259,6 +260,7 @@ public String toString() {
return "ContainerState{" +
"running=" + running +
", pid=" + pid +
", paused=" + paused +
", exitCode=" + exitCode +
", startedAt='" + startedAt + '\'' +
", ghost=" + ghost +
Expand Down
X Tutup