diff --git a/pom.xml b/pom.xml index a6c343ce6..e0edc4943 100644 --- a/pom.xml +++ b/pom.xml @@ -194,6 +194,13 @@ ${hamcrest.jpa-matchers} test + + + com.google.code.findbugs + annotations + 3.0.0 + provided + diff --git a/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java b/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java index 5a41a61fb..c737501fa 100644 --- a/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java +++ b/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java @@ -1,44 +1,95 @@ package com.github.dockerjava.api.command; -import java.io.File; -import java.io.InputStream; - import com.github.dockerjava.api.model.AuthConfigurations; import com.github.dockerjava.api.model.BuildResponseItem; +import javax.annotation.CheckForNull; +import java.io.File; +import java.io.InputStream; +import java.net.URI; + /** - * * Build an image from Dockerfile. - * + *

* TODO: http://docs.docker.com/reference/builder/#dockerignore * + * @see build-image-from-a-dockerfile */ public interface BuildImageCmd extends AsyncDockerCmd { - public BuildImageCmd withTag(String tag); +// lib specific public InputStream getTarInputStream(); + public AuthConfigurations getBuildAuthConfigs(); + +// getters + + /** + * "t" in API + */ + @CheckForNull public String getTag(); + /** + * "remote" in API + */ + @CheckForNull + public URI getRemote(); + + /** + * "nocache" in API + */ public boolean hasNoCacheEnabled(); + /** + * "rm" in API + */ public boolean hasRemoveEnabled(); + /** + * "forcerm" in API + */ + public boolean isForcerm(); + + @CheckForNull + public Boolean getForcerm(); + + /** + * "q" in API + */ public boolean isQuiet(); + /** + * "pull" in API + */ public boolean hasPullEnabled(); + @CheckForNull public String getPathToDockerfile(); - public AuthConfigurations getBuildAuthConfigs(); + @CheckForNull + public Long getMemory(); + + @CheckForNull + public Long getMemswap(); + + @CheckForNull + public String getCpushares(); + + @CheckForNull + public String getCpusetcpus(); + +// setters + + public BuildImageCmd withTag(String tag); + + public BuildImageCmd withRemote(URI remote); public BuildImageCmd withBaseDirectory(File baseDirectory); public BuildImageCmd withDockerfile(File dockerfile); - public BuildImageCmd withTarInputStream(InputStream tarInputStream); - public BuildImageCmd withNoCache(); public BuildImageCmd withNoCache(boolean noCache); @@ -47,6 +98,10 @@ public interface BuildImageCmd extends AsyncDockerCmd { } diff --git a/src/main/java/com/github/dockerjava/core/command/BuildImageCmdImpl.java b/src/main/java/com/github/dockerjava/core/command/BuildImageCmdImpl.java index 56ce8f78f..f516a1f17 100644 --- a/src/main/java/com/github/dockerjava/core/command/BuildImageCmdImpl.java +++ b/src/main/java/com/github/dockerjava/core/command/BuildImageCmdImpl.java @@ -5,12 +5,17 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import com.github.dockerjava.api.command.BuildImageCmd; import com.github.dockerjava.api.model.AuthConfigurations; import com.github.dockerjava.api.model.BuildResponseItem; import com.github.dockerjava.core.FilePathUtil; import com.github.dockerjava.core.dockerfile.Dockerfile; +import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +import javax.annotation.CheckForNull; /** * @@ -19,8 +24,10 @@ */ public class BuildImageCmdImpl extends AbstrAsyncDockerCmd implements BuildImageCmd { - private InputStream tarInputStream = null; + @CheckForNull + private InputStream tarInputStream; + @CheckForNull private String tag; private boolean noCache; @@ -31,12 +38,33 @@ public class BuildImageCmdImpl extends AbstrAsyncDockerCmd implements - BuildImageCmd.Exec { - +public class BuildImageCmdExec extends AbstrAsyncDockerCmdExec + implements BuildImageCmd.Exec { private static final Logger LOGGER = LoggerFactory.getLogger(BuildImageCmdExec.class); public BuildImageCmdExec(WebTarget baseResource) { @@ -43,23 +42,41 @@ protected AbstractCallbackNotifier callbackNotifier(BuildImag WebTarget webTarget = getBaseResource().path("/build"); String dockerFilePath = command.getPathToDockerfile(); + if (dockerFilePath != null && command.getRemote() == null && !"Dockerfile".equals(dockerFilePath)) { + webTarget = webTarget.queryParam("dockerfile", dockerFilePath); + } if (command.getTag() != null) { webTarget = webTarget.queryParam("t", command.getTag()); } + if (command.getRemote() != null) { + webTarget = webTarget.queryParam("remote", command.getRemote().toString()); + } + if (command.isQuiet()) { + webTarget = webTarget.queryParam("q", "true"); + } if (command.hasNoCacheEnabled()) { webTarget = webTarget.queryParam("nocache", "true"); } + if (command.hasPullEnabled()) { + webTarget = webTarget.queryParam("pull", "true"); + } if (!command.hasRemoveEnabled()) { webTarget = webTarget.queryParam("rm", "false"); } - if (command.isQuiet()) { - webTarget = webTarget.queryParam("q", "true"); + if (command.isForcerm()) { + webTarget = webTarget.queryParam("forcerm", "true"); } - if (command.hasPullEnabled()) { - webTarget = webTarget.queryParam("pull", "true"); + if (command.getMemory() != null) { + webTarget = webTarget.queryParam("memory", command.getMemory()); } - if (dockerFilePath != null && !"Dockerfile".equals(dockerFilePath)) { - webTarget = webTarget.queryParam("dockerfile", dockerFilePath); + if (command.getMemswap() != null) { + webTarget = webTarget.queryParam("memswap", command.getMemswap()); + } + if (command.getCpushares() != null) { + webTarget = webTarget.queryParam("cpushares", command.getCpushares()); + } + if (command.getCpusetcpus() != null) { + webTarget = webTarget.queryParam("cpusetcpus", command.getCpusetcpus()); } webTarget.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED); @@ -67,8 +84,11 @@ protected AbstractCallbackNotifier callbackNotifier(BuildImag LOGGER.trace("POST: {}", webTarget); - return new POSTCallbackNotifier(new JsonStreamProcessor( - BuildResponseItem.class), resultCallback, resourceWithOptionalAuthConfig(command, webTarget.request()) - .accept(MediaType.TEXT_PLAIN), entity(command.getTarInputStream(), "application/tar")); + return new POSTCallbackNotifier<>(new JsonStreamProcessor<>(BuildResponseItem.class), + resultCallback, + resourceWithOptionalAuthConfig(command, webTarget.request()) + .accept(MediaType.TEXT_PLAIN), + entity(command.getTarInputStream(), "application/tar") + ); } }