Search in sources :

Example 6 with ImageFromDockerfile

use of org.testcontainers.images.builder.ImageFromDockerfile in project testcontainers-java by testcontainers.

the class DockerfileTest method customizableImage.

@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);
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) BuildImageCmd(com.github.dockerjava.api.command.BuildImageCmd) Test(org.junit.Test)

Example 7 with ImageFromDockerfile

use of org.testcontainers.images.builder.ImageFromDockerfile in project testcontainers-java by testcontainers.

the class DirectoryTarResourceTest method simpleRecursiveClasspathResourceTest.

@Test
public void simpleRecursiveClasspathResourceTest() throws TimeoutException {
    // This test combines the copying of classpath resources from JAR files with the recursive TAR approach, to allow JARed classpath resources to be copied in to an image
    WaitingConsumer wait = new WaitingConsumer();
    final ToStringConsumer toString = new ToStringConsumer();
    GenericContainer container = new GenericContainer(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder.from("alpine:3.3").copy("/tmp/foo", "/foo").cmd("ls -lRt /foo").build()).withFileFromClasspath("/tmp/foo", // here we use /org/junit as a directory that really should exist on the classpath
    "/recursive/dir")).withStartupCheckStrategy(new OneShotStartupCheckStrategy()).withLogConsumer(wait.andThen(toString));
    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);
    final String results = toString.toUtf8String();
    // ExternalResource.class is known to exist in a subdirectory of /org/junit so should be successfully copied in
    assertTrue("The container has a file that was copied in via a recursive copy from a JAR resource", results.contains("content.txt"));
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) ToStringConsumer(org.testcontainers.containers.output.ToStringConsumer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GenericContainer(org.testcontainers.containers.GenericContainer) WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 ImageFromDockerfile (org.testcontainers.images.builder.ImageFromDockerfile)7 GenericContainer (org.testcontainers.containers.GenericContainer)4 WaitingConsumer (org.testcontainers.containers.output.WaitingConsumer)4 OneShotStartupCheckStrategy (org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ToStringConsumer (org.testcontainers.containers.output.ToStringConsumer)3 File (java.io.File)2 BuildImageCmd (com.github.dockerjava.api.command.BuildImageCmd)1 Transferable (org.testcontainers.images.builder.Transferable)1