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
@@ -1,5 +1,9 @@
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.model.EventStreamItem;
import com.github.dockerjava.api.model.PushEventStreamItem;

import java.io.IOException;
import java.io.InputStream;

/**
Expand All @@ -9,7 +13,7 @@
* TODO: http://docs.docker.com/reference/builder/#dockerignore
*
*/
public interface BuildImageCmd extends DockerCmd<InputStream>{
public interface BuildImageCmd extends DockerCmd<BuildImageCmd.Response>{

public BuildImageCmd withTag(String tag);

Expand Down Expand Up @@ -37,7 +41,10 @@ public interface BuildImageCmd extends DockerCmd<InputStream>{

public BuildImageCmd withQuiet(boolean quiet);

public static interface Exec extends DockerCmdExec<BuildImageCmd, InputStream> {
public static interface Exec extends DockerCmdExec<BuildImageCmd, BuildImageCmd.Response> {
}

public static abstract class Response extends InputStream {
public abstract Iterable<EventStreamItem> getItems() throws IOException;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.github.dockerjava.api.command;

import java.io.IOException;
import java.io.InputStream;

import com.github.dockerjava.api.NotFoundException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.PushEventStreamItem;

/**
* Push the latest image to the repository.
*
* @param name The name, e.g. "alexec/busybox" or just "busybox" if you want to default. Not null.
*/
public interface PushImageCmd extends DockerCmd<InputStream>{
public interface PushImageCmd extends DockerCmd<PushImageCmd.Response>{

public String getName();

Expand All @@ -33,10 +35,13 @@ public interface PushImageCmd extends DockerCmd<InputStream>{
/**
* @throws NotFoundException No such image
*/
@Override
public InputStream exec() throws NotFoundException;
public Response exec() throws NotFoundException;

public static interface Exec extends DockerCmdExec<PushImageCmd, InputStream> {
public static interface Exec extends DockerCmdExec<PushImageCmd, Response> {
}

public static abstract class Response extends InputStream {
public abstract Iterable<PushEventStreamItem> getItems() throws IOException;
}

}
64 changes: 64 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/EventStreamItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.dockerjava.api.model;



import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

import jersey.repackaged.com.google.common.base.Objects;

/**
* Represents an event stream
*/
@JsonIgnoreProperties(ignoreUnknown=true)
public class EventStreamItem implements Serializable {

@JsonProperty("stream")
private String stream;

// {"error":"Error...", "errorDetail":{"code": 123, "message": "Error..."}}
@JsonProperty("error")
private String error;

@JsonProperty("errorDetail")
private ErrorDetail errorDetail;

public String getStream() {
return stream;
}

public String getError() {
return error;
}

public ErrorDetail getErrorDetail() {
return errorDetail;
}

@JsonIgnoreProperties(ignoreUnknown=true)
public static class ErrorDetail implements Serializable {
@JsonProperty("code")
String code;
@JsonProperty("message")
String message;

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("code", code)
.add("message", message)
.toString();
}
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("stream", stream)
.add("error", error)
.add("errorDetail", errorDetail)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

import jersey.repackaged.com.google.common.base.Objects;

/**
* Represents an item returned from push
*/
@JsonIgnoreProperties(ignoreUnknown=true)
public class PushEventStreamItem implements Serializable {

@JsonProperty("status")
private String status;

@JsonProperty("progress")
private String progress;

@JsonProperty("progressDetail")
private ProgressDetail progressDetail;


public String getStatus() {
return status;
}

public String getProgress() {
return progress;
}

public ProgressDetail getProgressDetail() {
return progressDetail;
}

@JsonIgnoreProperties(ignoreUnknown=true)
public static class ProgressDetail implements Serializable {
@JsonProperty("current")
int current;


@Override
public String toString() {
return "current " + current;
}
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("status", status)
.add("progress", progress)
.add("progressDetail", progressDetail)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
* Build an image from Dockerfile.
*
*/
public class BuildImageCmdImpl extends
AbstrDockerCmd<BuildImageCmd, InputStream> implements BuildImageCmd {
public class BuildImageCmdImpl extends AbstrDockerCmd<BuildImageCmd, BuildImageCmd.Response> implements BuildImageCmd {

private static final Pattern ADD_OR_COPY_PATTERN = Pattern
.compile("^(ADD|COPY)\\s+(.*)\\s+(.*)$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import static jersey.repackaged.com.google.common.base.Preconditions.checkNotNull;

import java.io.InputStream;

import com.github.dockerjava.api.NotFoundException;
import com.github.dockerjava.api.command.PushImageCmd;

Expand All @@ -12,7 +10,7 @@
*
* @param name The name, e.g. "alexec/busybox" or just "busybox" if you want to default. Not null.
*/
public class PushImageCmdImpl extends AbstrAuthCfgDockerCmd<PushImageCmd, InputStream> implements PushImageCmd {
public class PushImageCmdImpl extends AbstrAuthCfgDockerCmd<PushImageCmd, PushImageCmd.Response> implements PushImageCmd {

private String name;
private String tag;
Expand Down Expand Up @@ -63,7 +61,7 @@ public String toString() {
* @throws NotFoundException No such image
*/
@Override
public InputStream exec() throws NotFoundException {
public Response exec() throws NotFoundException {
return super.exec();
}
}
51 changes: 44 additions & 7 deletions src/main/java/com/github/dockerjava/jaxrs/BuildImageCmdExec.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.github.dockerjava.jaxrs;



import static javax.ws.rs.client.Entity.entity;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
Expand All @@ -13,9 +17,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.github.dockerjava.api.command.BuildImageCmd;
import com.github.dockerjava.api.command.PushImageCmd;
import com.github.dockerjava.api.model.EventStreamItem;
import com.github.dockerjava.api.model.PushEventStreamItem;

import jersey.repackaged.com.google.common.collect.ImmutableList;

public class BuildImageCmdExec extends AbstrDockerCmdExec<BuildImageCmd, InputStream> implements BuildImageCmd.Exec {
public class BuildImageCmdExec extends AbstrDockerCmdExec<BuildImageCmd, BuildImageCmd.Response> implements BuildImageCmd.Exec {

private static final Logger LOGGER = LoggerFactory
.getLogger(BuildImageCmdExec.class);
Expand All @@ -25,7 +36,7 @@ public BuildImageCmdExec(WebTarget baseResource) {
}

@Override
protected InputStream execute(BuildImageCmd command) {
protected ResponseImpl execute(BuildImageCmd command) {
WebTarget webResource = getBaseResource().path("/build");

if(command.getTag() != null) {
Expand All @@ -45,12 +56,38 @@ protected InputStream execute(BuildImageCmd command) {
webResource.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
webResource.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024*1024);

LOGGER.debug("POST: {}", webResource);
return webResource
.request()
.accept(MediaType.TEXT_PLAIN)
.post(entity(command.getTarInputStream(), "application/tar"), Response.class).readEntity(InputStream.class);

LOGGER.debug("POST: {}", webResource);
InputStream is = webResource
.request()
.accept(MediaType.TEXT_PLAIN)
.post(entity(command.getTarInputStream(), "application/tar"), Response.class).readEntity(InputStream.class);

return new ResponseImpl(is);

}
public static class ResponseImpl extends BuildImageCmd.Response {

private final InputStream proxy;

public ResponseImpl(InputStream proxy) {
this.proxy = proxy;
}

@Override
public Iterable<EventStreamItem> getItems() throws IOException {
ObjectMapper mapper = new ObjectMapper();
// we'll be reading instances of MyBean
ObjectReader reader = mapper.reader(EventStreamItem.class);
// and then do other configuration, if any, and read:
Iterator<EventStreamItem> items = reader.readValues(proxy);

return ImmutableList.copyOf(items);
}

@Override
public int read() throws IOException {
return proxy.read();
}
}
}
Loading