Skip to content

Commit

Permalink
Accept image names with library/ prefix as a valid substitute
Browse files Browse the repository at this point in the history
Docker official images can be pulled with or without `library/`
prefix as part of the image name. For example, `mysql` or
`library/mysql`. This is explicit when using private repositories.
  • Loading branch information
eddumelendez committed Nov 14, 2022
1 parent 3280fda commit 9f694e1
Show file tree
Hide file tree
Showing 31 changed files with 92 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static Map<String, String> markerLabels() {
return Collections.unmodifiableMap(labels);
}

private static final DockerImageName TINY_IMAGE = DockerImageName.parse("alpine:3.16");
private static final DockerImageName TINY_IMAGE = DockerImageName.parse("library/alpine:3.16");

private static DockerClientFactory instance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class CassandraContainer<SELF extends CassandraContainer<SELF>> extends G

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("cassandra");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/cassandra");

private static final String DEFAULT_TAG = "3.11.2";

@Deprecated
Expand Down Expand Up @@ -64,7 +66,7 @@ public CassandraContainer(String dockerImageName) {

public CassandraContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

addExposedPort(CQL_PORT);
this.enableJmxReporting = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Slf4j
public class CassandraContainerTest {

private static final DockerImageName CASSANDRA_IMAGE = DockerImageName.parse("cassandra:3.11.2");
private static final DockerImageName CASSANDRA_IMAGE = DockerImageName.parse("library/cassandra:3.11.2");

private static final String TEST_CLUSTER_NAME_IN_CONF = "Test Cluster Integration Test";

Expand Down Expand Up @@ -88,7 +88,7 @@ public void testInitScript() {
public void testInitScriptWithLegacyCassandra() {
try (
CassandraContainer<?> cassandraContainer = new CassandraContainer<>(
DockerImageName.parse("cassandra:2.2.11")
DockerImageName.parse("library/cassandra:2.2.11")
)
.withInitScript("initial.cql")
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class CassandraDriver3Test {

@Rule
public CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2");
public CassandraContainer<?> cassandra = new CassandraContainer<>("library/cassandra:3.11.2");

@Test
public void testCassandraGetContactPoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class CassandraDriver4Test {

@Rule
public CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2");
public CassandraContainer<?> cassandra = new CassandraContainer<>("library/cassandra:3.11.2");

@Test
public void testCassandraGetContactPoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ConsulContainer extends GenericContainer<ConsulContainer> {

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("consul");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/consul");

private static final int CONSUL_HTTP_PORT = 8500;

private static final int CONSUL_GRPC_PORT = 8502;
Expand All @@ -33,7 +35,7 @@ public ConsulContainer(String dockerImageName) {

public ConsulContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

// Use the status leader endpoint to verify if consul is running.
setWaitStrategy(Wait.forHttp("/v1/status/leader").forPort(CONSUL_HTTP_PORT).forStatusCode(200));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.testcontainers.utility.DockerImageName;

public interface ConsulTestImages {
DockerImageName CONSUL_IMAGE = DockerImageName.parse("consul:1.10.12");
DockerImageName CONSUL_IMAGE = DockerImageName.parse("library/consul:1.10.12");
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class InfluxDBContainer<SELF extends InfluxDBContainer<SELF>> extends Gen

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("influxdb");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/influxdb");

private static final String DEFAULT_TAG = "1.4.3";

@Deprecated
Expand Down Expand Up @@ -53,7 +55,7 @@ public InfluxDBContainer(final String version) {

public InfluxDBContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

waitStrategy =
new WaitAllStrategy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.testcontainers.utility.DockerImageName;

public interface InfluxDBTestImages {
DockerImageName INFLUXDB_TEST_IMAGE = DockerImageName.parse("influxdb:1.4.3");
DockerImageName INFLUXDB_TEST_IMAGE = DockerImageName.parse("library/influxdb:1.4.3");
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class MariaDBContainer<SELF extends MariaDBContainer<SELF>> extends JdbcD

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("mariadb");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/mariadb");

@Deprecated
public static final String DEFAULT_TAG = "10.3.6";

Expand Down Expand Up @@ -52,7 +54,7 @@ public MariaDBContainer(String dockerImageName) {

public MariaDBContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

addExposedPort(MARIADB_PORT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.testcontainers.utility.DockerImageName;

public interface MariaDBTestImages {
DockerImageName MARIADB_IMAGE = DockerImageName.parse("mariadb:10.3.6");
DockerImageName MARIADB_IMAGE = DockerImageName.parse("library/mariadb:10.3.6");
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class MongoDBContainer extends GenericContainer<MongoDBContainer> {

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("mongo");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/mongo");

private static final String DEFAULT_TAG = "4.0.10";

private static final int CONTAINER_EXIT_CODE_OK = 0;
Expand All @@ -43,7 +45,7 @@ public MongoDBContainer(@NonNull final String dockerImageName) {

public MongoDBContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

withExposedPorts(MONGODB_INTERNAL_PORT);
withCommand("--replSet", "docker-rs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class MongoDBContainerTest {
public void shouldExecuteTransactions() {
try (
// creatingMongoDBContainer {
final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10"))
final MongoDBContainer mongoDBContainer = new MongoDBContainer(
DockerImageName.parse("library/mongo:4.0.10")
)
// }
) {
// startingMongoDBContainer {
Expand Down Expand Up @@ -88,14 +90,20 @@ private void executeTx(MongoDBContainer mongoDBContainer) {

@Test
public void supportsMongoDB_4_4() {
try (final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.4"))) {
try (
final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("library/mongo:4.4"))
) {
mongoDBContainer.start();
}
}

@Test
public void shouldTestDatabaseName() {
try (final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10"))) {
try (
final MongoDBContainer mongoDBContainer = new MongoDBContainer(
DockerImageName.parse("library/mongo:4.0.10")
)
) {
mongoDBContainer.start();
final String databaseName = "my-db";
assertThat(mongoDBContainer.getReplicaSetUrl(databaseName)).endsWith(databaseName);
Expand All @@ -104,7 +112,7 @@ public void shouldTestDatabaseName() {

@Test
public void supportsMongoDB_6() {
try (final MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.1")) {
try (final MongoDBContainer mongoDBContainer = new MongoDBContainer("library/mongo:6.0.1")) {
mongoDBContainer.start();
executeTx(mongoDBContainer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class MySQLContainer<SELF extends MySQLContainer<SELF>> extends JdbcDatab

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("mysql");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/mysql");

@Deprecated
public static final String DEFAULT_TAG = "5.7.34";

Expand Down Expand Up @@ -50,7 +52,7 @@ public MySQLContainer(String dockerImageName) {

public MySQLContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

addExposedPort(MYSQL_PORT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

public class MySQLTestImages {

public static final DockerImageName MYSQL_56_IMAGE = DockerImageName.parse("mysql:5.6.51");
public static final DockerImageName MYSQL_56_IMAGE = DockerImageName.parse("library/mysql:5.6.51");

public static final DockerImageName MYSQL_57_IMAGE = DockerImageName.parse("mysql:5.7.34");
public static final DockerImageName MYSQL_57_IMAGE = DockerImageName.parse("library/mysql:5.7.34");

public static final DockerImageName MYSQL_80_IMAGE = DockerImageName.parse("mysql:8.0.24");
public static final DockerImageName MYSQL_80_IMAGE = DockerImageName.parse("library/mysql:8.0.24");
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Neo4jContainer<S extends Neo4jContainer<S>> extends GenericContaine
*/
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("neo4j");

private static final DockerImageName LIBRARY_IMAGE_NAME = DockerImageName.parse("library/neo4j");

/**
* The default tag (version) to use.
*/
Expand Down Expand Up @@ -91,9 +93,11 @@ public Neo4jContainer(String dockerImageName) {
*/
public Neo4jContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
this.standardImage = dockerImageName.getUnversionedPart().equals(DEFAULT_IMAGE_NAME.getUnversionedPart());
this.standardImage =
dockerImageName.getUnversionedPart().equals(DEFAULT_IMAGE_NAME.getUnversionedPart()) ||
dockerImageName.getUnversionedPart().equals(LIBRARY_IMAGE_NAME.getUnversionedPart());

dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, LIBRARY_IMAGE_NAME);

WaitStrategy waitForBolt = new LogMessageWaitStrategy()
.withRegEx(String.format(".*Bolt enabled on .*:%d\\.\n", DEFAULT_BOLT_PORT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class Neo4jContainerJUnitIntegrationTest {

@ClassRule
public static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4");
public static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4");

@Test
public void shouldStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void shouldDisableAuthentication() {
try (
// spotless:off
// withoutAuthentication {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withoutAuthentication()
// }
// spotless:on
Expand All @@ -47,7 +47,7 @@ public void shouldDisableAuthentication() {
public void shouldCopyDatabase() {
try (
// copyDatabase {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:3.5.30")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:3.5.30")
.withDatabase(MountableFile.forClasspathResource("/test-graph.db"))
// }
) {
Expand All @@ -71,7 +71,8 @@ public void shouldFailOnCopyDatabaseForDefaultNeo4j4Image() {
public void shouldFailOnCopyDatabaseForCustomNeo4j4Image() {
assertThatIllegalArgumentException()
.isThrownBy(() -> {
new Neo4jContainer<>("neo4j:4.4.1").withDatabase(MountableFile.forClasspathResource("/test-graph.db"));
new Neo4jContainer<>("library/neo4j:4.4.1")
.withDatabase(MountableFile.forClasspathResource("/test-graph.db"));
})
.withMessage("Copying database folder is not supported for Neo4j instances with version 4.0 or higher.");
}
Expand All @@ -80,7 +81,8 @@ public void shouldFailOnCopyDatabaseForCustomNeo4j4Image() {
public void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() {
assertThatIllegalArgumentException()
.isThrownBy(() -> {
new Neo4jContainer<>("neo4j:latest").withDatabase(MountableFile.forClasspathResource("/test-graph.db"));
new Neo4jContainer<>("library/neo4j:latest")
.withDatabase(MountableFile.forClasspathResource("/test-graph.db"));
})
.withMessage("Copying database folder is not supported for Neo4j instances with version 4.0 or higher.");
}
Expand All @@ -89,7 +91,7 @@ public void shouldFailOnCopyDatabaseForCustomNonSemverNeo4j4Image() {
public void shouldCopyPlugins() {
try (
// registerPluginsPath {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withPlugins(MountableFile.forClasspathResource("/custom-plugins"))
// }
) {
Expand All @@ -104,7 +106,7 @@ public void shouldCopyPlugins() {
public void shouldCopyPlugin() {
try (
// registerPluginsJar {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withPlugins(MountableFile.forClasspathResource("/custom-plugins/hello-world.jar"))
// }
) {
Expand All @@ -129,7 +131,7 @@ public void shouldCheckEnterpriseLicense() {
String expectedImageName = "neo4j:4.4-enterprise";

assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> new Neo4jContainer<>("neo4j:4.4").withEnterpriseEdition())
.isThrownBy(() -> new Neo4jContainer<>("library/neo4j:4.4").withEnterpriseEdition())
.withMessageContaining("The image " + expectedImageName + " requires you to accept a license agreement.");
}

Expand All @@ -139,7 +141,7 @@ public void shouldRunEnterprise() {

try (
// enterpriseEdition {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withEnterpriseEdition()
// }
.withAdminPassword("Picard123")
Expand All @@ -159,7 +161,7 @@ public void shouldRunEnterprise() {
@Test
public void shouldAddConfigToEnvironment() {
// neo4jConfiguration {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withNeo4jConfig("dbms.security.procedures.unrestricted", "apoc.*,algo.*")
.withNeo4jConfig("dbms.tx_log.rotation.size", "42M");
// }
Expand All @@ -172,7 +174,8 @@ public void shouldAddConfigToEnvironment() {
@Test
public void shouldConfigureSingleLabsPlugin() {
try (
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4").withLabsPlugins(Neo4jLabsPlugin.APOC)
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withLabsPlugins(Neo4jLabsPlugin.APOC)
) {
// needs to get called explicitly for setup
neo4jContainer.configure();
Expand All @@ -185,7 +188,7 @@ public void shouldConfigureSingleLabsPlugin() {
public void shouldConfigureMultipleLabsPlugins() {
try (
// configureLabsPlugins {
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withLabsPlugins(Neo4jLabsPlugin.APOC, Neo4jLabsPlugin.BLOOM);
// }
) {
Expand All @@ -199,7 +202,7 @@ public void shouldConfigureMultipleLabsPlugins() {

@Test
public void shouldConfigureSingleLabsPluginWithString() {
try (Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4").withLabsPlugins("myApoc")) {
try (Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4").withLabsPlugins("myApoc")) {
// needs to get called explicitly for setup
neo4jContainer.configure();

Expand All @@ -210,7 +213,8 @@ public void shouldConfigureSingleLabsPluginWithString() {
@Test
public void shouldConfigureMultipleLabsPluginsWithString() {
try (
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.4").withLabsPlugins("myApoc", "myBloom")
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("library/neo4j:4.4")
.withLabsPlugins("myApoc", "myBloom")
) {
// needs to get called explicitly for setup
neo4jContainer.configure();
Expand Down
Loading

0 comments on commit 9f694e1

Please sign in to comment.