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;
}
});
}
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();
}
}
Aggregations