How to use prePullDependencyImages method of org.testcontainers.images.builder.ImageFromDockerfile class

Best Testcontainers-java code snippet using org.testcontainers.images.builder.ImageFromDockerfile.prePullDependencyImages

Source:ImageFromDockerfile.java Github

copy

Full Screen

...85 labels.putAll(buildImageCmd.getLabels());86 }87 labels.putAll(DockerClientFactory.DEFAULT_LABELS);88 buildImageCmd.withLabels(labels);89 prePullDependencyImages(dependencyImageNames);90 BuildImageResultCallback exec = buildImageCmd.exec(resultCallback);91 long bytesToDockerDaemon = 0;92 // To build an image, we have to send the context to Docker in TAR archive format93 try (TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(new GZIPOutputStream(out))) {94 tarArchive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);95 tarArchive.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);96 for (Map.Entry<String, Transferable> entry : transferables.entrySet()) {97 Transferable transferable = entry.getValue();98 final String destination = entry.getKey();99 transferable.transferTo(tarArchive, destination);100 bytesToDockerDaemon += transferable.getSize();101 }102 tarArchive.finish();103 }104 log.info("Transferred {} to Docker daemon", FileUtils.byteCountToDisplaySize(bytesToDockerDaemon));105 if (bytesToDockerDaemon > FileUtils.ONE_MB * 50) // warn if >50MB sent to docker daemon106 log.warn("A large amount of data was sent to the Docker daemon ({}). Consider using a .dockerignore file for better performance.",107 FileUtils.byteCountToDisplaySize(bytesToDockerDaemon));108 exec.awaitImageId();109 return dockerImageName;110 } catch(IOException e) {111 throw new RuntimeException("Can't close DockerClient", e);112 }113 }114 protected void configure(BuildImageCmd buildImageCmd) {115 buildImageCmd.withTag(this.getDockerImageName());116 this.dockerFilePath.ifPresent(buildImageCmd::withDockerfilePath);117 this.dockerfile.ifPresent(p -> {118 buildImageCmd.withDockerfile(p.toFile());119 dependencyImageNames = new ParsedDockerfile(p).getDependencyImageNames();120 if (dependencyImageNames.size() > 0) {121 // if we'll be pre-pulling images, disable the built-in pull as it is not necessary and will fail for122 // authenticated registries123 buildImageCmd.withPull(false);124 }125 });126 this.buildArgs.forEach(buildImageCmd::withBuildArg);127 }128 private void prePullDependencyImages(Set<String> imagesToPull) {129 final DockerClient dockerClient = DockerClientFactory.instance().client();130 imagesToPull.forEach(imageName -> {131 try {132 log.info("Pre-emptively checking local images for '{}', referenced via a Dockerfile. If not available, it will be pulled.", imageName);133 DockerClientFactory.instance().checkAndPullImage(dockerClient, imageName);134 } catch (Exception e) {135 log.warn("Unable to pre-fetch an image ({}) depended upon by Dockerfile - image build will continue but may fail. Exception message was: {}", imageName, e.getMessage());136 }137 });138 }139 public ImageFromDockerfile withBuildArg(final String key, final String value) {140 this.buildArgs.put(key, value);141 return this;142 }...

Full Screen

Full Screen

prePullDependencyImages

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.images.builder.ImageFromDockerfile2def image = new ImageFromDockerfile()3image.withDockerfileFromBuilder { dockerfile ->4 dockerfile.from('openjdk:8')5 dockerfile.run('apt-get update && apt-get install -y curl')6 dockerfile.run('apt-get update && apt-get install -y elasticsearch')7 dockerfile.run('update-rc.d elasticsearch defaults 95 10')8 dockerfile.run('service elasticsearch start')9}10image.prePullDependencyImages()11def container = image.run()12container.followOutput()13[elasticsearch] [2018-01-25T21:41:43,225][INFO ][o.e.e.NodeEnvironment ] [YbKdM4x] using [1] data paths, mounts [[/ (/dev/mapper/ubuntu--vg-ubuntu--lv)]], net usable_space [8.1gb], net total_space [9.8gb], types [

Full Screen

Full Screen

prePullDependencyImages

Using AI Code Generation

copy

Full Screen

1public static void prePullDependencyImages(String image, DockerClient dockerClient) throws IOException {2 DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder().build();3 DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()4 .dockerHost(config.getDockerHost())5 .sslConfig(config.getSSLConfig())6 .build();7 AuthConfig authConfig = config.getAuthConfig();8 try (ImageFromDockerfile imageFromDockerfile = new ImageFromDockerfile(image, false)) {9 for (String dependency : imageFromDockerfile.getDependencies()) {10 dockerClient.pullImageCmd(dependency).exec(new PullImageResultCallback()).awaitSuccess();11 }12 }13}

Full Screen

Full Screen

prePullDependencyImages

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.images.builder.ImageFromDockerfile2import org.testcontainers.utility.DockerImageName3def image = new ImageFromDockerfile()4 .withFileFromPath(".", project.file("src/main/docker"))5 .withFileFromPath(".", project.file("src/main/resources"))6 .withFileFromPath(".", project.file("build/libs/${project.name}-${project.version}.jar"))7 .withFileFromPath(".", project.file("build/resources/main"))8 .withFileFromPath(".", project.file("build/resources/test"))9 .withFileFromPath(".", project.file("build/generated-resources/main"))10 .withFileFromPath(".", project.file("build/generated-resources/test"))11 .withFileFromPath(".", project.file("build/classes/java/main"))

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful