Search in sources :

Example 6 with DockerImageName

use of org.testcontainers.utility.DockerImageName in project testcontainers-java by testcontainers.

the class AuthDelegatingDockerClientConfig method effectiveAuthConfig.

@Override
public AuthConfig effectiveAuthConfig(String imageName) {
    // allow docker-java auth config to be used as a fallback
    AuthConfig fallbackAuthConfig;
    try {
        fallbackAuthConfig = super.effectiveAuthConfig(imageName);
    } catch (Exception e) {
        log.debug("Delegate call to effectiveAuthConfig failed with cause: '{}'. " + "Resolution of auth config will continue using RegistryAuthLocator.", e.getMessage());
        fallbackAuthConfig = new AuthConfig();
    }
    // try and obtain more accurate auth config using our resolution
    final DockerImageName parsed = DockerImageName.parse(imageName);
    final AuthConfig effectiveAuthConfig = RegistryAuthLocator.instance().lookupAuthConfig(parsed, fallbackAuthConfig);
    log.debug("Effective auth config [{}]", toSafeString(effectiveAuthConfig));
    return effectiveAuthConfig;
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) AuthConfig(com.github.dockerjava.api.model.AuthConfig)

Example 7 with DockerImageName

use of org.testcontainers.utility.DockerImageName in project drill by apache.

the class TestJdbcPluginWithClickhouse method initClickhouse.

@BeforeClass
public static void initClickhouse() throws Exception {
    startCluster(ClusterFixture.builder(dirTestWatcher));
    String osName = System.getProperty("os.name").toLowerCase();
    DockerImageName imageName;
    if (osName.startsWith("linux") && "aarch64".equals(System.getProperty("os.arch"))) {
        imageName = DockerImageName.parse(DOCKER_IMAGE_CLICKHOUSE_ARM).asCompatibleSubstituteFor("yandex/clickhouse-server");
    } else {
        imageName = DockerImageName.parse(DOCKER_IMAGE_CLICKHOUSE_X86);
    }
    jdbcContainer = new ClickHouseContainer(imageName).withInitScript("clickhouse-test-data.sql");
    jdbcContainer.start();
    JdbcStorageConfig jdbcStorageConfig = new JdbcStorageConfig("ru.yandex.clickhouse.ClickHouseDriver", jdbcContainer.getJdbcUrl(), jdbcContainer.getUsername(), null, true, false, null, null, 0);
    jdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("clickhouse", jdbcStorageConfig);
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) ClickHouseContainer(org.testcontainers.containers.ClickHouseContainer) BeforeClass(org.junit.BeforeClass)

Example 8 with DockerImageName

use of org.testcontainers.utility.DockerImageName in project drill by apache.

the class TestJdbcPluginWithMySQLIT method initMysql.

@BeforeClass
public static void initMysql() throws Exception {
    startCluster(ClusterFixture.builder(dirTestWatcher));
    String osName = System.getProperty("os.name").toLowerCase();
    String mysqlDBName = "drill_mysql_test";
    DockerImageName imageName;
    if (osName.startsWith("linux") && "aarch64".equals(System.getProperty("os.arch"))) {
        imageName = DockerImageName.parse(DOCKER_IMAGE_MARIADB).asCompatibleSubstituteFor("mysql");
    } else {
        imageName = DockerImageName.parse(DOCKER_IMAGE_MYSQL);
    }
    jdbcContainer = new MySQLContainer<>(imageName).withExposedPorts(3306).withConfigurationOverride("mysql_config_override").withUsername("mysqlUser").withPassword("mysqlPass").withDatabaseName(mysqlDBName).withUrlParam("serverTimezone", "UTC").withUrlParam("useJDBCCompliantTimezoneShift", "true").withInitScript("mysql-test-data.sql");
    jdbcContainer.start();
    if (osName.startsWith("linux")) {
        JdbcDatabaseDelegate databaseDelegate = new JdbcDatabaseDelegate(jdbcContainer, "");
        ScriptUtils.runInitScript(databaseDelegate, "mysql-test-data-linux.sql");
    }
    String jdbcUrl = jdbcContainer.getJdbcUrl();
    JdbcStorageConfig jdbcStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), false, false, null, null, 10000);
    jdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("mysql", jdbcStorageConfig);
    if (osName.startsWith("linux")) {
        // adds storage plugin with case insensitive table names
        JdbcStorageConfig jdbcCaseSensitiveStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), true, false, null, null, 10000);
        jdbcCaseSensitiveStorageConfig.setEnabled(true);
        cluster.defineStoragePlugin("mysqlCaseInsensitive", jdbcCaseSensitiveStorageConfig);
    }
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) JdbcDatabaseDelegate(org.testcontainers.jdbc.JdbcDatabaseDelegate) BeforeClass(org.junit.BeforeClass)

Example 9 with DockerImageName

use of org.testcontainers.utility.DockerImageName in project testcontainers-java by testcontainers.

the class OutOfPackageImagePullPolicyTest method shouldSupportCustomPoliciesOutOfTestContainersPackage.

@Test
public void shouldSupportCustomPoliciesOutOfTestContainersPackage() {
    try (GenericContainer<?> container = new GenericContainer<>(TINY_IMAGE).withImagePullPolicy(new AbstractImagePullPolicy() {

        @Override
        protected boolean shouldPullCached(DockerImageName imageName, ImageData localImageData) {
            return false;
        }
    })) {
        container.withStartupCheckStrategy(new OneShotStartupCheckStrategy());
        container.start();
    }
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) ImageData(org.testcontainers.images.ImageData) AbstractImagePullPolicy(org.testcontainers.images.AbstractImagePullPolicy) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Example 10 with DockerImageName

use of org.testcontainers.utility.DockerImageName in project testcontainers-java by testcontainers.

the class ImagePullPolicyTest method shouldSupportCustomPolicies.

@Test
public void shouldSupportCustomPolicies() {
    try (// custom_image_pull_policy {
    GenericContainer<?> container = new GenericContainer<>(imageName).withImagePullPolicy(new AbstractImagePullPolicy() {

        @Override
        protected boolean shouldPullCached(DockerImageName imageName, ImageData localImageData) {
            return System.getenv("ALWAYS_PULL_IMAGE") != null;
        }
    })) // }
    {
        container.withStartupCheckStrategy(new OneShotStartupCheckStrategy());
        container.start();
    }
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Aggregations

DockerImageName (org.testcontainers.utility.DockerImageName)17 BeforeClass (org.junit.BeforeClass)5 IOException (java.io.IOException)3 Test (org.junit.Test)3 OneShotStartupCheckStrategy (org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy)3 Bind (com.github.dockerjava.api.model.Bind)2 Volume (com.github.dockerjava.api.model.Volume)2 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 Collectors (java.util.stream.Collectors)2 SneakyThrows (lombok.SneakyThrows)2 Logger (org.slf4j.Logger)2 GenericContainer (org.testcontainers.containers.GenericContainer)2 PostgreSQLContainer (org.testcontainers.containers.PostgreSQLContainer)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)1