
org.testifyproject.github.dockerjava.netty.exec.BuildImageCmdExec Maven / Gradle / Ivy
package org.testifyproject.testifyproject.github.dockerjava.netty.exec;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.ObjectMapper;
import org.testifyproject.slf4j.Logger;
import org.testifyproject.slf4j.LoggerFactory;
import org.testifyproject.testifyproject.fasterxml.jackson.core.type.TypeReference;
import org.testifyproject.testifyproject.github.dockerjava.api.async.ResultCallback;
import org.testifyproject.testifyproject.github.dockerjava.api.org.testifyproject.testifyprojectmand.BuildImageCmd;
import org.testifyproject.testifyproject.github.dockerjava.api.model.AuthConfigurations;
import org.testifyproject.testifyproject.github.dockerjava.api.model.BuildResponseItem;
import org.testifyproject.testifyproject.github.dockerjava.core.DockerClientConfig;
import org.testifyproject.testifyproject.github.dockerjava.netty.InvocationBuilder;
import org.testifyproject.testifyproject.github.dockerjava.netty.MediaType;
import org.testifyproject.testifyproject.github.dockerjava.netty.WebTarget;
import java.org.testifyproject.testifyproject.IOException;
public class BuildImageCmdExec extends AbstrAsyncDockerCmdExec implements
BuildImageCmd.Exec {
private static final Logger LOGGER = LoggerFactory.getLogger(BuildImageCmdExec.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
public BuildImageCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
super(baseResource, dockerClientConfig);
}
private InvocationBuilder resourceWithOptionalAuthConfig(BuildImageCmd org.testifyproject.testifyprojectmand, InvocationBuilder request) {
final AuthConfigurations authConfigs = firstNonNull(org.testifyproject.testifyprojectmand.getBuildAuthConfigs(), getBuildAuthConfigs());
if (authConfigs != null && !authConfigs.getConfigs().isEmpty()) {
request = request.header("X-Registry-Config", registryConfigs(authConfigs));
}
return request;
}
private static AuthConfigurations firstNonNull(final AuthConfigurations fromCommand,
final AuthConfigurations fromConfig) {
if (fromCommand != null) {
return fromCommand;
}
if (fromConfig != null) {
return fromConfig;
}
return null;
}
@Override
protected Void execute0(BuildImageCmd org.testifyproject.testifyprojectmand, ResultCallback resultCallback) {
WebTarget webTarget = getBaseResource().path("/build");
String dockerFilePath = org.testifyproject.testifyprojectmand.getPathToDockerfile();
if (dockerFilePath != null && org.testifyproject.testifyprojectmand.getRemote() == null && !"Dockerfile".equals(dockerFilePath)) {
webTarget = webTarget.queryParam("dockerfile", dockerFilePath);
}
if (org.testifyproject.testifyprojectmand.getTag() != null) {
webTarget = webTarget.queryParam("t", org.testifyproject.testifyprojectmand.getTag());
}
if (org.testifyproject.testifyprojectmand.getRemote() != null) {
webTarget = webTarget.queryParam("remote", org.testifyproject.testifyprojectmand.getRemote().toString());
}
webTarget = booleanQueryParam(webTarget, "q", org.testifyproject.testifyprojectmand.isQuiet());
webTarget = booleanQueryParam(webTarget, "nocache", org.testifyproject.testifyprojectmand.hasNoCacheEnabled());
webTarget = booleanQueryParam(webTarget, "pull", org.testifyproject.testifyprojectmand.hasPullEnabled());
webTarget = booleanQueryParam(webTarget, "rm", org.testifyproject.testifyprojectmand.hasRemoveEnabled());
webTarget = booleanQueryParam(webTarget, "forcerm", org.testifyproject.testifyprojectmand.isForcerm());
// this has to be handled differently as it should switch to 'false'
if (org.testifyproject.testifyprojectmand.hasRemoveEnabled() == null || !org.testifyproject.testifyprojectmand.hasRemoveEnabled()) {
webTarget = webTarget.queryParam("rm", "false");
}
if (org.testifyproject.testifyprojectmand.getMemory() != null) {
webTarget = webTarget.queryParam("memory", org.testifyproject.testifyprojectmand.getMemory());
}
if (org.testifyproject.testifyprojectmand.getMemswap() != null) {
webTarget = webTarget.queryParam("memswap", org.testifyproject.testifyprojectmand.getMemswap());
}
if (org.testifyproject.testifyprojectmand.getCpushares() != null) {
webTarget = webTarget.queryParam("cpushares", org.testifyproject.testifyprojectmand.getCpushares());
}
if (org.testifyproject.testifyprojectmand.getCpusetcpus() != null) {
webTarget = webTarget.queryParam("cpusetcpus", org.testifyproject.testifyprojectmand.getCpusetcpus());
}
if (org.testifyproject.testifyprojectmand.getBuildArgs() != null && !org.testifyproject.testifyprojectmand.getBuildArgs().isEmpty()) {
try {
webTarget = webTarget.queryParam("buildargs", MAPPER.writeValueAsString(org.testifyproject.testifyprojectmand.getBuildArgs()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (org.testifyproject.testifyprojectmand.getShmsize() != null) {
webTarget = webTarget.queryParam("shmsize", org.testifyproject.testifyprojectmand.getShmsize());
}
LOGGER.trace("POST: {}", webTarget);
InvocationBuilder builder = resourceWithOptionalAuthConfig(org.testifyproject.testifyprojectmand, webTarget.request())
.accept(MediaType.APPLICATION_JSON)
.header("Content-Type", "application/tar")
.header("encoding", "gzip");
builder.post(new TypeReference() {
}, resultCallback, org.testifyproject.testifyprojectmand.getTarInputStream());
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy