Skip to content

Commit

Permalink
Update MySQL default images to latest
Browse files Browse the repository at this point in the history
- 5.6 went EOL in Feb 2021. Stop testing against it.
- 5.7 went EOL in Oct 2023. Retain tests for a bit, but stop using it as the default.
- 8.0.34+ is now LTS rather than rolling - use this as the default for most tests
- Add 8.3.0 as a candidate "innovation" version which will eventually become LTS

Updates various docs to use 8.0 in the examples rather than EOL 5.7.
  • Loading branch information
chadlwilson committed Jan 23, 2024
1 parent 12bf2f6 commit faefdd6
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 85 deletions.
2 changes: 1 addition & 1 deletion core/src/test/resources/compose-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
redis:
image: redis
db:
image: mysql:5.7.34
image: mysql:8.0.36
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "true"
2 changes: 1 addition & 1 deletion core/src/test/resources/composev2/compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ services:
redis:
image: redis
db:
image: mysql:8.0.33
image: mysql:8.0.36
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public void simpleExample() {
try (
// spotless:off
// directDockerHubReference {
// Referring directly to an image on Docker Hub (mysql:8.0.24)
// Referring directly to an image on Docker Hub (mysql:8.0.36)
final MySQLContainer<?> mysql = new MySQLContainer<>(
DockerImageName.parse("mysql:8.0.24")
DockerImageName.parse("mysql:8.0.36")
)
// start the container and use it for testing
// }
Expand All @@ -36,7 +36,7 @@ public void substitutedExample() {
// hardcodedMirror {
// Referring directly to an image on a private registry - image name will vary
final MySQLContainer<?> mysql = new MySQLContainer<>(
DockerImageName.parse("registry.mycompany.com/mirror/mysql:8.0.24")
DockerImageName.parse("registry.mycompany.com/mirror/mysql:8.0.36")
.asCompatibleSubstituteFor("mysql")
)
// start the container and use it for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TestSpecificImageNameSubstitutor extends ImageNameSubstitutor {

@Override
public DockerImageName apply(final DockerImageName original) {
if (original.equals(DockerImageName.parse("registry.mycompany.com/mirror/mysql:8.0.24"))) {
if (original.equals(DockerImageName.parse("registry.mycompany.com/mirror/mysql:8.0.36"))) {
return DockerImageName.parse("mysql");
} else {
return original;
Expand Down
2 changes: 1 addition & 1 deletion docs/features/image_name_substitution.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Consider this if:

* Developers and CI machines need to use different image names. For example, developers are able to pull images from Docker Hub, but CI machines need to pull from a private registry
* Your private registry has copies of images from Docker Hub where the names are predictable, and just adding a prefix is enough.
For example, `registry.mycompany.com/mirror/mysql:8.0.24` can be derived from the original Docker Hub image name (`mysql:8.0.24`) with a consistent prefix string: `registry.mycompany.com/mirror/`
For example, `registry.mycompany.com/mirror/mysql:8.0.36` can be derived from the original Docker Hub image name (`mysql:8.0.36`) with a consistent prefix string: `registry.mycompany.com/mirror/`

In this case, image name references in code are **unchanged**.
i.e. you would leave as-is:
Expand Down
2 changes: 1 addition & 1 deletion docs/features/reuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ GenericContainer container = new GenericContainer("redis:6-alpine")
### Reusable Container with Testcontainers JDBC URL

If using the [Testcontainers JDBC URL support](../../modules/databases/jdbc#database-containers-launched-via-jdbc-url-scheme)
the URL **must** follow the pattern of `jdbc:tc:mysql:5.7.34:///databasename?TC_REUSABLE=true`.
the URL **must** follow the pattern of `jdbc:tc:mysql:8.0.36:///databasename?TC_REUSABLE=true`.
`TC_REUSABLE=true` is set as a parameter of the JDBC URL.
12 changes: 6 additions & 6 deletions docs/modules/databases/jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database

!!! note
We will use `///` (host-less URIs) from now on to emphasis the unimportance of the `host:port` pair.
From Testcontainers' perspective, `jdbc:mysql:5.7.34://localhost:3306/databasename` and `jdbc:mysql:5.7.34:///databasename` is the same URI.
From Testcontainers' perspective, `jdbc:mysql:8.0.36://localhost:3306/databasename` and `jdbc:mysql:8.0.36:///databasename` is the same URI.

!!! warning
If you're using the JDBC URL support, there is no need to instantiate an instance of the container - Testcontainers will do it automagically.
Expand Down Expand Up @@ -49,7 +49,7 @@ Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database

#### Using MySQL

`jdbc:tc:mysql:5.7.34:///databasename`
`jdbc:tc:mysql:8.0.36:///databasename`

#### Using MSSQL Server

Expand Down Expand Up @@ -92,21 +92,21 @@ Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database

Testcontainers can run an init script after the database container is started, but before your code is given a connection to it. The script must be on the classpath, and is referenced as follows:

`jdbc:tc:mysql:5.7.34:///databasename?TC_INITSCRIPT=somepath/init_mysql.sql`
`jdbc:tc:mysql:8.0.36:///databasename?TC_INITSCRIPT=somepath/init_mysql.sql`

This is useful if you have a fixed script for setting up database schema, etc.

### Using an init script from a file

If the init script path is prefixed `file:`, it will be loaded from a file (relative to the working directory, which will usually be the project root).

`jdbc:tc:mysql:5.7.34:///databasename?TC_INITSCRIPT=file:src/main/resources/init_mysql.sql`
`jdbc:tc:mysql:8.0.36:///databasename?TC_INITSCRIPT=file:src/main/resources/init_mysql.sql`

### Using an init function

Instead of running a fixed script for DB setup, it may be useful to call a Java function that you define. This is intended to allow you to trigger database schema migration tools. To do this, add TC_INITFUNCTION to the URL as follows, passing a full path to the class name and method:

`jdbc:tc:mysql:5.7.34:///databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction`
`jdbc:tc:mysql:8.0.36:///databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction`

The init function must be a public static method which takes a `java.sql.Connection` as its only parameter, e.g.
```java
Expand All @@ -121,7 +121,7 @@ public class JDBCDriverTest {

By default database container is being stopped as soon as last connection is closed. There are cases when you might need to start container and keep it running till you stop it explicitly or JVM is shutdown. To do this, add `TC_DAEMON` parameter to the URL as follows:

`jdbc:tc:mysql:5.7.34:///databasename?TC_DAEMON=true`
`jdbc:tc:mysql:8.0.36:///databasename?TC_DAEMON=true`

With this parameter database container will keep running even when there're no open connections.
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/databases/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ See [Database containers](./index.md) for documentation and usage that is common
For MySQL databases, it is possible to override configuration settings using resources on the classpath. Assuming `somepath/mysql_conf_override`
is a directory on the classpath containing .cnf files, the following URL can be used:

`jdbc:tc:mysql:5.7.34://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override`
`jdbc:tc:mysql:8.0.36://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override`

Any .cnf files in this classpath directory will be mapped into the database container's /etc/mysql/conf.d directory,
and will be able to override server settings when the container starts.
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/databases/r2dbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The started container will be terminated when the `ConnectionFactory` is closed.
**Note that, unlike Testcontainers' JDBC URL support, it is not possible to specify an image tag in the 'scheme' part of the URL, and it is always necessary to specify a tag using `TC_IMAGE_TAG`.**

So that the URL becomes:
`r2dbc:tc:mysql:///databasename?TC_IMAGE_TAG=5.7.34`
`r2dbc:tc:mysql:///databasename?TC_IMAGE_TAG=8.0.36`

!!! note
We will use `///` (host-less URIs) from now on to emphasis the unimportance of the `host:port` pair.
Expand All @@ -35,7 +35,7 @@ So that the URL becomes:

#### Using MySQL

`r2dbc:tc:mysql:///databasename?TC_IMAGE_TAG=5.7.34`
`r2dbc:tc:mysql:///databasename?TC_IMAGE_TAG=8.0.36`

#### Using MariaDB

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ private HikariDataSource verifyCharacterSet(String jdbcUrl) throws SQLException
private void performTestForCustomIniFile(HikariDataSource dataSource) throws SQLException {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
Statement statement = dataSource.getConnection().createStatement();
statement.execute("SELECT @@GLOBAL.innodb_file_format");
statement.execute("SELECT @@GLOBAL.innodb_max_undo_log_size");
ResultSet resultSet = statement.getResultSet();

assertThat(resultSet.next()).as("The query returns a result").isTrue();
String result = resultSet.getString(1);
long result = resultSet.getLong(1);

assertThat(result).as("The InnoDB file format has been set by the ini file content").isEqualTo("Barracuda");
assertThat(result).as("The InnoDB max undo log size has been set by the ini file content").isEqualTo(2000000);
}

private HikariDataSource getDataSource(String jdbcUrl, int poolSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ConnectionUrlDriversTests {
public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][] {
{ "jdbc:tc:mysql:5.7.34://hostname/test", "mysql", Optional.of("5.7.34"), "hostname/test", "test" },
{ "jdbc:tc:mysql:8.0.36://hostname/test", "mysql", Optional.of("8.0.36"), "hostname/test", "test" },
{ "jdbc:tc:mysql://hostname/test", "mysql", Optional.empty(), "hostname/test", "test" },
{
"jdbc:tc:postgresql:1.2.3://hostname/test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ConnectionUrlTest {

@Test
public void testConnectionUrl1() {
String urlString = "jdbc:tc:mysql:5.7.34://somehostname:3306/databasename?a=b&c=d";
String urlString = "jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.getDatabaseType()).as("Database Type value is as expected").isEqualTo("mysql");
assertThat(url.getImageTag()).as("Database Image tag value is as expected").contains("5.7.34");
assertThat(url.getImageTag()).as("Database Image tag value is as expected").contains("8.0.36");
assertThat(url.getDbHostString())
.as("Database Host String is as expected")
.isEqualTo("somehostname:3306/databasename");
Expand Down Expand Up @@ -71,7 +71,7 @@ public void testTmpfsOption() {
@Test
public void testInitScriptPathCapture() {
String urlString =
"jdbc:tc:mysql:5.7.34://somehostname:3306/databasename?a=b&c=d&TC_INITSCRIPT=somepath/init_mysql.sql";
"jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d&TC_INITSCRIPT=somepath/init_mysql.sql";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.getInitScriptPath())
Expand All @@ -91,7 +91,7 @@ public void testInitScriptPathCapture() {
@Test
public void testInitFunctionCapture() {
String urlString =
"jdbc:tc:mysql:5.7.34://somehostname:3306/databasename?a=b&c=d&TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction";
"jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d&TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.getInitFunction()).as("Init Function parameter exists").isPresent();
Expand All @@ -106,7 +106,7 @@ public void testInitFunctionCapture() {

@Test
public void testDaemonCapture() {
String urlString = "jdbc:tc:mysql:5.7.34://somehostname:3306/databasename?a=b&c=d&TC_DAEMON=true";
String urlString = "jdbc:tc:mysql:8.0.36://somehostname:3306/databasename?a=b&c=d&TC_DAEMON=true";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.isInDaemonMode()).as("Daemon flag is set to true.").isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static class MissingDriverContainer extends JdbcDatabaseContainer {
private final AtomicInteger connectionAttempts = new AtomicInteger();

MissingDriverContainer() {
super(DockerImageName.parse("mysql:5.7.34"));
super(DockerImageName.parse("mysql:8.0.36"));
withEnv("MYSQL_ROOT_PASSWORD", "test");
withExposedPorts(3306);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MySQLContainer<SELF extends MySQLContainer<SELF>> extends JdbcDatab
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("mysql");

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

@Deprecated
public static final String IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart();
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_57_IMAGE = DockerImageName.parse("mysql:5.7.44");

public static final DockerImageName MYSQL_57_IMAGE = DockerImageName.parse("mysql:5.7.34");
public static final DockerImageName MYSQL_80_IMAGE = DockerImageName.parse("mysql:8.0.36");

public static final DockerImageName MYSQL_80_IMAGE = DockerImageName.parse("mysql:8.0.24");
public static final DockerImageName MYSQL_INNOVATION_IMAGE = DockerImageName.parse("mysql:8.3.0");
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public class MySQLRootAccountTest {

@Parameterized.Parameters(name = "{0}")
public static DockerImageName[] params() {
return new DockerImageName[] { MySQLTestImages.MYSQL_80_IMAGE, MySQLTestImages.MYSQL_57_IMAGE };
return new DockerImageName[] {
MySQLTestImages.MYSQL_57_IMAGE,
MySQLTestImages.MYSQL_80_IMAGE,
MySQLTestImages.MYSQL_INNOVATION_IMAGE,
};
}

@Parameterized.Parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class JDBCDriverWithPoolTest {

public static final String URL =
"jdbc:tc:mysql:5.7.34://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.mysql.JDBCDriverWithPoolTest::sampleInitFunction";
"jdbc:tc:mysql:8.0.36://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.mysql.JDBCDriverWithPoolTest::sampleInitFunction";

private final DataSource dataSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MySQLDatabaseContainerDriverTest {
@Test
public void shouldRespectBothUrlPropertiesAndParameterProperties() throws SQLException {
ContainerDatabaseDriver driver = new ContainerDatabaseDriver();
String url = "jdbc:tc:mysql:5.7.22://hostname/databasename?padCharsWithSpace=true";
String url = "jdbc:tc:mysql:8.0.36://hostname/databasename?padCharsWithSpace=true";
Properties properties = new Properties();
properties.setProperty("maxRows", "1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ public static Iterable<Object[]> data() {
EnumSet.of(Options.ScriptedSchema, Options.JDBCParams),
},
{
"jdbc:tc:mysql:5.7.34://hostname/databasename?user=someuser&TC_INITFUNCTION=org.testcontainers.jdbc.AbstractJDBCDriverTest::sampleInitFunction",
"jdbc:tc:mysql:8.0.36://hostname/databasename?user=someuser&TC_INITFUNCTION=org.testcontainers.jdbc.AbstractJDBCDriverTest::sampleInitFunction",
EnumSet.of(Options.ScriptedSchema, Options.JDBCParams),
},
{
"jdbc:tc:mysql:5.7.34://hostname/databasename?user=someuser&password=somepwd&TC_INITSCRIPT=somepath/init_mysql.sql",
"jdbc:tc:mysql:8.0.36://hostname/databasename?user=someuser&password=somepwd&TC_INITSCRIPT=somepath/init_mysql.sql",
EnumSet.of(Options.ScriptedSchema, Options.JDBCParams),
},
{
"jdbc:tc:mysql:5.7.34://hostname/databasename?user=someuser&password=somepwd&TC_INITSCRIPT=file:sql/init_mysql.sql",
"jdbc:tc:mysql:8.0.36://hostname/databasename?user=someuser&password=somepwd&TC_INITSCRIPT=file:sql/init_mysql.sql",
EnumSet.of(Options.ScriptedSchema, Options.JDBCParams),
},
{
"jdbc:tc:mysql:5.7.34://hostname/databasename?user=someuser&password=somepwd&TC_INITFUNCTION=org.testcontainers.jdbc.AbstractJDBCDriverTest::sampleInitFunction",
"jdbc:tc:mysql:8.0.36://hostname/databasename?user=someuser&password=somepwd&TC_INITFUNCTION=org.testcontainers.jdbc.AbstractJDBCDriverTest::sampleInitFunction",
EnumSet.of(Options.ScriptedSchema, Options.JDBCParams),
},
{
"jdbc:tc:mysql:5.7.34://hostname/databasename?TC_INITSCRIPT=somepath/init_unicode_mysql.sql&useUnicode=yes&characterEncoding=utf8",
"jdbc:tc:mysql:8.0.36://hostname/databasename?TC_INITSCRIPT=somepath/init_unicode_mysql.sql&useUnicode=yes&characterEncoding=utf8",
EnumSet.of(Options.CharacterSet),
},
{ "jdbc:tc:mysql:5.7.34://hostname/databasename", EnumSet.noneOf(Options.class) },
{ "jdbc:tc:mysql:5.7.34://hostname/databasename?useSSL=false", EnumSet.noneOf(Options.class) },
{ "jdbc:tc:mysql:8.0.36://hostname/databasename", EnumSet.noneOf(Options.class) },
{ "jdbc:tc:mysql:8.0.36://hostname/databasename?useSSL=false", EnumSet.noneOf(Options.class) },
{
"jdbc:tc:mysql:5.6.51://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override",
"jdbc:tc:mysql:8.0.36://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override",
EnumSet.of(Options.CustomIniFile),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CustomizableMysqlTest extends AbstractContainerDatabaseTest {
public void testSimple() throws SQLException {
// Add MYSQL_ROOT_HOST environment so that we can root login from anywhere for testing purposes
try (
MySQLContainer<?> mysql = new MySQLContainer<>(MySQLTestImages.MYSQL_57_IMAGE)
MySQLContainer<?> mysql = new MySQLContainer<>(MySQLTestImages.MYSQL_80_IMAGE)
.withDatabaseName(DB_NAME)
.withUsername(USER)
.withPassword(PWD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class MultiVersionMySQLTest extends AbstractContainerDatabaseTest {
@Parameterized.Parameters(name = "{0}")
public static DockerImageName[] params() {
return new DockerImageName[] {
MySQLTestImages.MYSQL_56_IMAGE,
MySQLTestImages.MYSQL_57_IMAGE,
MySQLTestImages.MYSQL_80_IMAGE,
MySQLTestImages.MYSQL_INNOVATION_IMAGE,
};
}

Expand Down

0 comments on commit faefdd6

Please sign in to comment.