Java Code Examples for org.testcontainers.images.builder.ImageFromDockerfile#withFileFromFile()

The following examples show how to use org.testcontainers.images.builder.ImageFromDockerfile#withFileFromFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LibertyAdapter.java    From microshed-testing with Apache License 2.0 5 votes vote down vote up
@Override
    public ImageFromDockerfile getDefaultImage(File appFile) {
        final String appName = appFile.getName();
        final File configDir = new File("src/main/liberty/config");
        final boolean configDirExists = configDir.exists() && configDir.canRead();
        // Compose a docker image equivalent to doing:
        // FROM openliberty/open-liberty:full-java8-openj9-ubi
        // COPY src/main/liberty/config /config/
        // RUN configure.sh
        // ADD build/libs/<appFile> /config/dropins
        ImageFromDockerfile image = new ImageFromDockerfile()
                        .withDockerfileFromBuilder(builder -> {
                            builder.from(getBaseDockerImage());
                            if (configDirExists) {
                                builder.copy("/config", "/config");
                            }
//                            // Best practice is to run configure.sh after the app is added, but we will
//                            // run it before adding the app because due to how often the app changes while
//                            // running tests this will yeild the most overall time saved
                            // TODO: Cache does not work correctly when running the previous docker line
                            // which causes configure.sh to be run every time. See https://github.com/MicroShed/microshed-testing/issues/122
//                            builder.run("configure.sh");
                            builder.add("/config/dropins/" + appName, "/config/dropins/" + appName);
                            builder.build();
                        })
                        .withFileFromFile("/config/dropins/" + appName, appFile);
        if (configDirExists)
            image.withFileFromFile("/config", configDir);
        return image;
    }
 
Example 2
Source File: ElasticsearchWithPluginContainer.java    From elasticsearch-analysis-morfologik with Apache License 2.0 5 votes vote down vote up
private ImageFromDockerfile prepareImage(String imageName) {
    String pluginContainerPath = plugin == null ? null : ("/tmp/plugins/" + plugin.getName());
    ImageFromDockerfile image = new ImageFromDockerfile()
            .withDockerfileFromBuilder(builder -> {
                builder.from(imageName);
                if (pluginContainerPath != null) {
                    builder.copy(pluginContainerPath, pluginContainerPath);
                    builder.run("bin/elasticsearch-plugin", "install", "file://" + pluginContainerPath);
                }
            });
    if (pluginContainerPath != null) {
        image.withFileFromFile(pluginContainerPath, plugin);
    }
    return image;
}