Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin tags #671

Merged
merged 8 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Fixed

### Changed
- 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link the PR :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I have one I will :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same issue every time I submit a PR :D Even started to predict the next number 😂


## [1.7.1] - 2018-04-20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public abstract class AbstractWaitStrategyTest<W extends WaitStrategy> {
static final long WAIT_TIMEOUT_MILLIS = 3000;
static final String IMAGE_NAME = "alpine:latest";
static final String IMAGE_NAME = "alpine:3.7";

/**
* Indicates that the WaitStrategy has completed waiting successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class HostPortWaitStrategyTest {

private static final String IMAGE_NAME = "alpine:latest";
private static final String IMAGE_NAME = "alpine:3.7";

@ClassRule
public static GenericContainer container = new GenericContainer(IMAGE_NAME).withExposedPorts()
Expand Down
23 changes: 7 additions & 16 deletions docs/usage/database_containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,40 @@ _N.B:_
* _TC needs to be on your application's classpath at runtime for this to work_
* _For Spring Boot you need to specify the driver manually `spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver`_

**Original URL**: `jdbc:mysql://somehostname:someport/databasename`
**Original URL**: `jdbc:mysql:5.7.22://somehostname:someport/databasename`

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.

### JDBC URL examples

#### Simple Testcontainers JDBC driver usage
#### DEPRECATED: Simple Testcontainers JDBC driver usage

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

*(Note: this will use the latest version of MySQL)*
*(Note: this will implicitly use the `latest` version of MySQL. Using `latest` is risky and Testcontainers will soon require an explicit tag name to be provided)*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should implicitly set it to 5 if no version was provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps - I think I might sleep on it. Both approaches have tradeoffs, so I guess it's just a case of which one we think is least troublesome for users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Just thought that given the fact that the latest MySQL broke our own tests, a lot of users will also be affected, especially the ones who use the JDBC url approach :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided 😆
Updated following your suggestion. We're now using a fixed version (which is similar to current latest) if there is no tag provided in the JDBC URL.


#### Using Testcontainers with a fixed version

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

#### Using PostgreSQL

`jdbc:tc:postgresql://hostname/databasename`
`jdbc:tc:postgresql:9.6.8://hostname/databasename`


## Using an init script

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:

`jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql`
`jdbc:tc:mysql:5.7.22://hostname/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 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://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction`
`jdbc:tc:mysql:5.7.22://hostname/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 @@ -101,7 +101,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://hostname/databasename?TC_DAEMON=true`
`jdbc:tc:mysql:5.7.22://hostname/databasename?TC_DAEMON=true`

With this parameter database container will keep running even when there're no open connections.

Expand All @@ -114,12 +114,3 @@ is a directory on the classpath containing .cnf files, the following URL can be

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.

### Additional Non-standard Methods

#### Virtuoso SPARQL Service URL

VirtuosoContainer provides access to the SPARQL service URL
```java
String sparqlServiceUrl = ((VirtuosoContainer)container).getSparqlUrl();
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void testCleanup() {

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

getConnectionAndClose(jdbcUrl);

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

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

getConnectionAndClose(jdbcUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public static Iterable<Object[]> data() {
return asList(
new Object[][]{
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
{"jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false},
{"jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
{"jdbc:tc:mysql://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mysql://hostname/databasename", false, false, false},
{"jdbc:tc:mysql://hostname/databasename?useSSL=false", false, false, false},
{"jdbc:tc:postgresql://hostname/databasename", false, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
{"jdbc:tc:mysql:5.5.43://hostname/databasename?useSSL=false", false, false, false},
{"jdbc:tc:postgresql:9.6.8://hostname/databasename", false, false, false},
{"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override", false, false, true},
{"jdbc:tc:mariadb:10.1.16://hostname/databasename", false, false, false},
{"jdbc:tc:mariadb://hostname/databasename", false, false, false},
{"jdbc:tc:mariadb://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mariadb://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql", true, false, false},
{"jdbc:tc:mariadb://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
{"jdbc:tc:mariadb:10.1.16://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override", false, false, true}
{"jdbc:tc:mariadb:10.2.14://hostname/databasename", false, false, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql", true, false, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
{"jdbc:tc:mariadb:10.2.14://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override", false, false, true}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CustomizablePostgreSQLTest {
private static final String PWD = "baz";

@Rule
public PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:latest")
public PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:9.6.8")
.withDatabaseName(DB_NAME)
.withUsername(USER)
.withPassword(PWD);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
microsoft/mssql-server-linux:latest
microsoft/mssql-server-linux:2017-CU6
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public synchronized Connection connect(String url, final Properties info) throws
String tag = urlMatcher.group(3);
if (tag == null) {
tag = "latest";
LOGGER.warn("No version tag set in JDBC URL. `latest` will be used now, but " +
"this will stop working in a future version. Please update the JDBC URL to " +
"include a tag.");
}

queryString = urlMatcher.group(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Container implementation for the MariaDB project.
*
*
* @author Miguel Gonzalez Sanchez
*/
public class MariaDBContainer<SELF extends MariaDBContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
Expand All @@ -16,7 +16,7 @@ public class MariaDBContainer<SELF extends MariaDBContainer<SELF>> extends JdbcD
private static final String MY_CNF_CONFIG_OVERRIDE_PARAM_NAME = "TC_MY_CNF";

public MariaDBContainer() {
super(IMAGE + ":latest");
super(IMAGE + ":10.3.6");
}

public MariaDBContainer(String dockerImageName) {
Expand All @@ -31,7 +31,7 @@ protected Integer getLivenessCheckPort() {
@Override
protected void configure() {
optionallyMapResourceParameterAsVolume(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, "/etc/mysql/conf.d", "mariadb-default-conf");

addExposedPort(MARIADB_PORT);
addEnv("MYSQL_DATABASE", MARIADB_DATABASE);
addEnv("MYSQL_USER", MARIADB_USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MSSQLServerContainer<SELF extends MSSQLServerContainer<SELF>> exten
private String password = "A_Str0ng_Required_Password";

public MSSQLServerContainer() {
this(IMAGE + ":latest");
this(IMAGE + ":2017-CU6");
}

public MSSQLServerContainer(final String dockerImageName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MySQLContainer<SELF extends MySQLContainer<SELF>> extends JdbcDatab
private String password = "test";

public MySQLContainer() {
super(IMAGE + ":latest");
super(IMAGE + ":5.7.22");
}

public MySQLContainer(String dockerImageName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PostgreSQLContainer<SELF extends PostgreSQLContainer<SELF>> extends
private String password = "test";

public PostgreSQLContainer() {
this(IMAGE + ":latest");
this(IMAGE + ":9.6.8");
}

public PostgreSQLContainer(final String dockerImageName) {
Expand Down