本文整理汇总了Java中com.github.dockerjava.api.command.BuildImageCmd类的典型用法代码示例。如果您正苦于以下问题:Java BuildImageCmd类的具体用法?Java BuildImageCmd怎么用?Java BuildImageCmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BuildImageCmd类属于com.github.dockerjava.api.command包,在下文中一共展示了BuildImageCmd类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: customizableImage
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Test
public void customizableImage() {
ImageFromDockerfile image = new ImageFromDockerfile() {
@Override
protected void configure(BuildImageCmd buildImageCmd) {
super.configure(buildImageCmd);
List<String> dockerfile = Arrays.asList(
"FROM alpine:3.2",
"RUN echo 'hello from Docker build process'",
"CMD yes"
);
withFileFromString("Dockerfile", String.join("\n", dockerfile));
buildImageCmd.withNoCache(true);
}
};
verifyImage(image);
}
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:21,代码来源:DockerfileTest.java
示例2: createBuildImageCmdExec
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
public BuildImageCmd.Exec createBuildImageCmdExec() {
return new BuildImageCmd.Exec() {
@Override
public Void exec(BuildImageCmd command, ResultCallback<BuildResponseItem> resultCallback) {
// can't detect image id here so tagging it
String tag = command.getTag();
if (tag == null || "".equals(tag.trim())) {
tag = "" + new SecureRandom().nextInt(Integer.MAX_VALUE);
command.withTag(tag);
}
delegate.createBuildImageCmdExec().exec(command, resultCallback);
imageNames.add(tag);
return null;
}
};
}
开发者ID:docker-java,项目名称:docker-java,代码行数:18,代码来源:TestDockerCmdExecFactory.java
示例3: configureBuildCommand
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
private void configureBuildCommand(Map<String, Object> params, BuildImageCmd buildImageCmd) {
if (params.containsKey(NO_CACHE)) {
buildImageCmd.withNoCache((boolean) params.get(NO_CACHE));
}
if (params.containsKey(REMOVE)) {
buildImageCmd.withRemove((boolean) params.get(REMOVE));
}
if (params.containsKey(DOCKERFILE_NAME)) {
buildImageCmd.withDockerfile(new File((String) params.get(DOCKERFILE_NAME)));
}
if(this.dockerClientConfig.getRegistryUsername() != null && this.dockerClientConfig.getRegistryPassword() != null){
AuthConfig buildAuthConfig = new AuthConfig().withUsername(this.dockerClientConfig.getRegistryUsername())
.withPassword(this.dockerClientConfig.getRegistryPassword())
.withEmail(this.dockerClientConfig.getRegistryEmail())
.withRegistryAddress(this.dockerClientConfig.getRegistryUrl());
final AuthConfigurations authConfigurations = new AuthConfigurations();
authConfigurations.addConfig(buildAuthConfig);
buildImageCmd.withBuildAuthConfigs(authConfigurations);
}
}
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:24,代码来源:DockerClientExecutor.java
示例4: testCreateImage_success
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Test
public void testCreateImage_success() throws Exception {
// Prepare the mocks
BuildImageCmd buildImageCmd = Mockito.mock( BuildImageCmd.class );
Mockito.when( this.dockerClient.buildImageCmd( Mockito.any( File.class ))).thenReturn( buildImageCmd );
Mockito.when( buildImageCmd.withPull( true )).thenReturn( buildImageCmd );
Mockito.when( buildImageCmd.withTags( Mockito.anySetOf( String.class ))).thenReturn( buildImageCmd );
RoboconfBuildImageResultCallback cb = Mockito.mock( RoboconfBuildImageResultCallback.class );
Mockito.when( buildImageCmd.exec( Mockito.any( RoboconfBuildImageResultCallback.class ))).thenReturn( cb );
Mockito.when( cb.awaitImageId()).thenReturn( "my-img-id" );
// Create the container (mock)
final String imageId = "toto";
this.configurator.getParameters().setTargetPropertiesDirectory( this.folder.newFolder());
this.configurator.getParameters().getTargetProperties().put( GENERATE_IMAGE_FROM, "img" );
File dockerfileDir = new File( this.configurator.getParameters().getTargetPropertiesDirectory(), "img" );
Utils.createDirectory( dockerfileDir );
this.configurator.createImage( imageId );
// Check the client
Mockito.verify( this.dockerClient, Mockito.only()).buildImageCmd( dockerfileDir );
Mockito.verify( buildImageCmd ).withPull( true );
Mockito.verify( buildImageCmd ).withTags( new HashSet<>( Arrays.asList( imageId )));
Mockito.verify( buildImageCmd ).exec( Mockito.any( RoboconfBuildImageResultCallback.class ));
Mockito.verifyNoMoreInteractions( buildImageCmd );
Mockito.verify( cb, Mockito.only()).awaitImageId();
}
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:33,代码来源:DockerMachineConfiguratorTest.java
示例5: resourceWithOptionalAuthConfig
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
private Invocation.Builder resourceWithOptionalAuthConfig(BuildImageCmd command, Invocation.Builder request) {
final AuthConfigurations authConfigs = firstNonNull(command.getBuildAuthConfigs(), getBuildAuthConfigs());
if (authConfigs != null && !authConfigs.getConfigs().isEmpty()) {
request = request.header("X-Registry-Config", registryConfigs(authConfigs));
}
return request;
}
开发者ID:docker-java,项目名称:docker-java,代码行数:8,代码来源:BuildImageCmdExec.java
示例6: resourceWithOptionalAuthConfig
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
private InvocationBuilder resourceWithOptionalAuthConfig(BuildImageCmd command, InvocationBuilder request) {
final AuthConfigurations authConfigs = firstNonNull(command.getBuildAuthConfigs(), getBuildAuthConfigs());
if (authConfigs != null && !authConfigs.getConfigs().isEmpty()) {
request = request.header("X-Registry-Config", registryConfigs(authConfigs));
}
return request;
}
开发者ID:docker-java,项目名称:docker-java,代码行数:8,代码来源:BuildImageCmdExec.java
示例7: BuildImageCmdImpl
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
public BuildImageCmdImpl(BuildImageCmd.Exec exec, File dockerFileOrFolder) {
super(exec);
checkNotNull(dockerFileOrFolder, "dockerFolder is null");
if (dockerFileOrFolder.isDirectory()) {
withBaseDirectory(dockerFileOrFolder);
withDockerfile(new File(dockerFileOrFolder, "Dockerfile"));
} else {
withDockerfile(dockerFileOrFolder);
}
}
开发者ID:docker-java,项目名称:docker-java,代码行数:12,代码来源:BuildImageCmdImpl.java
示例8: withBuildArg
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
public BuildImageCmd withBuildArg(String key, String value) {
if (this.buildArgs == null) {
this.buildArgs = new HashMap<String, String>();
}
this.buildArgs.put(key, value);
return this;
}
开发者ID:docker-java,项目名称:docker-java,代码行数:9,代码来源:BuildImageCmdImpl.java
示例9: execBuild
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
private String execBuild(BuildImageCmd buildImageCmd) throws Exception {
String imageId = buildImageCmd.withNoCache(true).exec(new BuildImageResultCallback()).awaitImageId();
// Create container based on image
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(imageId).exec();
LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
dockerRule.getClient().waitContainerCmd(container.getId()).exec(new WaitContainerResultCallback()).awaitStatusCode();
return dockerRule.containerLog(container.getId());
}
开发者ID:docker-java,项目名称:docker-java,代码行数:15,代码来源:BuildImageCmdIT.java
示例10: dockerfileNotInBaseDirectory
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
public void dockerfileNotInBaseDirectory() throws Exception {
File baseDirectory = fileFromBuildTestResource("dockerfileNotInBaseDirectory");
File dockerfile = fileFromBuildTestResource("dockerfileNotInBaseDirectory/dockerfileFolder/Dockerfile");
BuildImageCmd command = dockerRule.getClient().buildImageCmd()
.withBaseDirectory(baseDirectory)
.withDockerfile(dockerfile);
String response = execBuild(command);
assertThat(response, containsString("Successfully executed testrun.sh"));
}
开发者ID:docker-java,项目名称:docker-java,代码行数:12,代码来源:BuildImageCmdIT.java
示例11: buildImage
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
private String buildImage(String location, String name, Map<String, Object> params) {
this.readWriteLock.writeLock().lock();
try {
BuildImageCmd buildImageCmd = createBuildCommand(location);
configureBuildCommand(params, buildImageCmd);
if (name != null) {
buildImageCmd.withTag(name);
}
String imageId = buildImageCmd.exec(new BuildImageResultCallback()).awaitImageId();
if (imageId == null) {
throw new IllegalStateException(
String.format(
"Docker server has not provided an imageId for image build from %s.",
location));
}
// TODO this should be removed in the future it is only a hack to avoid some errors with Hijack is incompatible with use of CloseNotifier.
// It seems to be a problem with go and should be fixed in go 1.6 (and maybe in Docker 1.11.0).
// To test in future versions we only need to comment the close + recreation.
// following lines fixes #310 by closing and rebuilding dockerClient
// https://github.com/arquillian/arquillian-cube/issues/322
try {
this.dockerClient.close();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
this.dockerClient = buildDockerClient();
return imageId.trim();
} finally {
this.readWriteLock.writeLock().unlock();
}
}
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:36,代码来源:DockerClientExecutor.java
示例12: executeBuildImageRequest
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
/**
* Produces a build image request
*
* @param client
* @param message
* @return
* @throws DockerException
*/
private BuildImageCmd executeBuildImageRequest(DockerClient client, Message message) throws DockerException {
LOGGER.debug("Executing Docker Build Image Request");
Object body = message.getBody();
BuildImageCmd buildImageCmd;
if (body != null && body instanceof InputStream) {
buildImageCmd = client.buildImageCmd((InputStream) body);
} else if (body != null && body instanceof File) {
buildImageCmd = client.buildImageCmd((File) body);
} else {
throw new DockerException("Unable to location source Image");
}
Boolean noCache = DockerHelper.getProperty(DockerConstants.DOCKER_NO_CACHE, configuration, message, Boolean.class);
if (noCache != null) {
buildImageCmd.withNoCache(noCache);
}
Boolean quiet = DockerHelper.getProperty(DockerConstants.DOCKER_QUIET, configuration, message, Boolean.class);
if (quiet != null) {
buildImageCmd.withQuiet(quiet);
}
Boolean remove = DockerHelper.getProperty(DockerConstants.DOCKER_REMOVE, configuration, message, Boolean.class);
if (remove != null) {
buildImageCmd.withRemove(remove);
}
String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
if (tag != null) {
buildImageCmd.withTag(tag);
}
return buildImageCmd;
}
开发者ID:HydAu,项目名称:Camel,代码行数:52,代码来源:DockerProducer.java
示例13: resolve
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
protected final String resolve() {
Logger logger = DockerLoggerFactory.getLogger(dockerImageName);
Profiler profiler = new Profiler("Rule creation - build image");
profiler.setLogger(logger);
DockerClient dockerClient = DockerClientFactory.instance().client();
try {
if (deleteOnExit) {
imagesToDelete.add(dockerImageName);
}
BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
@Override
public void onNext(BuildResponseItem item) {
super.onNext(item);
if (item.isErrorIndicated()) {
logger.error(item.getErrorDetail().getMessage());
} else {
logger.debug(StringUtils.chomp(item.getStream(), "\n"));
}
}
};
// We have to use pipes to avoid high memory consumption since users might want to build really big images
@Cleanup PipedInputStream in = new PipedInputStream();
@Cleanup PipedOutputStream out = new PipedOutputStream(in);
profiler.start("Configure image");
BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(in);
configure(buildImageCmd);
profiler.start("Build image");
BuildImageResultCallback exec = buildImageCmd.exec(resultCallback);
// To build an image, we have to send the context to Docker in TAR archive format
profiler.start("Send context as TAR");
try (TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(new GZIPOutputStream(out))) {
tarArchive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
for (Map.Entry<String, Transferable> entry : transferables.entrySet()) {
Transferable transferable = entry.getValue();
final String destination = entry.getKey();
transferable.transferTo(tarArchive, destination);
}
tarArchive.finish();
}
profiler.start("Wait for an image id");
exec.awaitImageId();
return dockerImageName;
} catch(IOException e) {
throw new RuntimeException("Can't close DockerClient", e);
} finally {
profiler.stop().log();
}
}
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:62,代码来源:ImageFromDockerfile.java
示例14: configure
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
protected void configure(BuildImageCmd buildImageCmd) {
buildImageCmd.withTag(this.getDockerImageName());
}
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:4,代码来源:ImageFromDockerfile.java
示例15: call
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
public String call() throws Exception {
FilePath folder = new FilePath(new File(expandedDockerFolder));
if (!exist(folder))
throw new IllegalArgumentException(
"configured dockerFolder '" + expandedDockerFolder + "' does not exist.");
if (!exist(folder.child(dockerFileRes))) {
throw new IllegalArgumentException(
String.format("Configured Docker file '%s' does not exist.", dockerFileRes));
}
File docker = new File(expandedDockerFolder, dockerFileRes);
BuildImageResultCallback callback = new BuildImageResultCallback() {
@Override
public void onNext(BuildResponseItem item) {
super.onNext(item);
}
@Override
public void onError(Throwable throwable) {
super.onError(throwable);
}
};
DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);
BuildImageCmd buildImageCmd = client
.buildImageCmd(docker)
.withTag(expandedImageTag)
.withNoCache(noCache)
.withRemove(rm);
if (!buildArgsMap.isEmpty()) {
for (final Map.Entry<String, String> entry : buildArgsMap.entrySet()) {
buildImageCmd = buildImageCmd.withBuildArg(entry.getKey(), entry.getValue());
}
}
BuildImageResultCallback result = buildImageCmd.exec(callback);
return result.awaitImageId();
}
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:43,代码来源:CreateImageRemoteCallable.java
示例16: createBuildImageCmdExec
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
public BuildImageCmd.Exec createBuildImageCmdExec() {
return new BuildImageCmdExec(getBaseResource(), getDockerClientConfig());
}
开发者ID:docker-java,项目名称:docker-java,代码行数:5,代码来源:JerseyDockerCmdExecFactory.java
示例17: callbackNotifier
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
protected AbstractCallbackNotifier<BuildResponseItem> callbackNotifier(BuildImageCmd command,
ResultCallback<BuildResponseItem> resultCallback) {
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.getTags() != null && !command.getTags().isEmpty()) {
for (String t : command.getTags()) {
webTarget = webTarget.queryParam("t", t);
}
} else if (isNotBlank(command.getTag())) {
webTarget = webTarget.queryParam("t", command.getTag());
}
if (command.getCacheFrom() != null) {
for (String c: command.getCacheFrom()) {
webTarget = webTarget.queryParam("cachefrom", c);
}
}
if (command.getRemote() != null) {
webTarget = webTarget.queryParam("remote", command.getRemote().toString());
}
webTarget = booleanQueryParam(webTarget, "q", command.isQuiet());
webTarget = booleanQueryParam(webTarget, "nocache", command.hasNoCacheEnabled());
webTarget = booleanQueryParam(webTarget, "pull", command.hasPullEnabled());
webTarget = booleanQueryParam(webTarget, "rm", command.hasRemoveEnabled());
webTarget = booleanQueryParam(webTarget, "forcerm", command.isForcerm());
// this has to be handled differently as it should switch to 'false'
if (command.hasRemoveEnabled() == null || !command.hasRemoveEnabled()) {
webTarget = webTarget.queryParam("rm", "false");
}
if (command.getMemory() != null) {
webTarget = webTarget.queryParam("memory", command.getMemory());
}
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());
}
if (command.hasRemoveEnabled() == null || !command.hasRemoveEnabled()) {
webTarget = webTarget.queryParam("rm", "false");
}
webTarget = writeMap(webTarget, "buildargs", command.getBuildArgs());
if (command.getShmsize() != null) {
webTarget = webTarget.queryParam("shmsize", command.getShmsize());
}
webTarget = writeMap(webTarget, "labels", command.getLabels());
webTarget.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
webTarget.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024 * 1024);
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")
);
}
开发者ID:docker-java,项目名称:docker-java,代码行数:77,代码来源:BuildImageCmdExec.java
示例18: buildImageCmd
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
public BuildImageCmd buildImageCmd() {
return new BuildImageCmdImpl(getDockerCmdExecFactory().createBuildImageCmdExec());
}
开发者ID:docker-java,项目名称:docker-java,代码行数:5,代码来源:DockerClientImpl.java
示例19: execute0
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
protected Void execute0(BuildImageCmd command, ResultCallback<BuildResponseItem> resultCallback) {
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.getTags() != null && !command.getTags().isEmpty()) {
webTarget = webTarget.queryParamsSet("t", command.getTags());
} else if (isNotBlank(command.getTag())) {
webTarget = webTarget.queryParam("t", command.getTag());
}
if (command.getCacheFrom() != null && !command.getCacheFrom().isEmpty()) {
webTarget = webTarget.queryParamsSet("cachefrom", command.getCacheFrom());
}
if (command.getRemote() != null) {
webTarget = webTarget.queryParam("remote", command.getRemote().toString());
}
webTarget = booleanQueryParam(webTarget, "q", command.isQuiet());
webTarget = booleanQueryParam(webTarget, "nocache", command.hasNoCacheEnabled());
webTarget = booleanQueryParam(webTarget, "pull", command.hasPullEnabled());
webTarget = booleanQueryParam(webTarget, "rm", command.hasRemoveEnabled());
webTarget = booleanQueryParam(webTarget, "forcerm", command.isForcerm());
// this has to be handled differently as it should switch to 'false'
if (command.hasRemoveEnabled() == null || !command.hasRemoveEnabled()) {
webTarget = webTarget.queryParam("rm", "false");
}
if (command.getMemory() != null) {
webTarget = webTarget.queryParam("memory", command.getMemory());
}
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());
}
if (command.getBuildArgs() != null) {
webTarget = webTarget.queryParamsJsonMap("buildargs", command.getBuildArgs());
}
if (command.getShmsize() != null) {
webTarget = webTarget.queryParam("shmsize", command.getShmsize());
}
if (command.getLabels() != null) {
webTarget = webTarget.queryParamsJsonMap("labels", command.getLabels());
}
LOGGER.trace("POST: {}", webTarget);
InvocationBuilder builder = resourceWithOptionalAuthConfig(command, webTarget.request())
.accept(MediaType.APPLICATION_JSON)
.header("Content-Type", "application/tar")
.header("encoding", "gzip");
builder.post(new TypeReference<BuildResponseItem>() {
}, resultCallback, command.getTarInputStream());
return null;
}
开发者ID:docker-java,项目名称:docker-java,代码行数:73,代码来源:BuildImageCmdExec.java
示例20: withTags
import com.github.dockerjava.api.command.BuildImageCmd; //导入依赖的package包/类
@Override
public BuildImageCmd withTags(Set<String> tags) {
this.tags = tags;
return this;
}
开发者ID:docker-java,项目名称:docker-java,代码行数:6,代码来源:BuildImageCmdImpl.java
注:本文中的com.github.dockerjava.api.command.BuildImageCmd类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论