Search in sources :

Example 1 with ImageFromDockerfile

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

the class DockerfileTest method dockerfileBuilderWorks.

@Test
public void dockerfileBuilderWorks() {
    ImageFromDockerfile image = new ImageFromDockerfile().withFileFromClasspath("test.txt", "mappable-resource/test-resource.txt").withFileFromString("folder/someFile.txt", "hello").withDockerfileFromBuilder(builder -> builder.from("alpine:3.2").workDir("/app").add("test.txt", "test file.txt").run("ls", "-la", "/app/test file.txt").copy("folder/someFile.txt", "/someFile.txt").expose(80, 8080).cmd("while true; do cat /someFile.txt | nc -l -p 80; done"));
    verifyImage(image);
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) Test(org.junit.Test)

Example 2 with ImageFromDockerfile

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

the class DirectoryTarResourceTest method simpleRecursiveFileTest.

@Test
public void simpleRecursiveFileTest() throws TimeoutException {
    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("cat /foo/src/test/resources/test-recursive-file.txt").build()).withFileFromFile("/tmp/foo", // '.' is expected to be the project base directory, so all source code/resources should be copied in
    new File("."))).withStartupCheckStrategy(new OneShotStartupCheckStrategy()).withLogConsumer(wait.andThen(toString));
    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);
    final String results = toString.toUtf8String();
    assertTrue("The container has a file that was copied in via a recursive copy", results.contains("Used for DirectoryTarResourceTest"));
}
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) File(java.io.File) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Example 3 with ImageFromDockerfile

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

the class DirectoryTarResourceTest method simpleRecursiveFileWithPermissionTest.

@Test
public void simpleRecursiveFileWithPermissionTest() throws TimeoutException {
    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", "-al", "/").build()).withFileFromFile("/tmp/foo", new File("/mappable-resource/test-resource.txt"), 0754)).withStartupCheckStrategy(new OneShotStartupCheckStrategy()).withLogConsumer(wait.andThen(toString));
    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);
    String listing = toString.toUtf8String();
    assertThat("Listing shows that file is copied with mode requested.", Arrays.asList(listing.split("\\n")), exactlyNItems(1, allOf(containsString("-rwxr-xr--"), containsString("foo"))));
}
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) File(java.io.File) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Example 4 with ImageFromDockerfile

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

the class DockerfileTest method simpleDockerfileWorks.

@Test
public void simpleDockerfileWorks() {
    ImageFromDockerfile image = new ImageFromDockerfile().withFileFromString("folder/someFile.txt", "hello").withFileFromClasspath("test.txt", "mappable-resource/test-resource.txt").withFileFromClasspath("Dockerfile", "mappable-dockerfile/Dockerfile");
    verifyImage(image);
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) Test(org.junit.Test)

Example 5 with ImageFromDockerfile

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

the class DockerfileTest method filePermissions.

@Test
public void filePermissions() throws TimeoutException {
    WaitingConsumer consumer = new WaitingConsumer();
    ImageFromDockerfile image = new ImageFromDockerfile().withFileFromTransferable("/someFile.txt", new Transferable() {

        @Override
        public long getSize() {
            return 0;
        }

        @Override
        public byte[] getBytes() {
            return new byte[0];
        }

        @Override
        public String getDescription() {
            return "test file";
        }

        @Override
        public int getFileMode() {
            return 0123;
        }
    }).withDockerfileFromBuilder(builder -> builder.from("alpine:3.2").copy("someFile.txt", "/someFile.txt").cmd("stat -c \"%a\" /someFile.txt"));
    GenericContainer container = new GenericContainer(image).withStartupCheckStrategy(new OneShotStartupCheckStrategy()).withLogConsumer(consumer);
    try {
        container.start();
        consumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("123"), 5, TimeUnit.SECONDS);
    } finally {
        container.stop();
    }
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) Transferable(org.testcontainers.images.builder.Transferable) 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