Skip to content

Commit bead0b3

Browse files
authored
Pin tags (#671)
* Pin tags where it makes sense to do so * Update changelog and docs * Use fixed tag names for JDBC URLs when none specified (equivalent to current 'latest')
1 parent 67cde07 commit bead0b3

File tree

19 files changed

+85
-49
lines changed

19 files changed

+85
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
- Retry any exceptions (not just `DockerClientException`) on image pull ([\#662](https://github.com/testcontainers/testcontainers-java/issues/662))
88

99
### Changed
10+
- Database container images are now pinned to a specific version rather than using `latest`. The tags selected are the most recent as of the time of this change. If a JDBC URL is used with no tag specified, a WARN level log message is output, pending a future change to make tags mandatory in the JDBC URL. ([\#671](https://github.com/testcontainers/testcontainers-java/issues/671))
1011

1112
## [1.7.1] - 2018-04-20
1213

core/src/test/java/org/testcontainers/junit/wait/strategy/AbstractWaitStrategyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
public abstract class AbstractWaitStrategyTest<W extends WaitStrategy> {
2222
static final long WAIT_TIMEOUT_MILLIS = 3000;
23-
static final String IMAGE_NAME = "alpine:latest";
23+
static final String IMAGE_NAME = "alpine:3.7";
2424

2525
/**
2626
* Indicates that the WaitStrategy has completed waiting successfully.

core/src/test/java/org/testcontainers/junit/wait/strategy/HostPortWaitStrategyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
public class HostPortWaitStrategyTest {
1717

18-
private static final String IMAGE_NAME = "alpine:latest";
18+
private static final String IMAGE_NAME = "alpine:3.7";
1919

2020
@ClassRule
2121
public static GenericContainer container = new GenericContainer(IMAGE_NAME).withExposedPorts()

docs/usage/database_containers.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,40 @@ _N.B:_
5353
* _TC needs to be on your application's classpath at runtime for this to work_
5454
* _For Spring Boot you need to specify the driver manually `spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver`_
5555

56-
**Original URL**: `jdbc:mysql://somehostname:someport/databasename`
56+
**Original URL**: `jdbc:mysql:5.7.22://somehostname:someport/databasename`
5757

5858
Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database name will be ignored; you can leave these as-is or set them to any value.
5959

6060
### JDBC URL examples
6161

62-
#### Simple Testcontainers JDBC driver usage
62+
#### DEPRECATED: Simple Testcontainers JDBC driver usage
6363

6464
`jdbc:tc:mysql://somehostname:someport/databasename`
6565

66-
*(Note: this will use the latest version of MySQL)*
66+
*(Note: this will use a fixed version of the database. You should typically specify the version you desire via a tag parameter, as below).*
6767

6868
#### Using Testcontainers with a fixed version
6969

7070
`jdbc:tc:mysql:5.6.23://somehostname:someport/databasename`
7171

7272
#### Using PostgreSQL
7373

74-
`jdbc:tc:postgresql://hostname/databasename`
74+
`jdbc:tc:postgresql:9.6.8://hostname/databasename`
7575

7676

7777
## Using an init script
7878

7979
Testcontainers can run an initscript 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:
8080

81-
`jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql`
81+
`jdbc:tc:mysql:5.7.22://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql`
8282

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

8585
#### Using an init function
8686

8787
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:
8888

89-
`jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction`
89+
`jdbc:tc:mysql:5.7.22://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction`
9090

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

102102
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:
103103

104-
`jdbc:tc:mysql://hostname/databasename?TC_DAEMON=true`
104+
`jdbc:tc:mysql:5.7.22://hostname/databasename?TC_DAEMON=true`
105105

106106
With this parameter database container will keep running even when there're no open connections.
107107
@@ -114,12 +114,3 @@ is a directory on the classpath containing .cnf files, the following URL can be
114114
115115
Any .cnf files in this classpath directory will be mapped into the database container's /etc/mysql/conf.d directory,
116116
and will be able to override server settings when the container starts.
117-
118-
### Additional Non-standard Methods
119-
120-
#### Virtuoso SPARQL Service URL
121-
122-
VirtuosoContainer provides access to the SPARQL service URL
123-
```java
124-
String sparqlServiceUrl = ((VirtuosoContainer)container).getSparqlUrl();
125-
```

modules/jdbc-test/src/test/java/org/testcontainers/jdbc/DatabaseDriverShutdownTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void testCleanup() {
2323

2424
@Test
2525
public void shouldStopContainerWhenAllConnectionsClosed() throws SQLException {
26-
final String jdbcUrl = "jdbc:tc:postgresql://hostname/databasename";
26+
final String jdbcUrl = "jdbc:tc:postgresql:9.6.8://hostname/databasename";
2727

2828
getConnectionAndClose(jdbcUrl);
2929

@@ -33,7 +33,7 @@ public void shouldStopContainerWhenAllConnectionsClosed() throws SQLException {
3333

3434
@Test
3535
public void shouldNotStopDaemonContainerWhenAllConnectionsClosed() throws SQLException {
36-
final String jdbcUrl = "jdbc:tc:postgresql://hostname/databasename?TC_DAEMON=true";
36+
final String jdbcUrl = "jdbc:tc:postgresql:9.6.8://hostname/databasename?TC_DAEMON=true";
3737

3838
getConnectionAndClose(jdbcUrl);
3939

modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ public class JDBCDriverTest {
3737
public static Iterable<Object[]> data() {
3838
return asList(
3939
new Object[][]{
40-
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
41-
{"jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false},
42-
{"jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
43-
{"jdbc:tc:mysql://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
4440
{"jdbc:tc:mysql://hostname/databasename", false, false, false},
45-
{"jdbc:tc:mysql://hostname/databasename?useSSL=false", false, false, false},
46-
{"jdbc:tc:postgresql://hostname/databasename", false, false, false},
41+
{"jdbc:tc:mysql:5.5.43://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false},
42+
{"jdbc:tc:mysql:5.5.43://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
43+
{"jdbc:tc:mysql:5.5.43://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
44+
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
45+
{"jdbc:tc:mysql:5.5.43://hostname/databasename?useSSL=false", false, false, false},
46+
{"jdbc:tc:postgresql:9.6.8://hostname/databasename", false, false, false},
4747
{"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override", false, false, true},
48-
{"jdbc:tc:mariadb:10.1.16://hostname/databasename", false, false, false},
4948
{"jdbc:tc:mariadb://hostname/databasename", false, false, false},
50-
{"jdbc:tc:mariadb://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
51-
{"jdbc:tc:mariadb://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql", true, false, false},
52-
{"jdbc:tc:mariadb://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
53-
{"jdbc:tc:mariadb:10.1.16://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override", false, false, true}
49+
{"jdbc:tc:mariadb:10.2.14://hostname/databasename", false, false, false},
50+
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
51+
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql", true, false, false},
52+
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
53+
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override", false, false, true}
5454
});
5555
}
5656

modules/jdbc-test/src/test/java/org/testcontainers/junit/CustomizablePostgreSQLTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class CustomizablePostgreSQLTest {
2121
private static final String PWD = "baz";
2222

2323
@Rule
24-
public PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:latest")
24+
public PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:9.6.8")
2525
.withDatabaseName(DB_NAME)
2626
.withUsername(USER)
2727
.withPassword(PWD);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
microsoft/mssql-server-linux:latest
1+
microsoft/mssql-server-linux:2017-CU6
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
package org.testcontainers.containers;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
35
/**
46
* Base class for classes that can provide a JDBC container.
57
*/
8+
@Slf4j
69
public abstract class JdbcDatabaseContainerProvider {
710

811
public abstract boolean supports(String databaseType);
912

13+
public JdbcDatabaseContainer newInstance() {
14+
log.warn("No explicit version tag was provided in JDBC URL and this class ({}) does not " +
15+
"override newInstance() to set a default tag. `latest` will be used but results may " +
16+
"be unreliable!", this.getClass().getCanonicalName());
17+
return this.newInstance("latest");
18+
}
19+
1020
public abstract JdbcDatabaseContainer newInstance(String tag);
1121
}

modules/jdbc/src/main/java/org/testcontainers/jdbc/ContainerDatabaseDriver.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ public synchronized Connection connect(String url, final Properties info) throws
102102
}
103103
String databaseType = urlMatcher.group(1);
104104
String tag = urlMatcher.group(3);
105-
if (tag == null) {
106-
tag = "latest";
107-
}
108105

109106
queryString = urlMatcher.group(4);
110107
if (queryString == null) {
@@ -119,7 +116,12 @@ public synchronized Connection connect(String url, final Properties info) throws
119116
ServiceLoader<JdbcDatabaseContainerProvider> databaseContainers = ServiceLoader.load(JdbcDatabaseContainerProvider.class);
120117
for (JdbcDatabaseContainerProvider candidateContainerType : databaseContainers) {
121118
if (candidateContainerType.supports(databaseType)) {
122-
container = candidateContainerType.newInstance(tag);
119+
120+
if (tag != null) {
121+
container = candidateContainerType.newInstance(tag);
122+
} else {
123+
container = candidateContainerType.newInstance();
124+
}
123125
delegate = container.getJdbcDriverInstance();
124126
}
125127
}

0 commit comments

Comments
 (0)