本文整理汇总了Java中com.github.dockerjava.core.command.BuildImageResultCallback类的典型用法代码示例。如果您正苦于以下问题:Java BuildImageResultCallback类的具体用法?Java BuildImageResultCallback怎么用?Java BuildImageResultCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BuildImageResultCallback类属于com.github.dockerjava.core.command包,在下文中一共展示了BuildImageResultCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Override
protected String run() throws Exception {
AtomicReference<String> result = new AtomicReference<>();
BuildImageResultCallback callback =
new BuildImageResultCallback() {
@Override
public void onNext(BuildResponseItem item) {
result.set(item.getImageId());
super.onNext(item);
}
};
try (BuildImageResultCallback cmd = dockerClient.buildImageCmd(workingDirectory).withTag(imageName).exec(callback)) {
cmd.awaitImageId();
}
return result.get();
}
示例2: buildImage
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
private boolean buildImage(DockerfileRequest request, DockerfileResponse response) throws Exception {
logger.info(String.format("begin buildImage: %s", request));
try {
File dockerFileTemplate = new File(request.getDockerfileTemplateLocation());
String dockerfileContent = templateService.getContentFromTemplateFile(dockerFileTemplate, request.getDockerfileParams());
response.setDockerfileContent(dockerfileContent);
File dockerfile = FileUtil.write(request.getDockerfileLocation(), dockerfileContent);
String imageId = dockerClient.buildImageCmd(dockerfile).withTag(buildImageTag(request)).exec(new BuildImageResultCallback()).awaitImageId();
response.setImageId(imageId);
response.success();
} catch (Exception e) {
response.fail(e.toString());
logger.error(String.format("error buildImage: %s", request), e);
}
logger.info(String.format("end buildImage: %s", response));
return response.isSuccess();
}
示例3: labels
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Test
public void labels() throws Exception {
assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_23));
File baseDir = fileFromBuildTestResource("labels");
String imageId = dockerRule.getClient().buildImageCmd(baseDir).withNoCache(true)
.withLabels(Collections.singletonMap("test", "abc"))
.exec(new BuildImageResultCallback())
.awaitImageId();
InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec();
assertThat(inspectImageResponse, not(nullValue()));
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
assertThat(inspectImageResponse.getConfig().getLabels().get("test"), equalTo("abc"));
}
示例4: multipleTags
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Test
public void multipleTags() throws Exception {
assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_21));
File baseDir = fileFromBuildTestResource("labels");
String imageId = dockerRule.getClient().buildImageCmd(baseDir).withNoCache(true)
.withTag("fallback-when-withTags-not-called")
.withTags(new HashSet<>(Arrays.asList("docker-java-test:tag1", "docker-java-test:tag2")))
.exec(new BuildImageResultCallback())
.awaitImageId();
InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec();
assertThat(inspectImageResponse, not(nullValue()));
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
assertThat(inspectImageResponse.getRepoTags().size(), equalTo(2));
assertThat(inspectImageResponse.getRepoTags(), containsInAnyOrder("docker-java-test:tag1", "docker-java-test:tag2"));
}
示例5: cacheFrom
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Test
public void cacheFrom() throws Exception {
assumeThat(dockerRule, isGreaterOrEqual(VERSION_1_27));
File baseDir1 = fileFromBuildTestResource("CacheFrom/test1");
String imageId1 = dockerRule.getClient().buildImageCmd(baseDir1)
.exec(new BuildImageResultCallback())
.awaitImageId();
InspectImageResponse inspectImageResponse1 = dockerRule.getClient().inspectImageCmd(imageId1).exec();
assertThat(inspectImageResponse1, not(nullValue()));
File baseDir2 = fileFromBuildTestResource("CacheFrom/test2");
String cacheImage = String.format("[\"%s\"]", imageId1);
String imageId2 = dockerRule.getClient().buildImageCmd(baseDir2).withCacheFrom(new HashSet<>(Arrays.asList(cacheImage)))
.exec(new BuildImageResultCallback())
.awaitImageId();
InspectImageResponse inspectImageResponse2 = dockerRule.getClient().inspectImageCmd(imageId2).exec();
assertThat(inspectImageResponse2, not(nullValue()));
// Compare whether the image2's parent layer is from image1 so that cache is used
assertThat(inspectImageResponse2.getParent(), equalTo(inspectImageResponse1.getId()));
}
示例6: buildImage
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
private String buildImage(DockerClient docker) {
BuildImageResultCallback resultCallback = new BuildImageResultCallback();
String dockerfile = "src/test/resources/conf/" + this.os + "/" + this.version
+ "/Dockerfile";
String tag = "spring-boot-it/" + this.os.toLowerCase() + ":" + this.version;
docker.buildImageCmd(new File(dockerfile)).withTag(tag).exec(resultCallback);
String imageId = resultCallback.awaitImageId();
return imageId;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:SysVinitLaunchScriptIT.java
示例7: buildImage
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Override
public void buildImage(File dockerfile, DockerImage image) {
try {
dockerClient.buildImageCmd(dockerfile).withTags(Collections.singleton(image.asString()))
.exec(new BuildImageResultCallback()).awaitImageId();
} catch (RuntimeException e) {
numberOfDockerDaemonFails.add();
throw new DockerException("Failed to build image " + image.asString(), e);
}
}
示例8: onBuild
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Test
public void onBuild() throws Exception {
File baseDir = fileFromBuildTestResource("ONBUILD/parent");
dockerRule.getClient().buildImageCmd(baseDir)
.withNoCache(true)
.withTag("docker-java-onbuild")
.exec(new BuildImageResultCallback())
.awaitImageId();
baseDir = fileFromBuildTestResource("ONBUILD/child");
String response = dockerfileBuild(baseDir);
assertThat(response, containsString("Successfully executed testrun.sh"));
}
示例9: execBuild
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的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());
}
示例10: buildArgs
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
@Test
public void buildArgs() throws Exception {
File baseDir = fileFromBuildTestResource("buildArgs");
String imageId = dockerRule.getClient().buildImageCmd(baseDir).withNoCache(true).withBuildArg("testArg", "abc")
.exec(new BuildImageResultCallback())
.awaitImageId();
InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec();
assertThat(inspectImageResponse, not(nullValue()));
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
assertThat(inspectImageResponse.getConfig().getLabels().get("test"), equalTo("abc"));
}
示例11: buildImage
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的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();
}
}
示例12: buildImage
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
private String buildImage() throws IOException, InterruptedException {
final AuthConfigurations auths = new AuthConfigurations();
final DockerRegistryEndpoint pullRegistry = getFromRegistry();
if (pullRegistry != null && pullRegistry.getCredentialsId() != null) {
auths.addConfig(DockerCloud.getAuthConfig(pullRegistry, run.getParent().getParent()));
}
final DockerClient client = getClient();
log("Docker Build: building image at path " + fpChild.getRemote());
final InputStream tar = fpChild.act(new DockerBuildCallable());
BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
public void onNext(BuildResponseItem item) {
String text = item.getStream();
if (text != null) {
listener.getLogger().println(text);
}
super.onNext(item);
}
};
String imageId = client.buildImageCmd(tar)
.withBuildAuthConfigs(auths)
.exec(resultCallback)
.awaitImageId();
if (imageId == null) {
throw new AbortException("Built image id is null. Some error accured");
}
// tag built image with tags
for (String tag : tagsToUse) {
final NameParser.ReposTag reposTag = NameParser.parseRepositoryTag(tag);
final String commitTag = isEmpty(reposTag.tag) ? "latest" : reposTag.tag;
log("Tagging built image with " + reposTag.repos + ":" + commitTag);
client.tagImageCmd(imageId, reposTag.repos, commitTag).withForce().exec();
}
return imageId;
}
示例13: resolve
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的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();
}
}
示例14: call
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的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();
}
示例15: buildImage
import com.github.dockerjava.core.command.BuildImageResultCallback; //导入依赖的package包/类
public String buildImage(File baseDir) throws Exception {
return getClient().buildImageCmd(baseDir)
.withNoCache(true)
.exec(new BuildImageResultCallback())
.awaitImageId();
}