Skip to content

Destroy docker container properly #2379

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
*
* @author Gabriel Basilio
* @author Greg Turnquist
* @author Yanming Zhou
*/
@Transactional
@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -190,26 +191,21 @@ public interface EmployeeRepositoryWithNoCursor extends JpaRepository<Employee,
@EnableTransactionManagement
static class Config {

private MySQLContainer<?> MYSQL_CONTAINER;

@Bean
public DataSource dataSource() {

if (MYSQL_CONTAINER == null) {

MYSQL_CONTAINER = new MySQLContainer<>("mysql:8.0.24") //
@SuppressWarnings("resource")
@Bean(initMethod = "start")
public MySQLContainer<?> container() {
return new MySQLContainer<>("mysql:8.0.24") //
.withUsername("test") //
.withPassword("test") //
.withConfigurationOverride("");
MYSQL_CONTAINER.start();
}
}

@Bean
public DataSource dataSource(MySQLContainer<?> container) {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUrl(MYSQL_CONTAINER.getJdbcUrl());
dataSource.setUser("root");
dataSource.setPassword(MYSQL_CONTAINER.getPassword());
dataSource.setDatabaseName(MYSQL_CONTAINER.getDatabaseName());

dataSource.setUrl(container.getJdbcUrl());
dataSource.setUser(container.getUsername());
dataSource.setPassword(container.getPassword());
return dataSource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
*
* @author Gabriel Basilio
* @author Greg Turnquist
* @author Yanming Zhou
*/
@Transactional
@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -193,23 +194,19 @@ public interface EmployeeRepositoryWithRefCursor extends JpaRepository<Employee,
@EnableTransactionManagement
static class Config {

private PostgreSQLContainer<?> POSTGRESQL_CONTAINER;
@SuppressWarnings("resource")
@Bean(initMethod = "start")
public PostgreSQLContainer<?> container() {
return new PostgreSQLContainer<>("postgres:9.6.12") //
.withUsername("postgres");
}

@Bean
public DataSource dataSource() {

if (POSTGRESQL_CONTAINER == null) {

POSTGRESQL_CONTAINER = new PostgreSQLContainer<>("postgres:9.6.12") //
.withUsername("postgres");
POSTGRESQL_CONTAINER.start();
}

public DataSource dataSource(PostgreSQLContainer<?> container) {
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setUrl(POSTGRESQL_CONTAINER.getJdbcUrl());
dataSource.setUser(POSTGRESQL_CONTAINER.getUsername());
dataSource.setPassword(POSTGRESQL_CONTAINER.getPassword());

dataSource.setUrl(container.getJdbcUrl());
dataSource.setUser(container.getUsername());
dataSource.setPassword(container.getPassword());
return dataSource;
}

Expand Down