Search in sources :

Example 1 with Transferable

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

the class DockerfileTrait method withDockerfileFromBuilder.

default SELF withDockerfileFromBuilder(Consumer<DockerfileBuilder> builderConsumer) {
    DockerfileBuilder builder = new DockerfileBuilder();
    builderConsumer.accept(builder);
    // return Transferable because we want to build Dockerfile's content lazily
    return ((SELF) this).withFileFromTransferable("Dockerfile", new Transferable() {

        @Getter(lazy = true)
        private final byte[] bytes = builder.build().getBytes();

        @Override
        public long getSize() {
            return getBytes().length;
        }

        @Override
        public String getDescription() {
            return "Dockerfile: " + builder;
        }
    });
}
Also used : DockerfileBuilder(org.testcontainers.images.builder.dockerfile.DockerfileBuilder) Getter(lombok.Getter) Transferable(org.testcontainers.images.builder.Transferable)

Example 2 with Transferable

use of org.testcontainers.images.builder.Transferable 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

Transferable (org.testcontainers.images.builder.Transferable)2 Getter (lombok.Getter)1 Test (org.junit.Test)1 GenericContainer (org.testcontainers.containers.GenericContainer)1 WaitingConsumer (org.testcontainers.containers.output.WaitingConsumer)1 OneShotStartupCheckStrategy (org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy)1 ImageFromDockerfile (org.testcontainers.images.builder.ImageFromDockerfile)1 DockerfileBuilder (org.testcontainers.images.builder.dockerfile.DockerfileBuilder)1