Skip to content

Commit

Permalink
[Mysql] Extract mysql docker image
Browse files Browse the repository at this point in the history
Fix #231
  • Loading branch information
swarajsaaj committed Dec 14, 2021
1 parent fb17443 commit a2488c8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ public class MySQL {

public static final String TESTCONTAINERS_VERSION = "1.16.0";

public static final String DOCKER_IMAGE_NAME = "mysql:8.0.27";

private MySQL() {}

public static String getTestcontainersVersion() {
return TESTCONTAINERS_VERSION;
}

public static String getDockerImageName() {
return DOCKER_IMAGE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void addHibernateCore(Project project) {
@Override
public void addDockerCompose(Project project) {
project.addDefaultConfig(BASE_NAME);
project.addConfig("dockerImageName", MySQL.getDockerImageName());
projectRepository.template(project, SOURCE, "mysql.yml", "src/main/docker", "mysql.yml");
}

Expand Down Expand Up @@ -118,12 +119,10 @@ private Map<String, Object> springProperties(String baseName, String packageName
result.put("spring.datasource.url", "jdbc:mysql://localhost:3306/" + baseName);
result.put("spring.datasource.username", "root");
result.put("spring.datasource.password", "");
result.put("spring.datasource.driver-class-name", "com.mysql.jdbc.Driver");
result.put("spring.datasource.hikari.poolName", "Hikari");
result.put("spring.datasource.hikari.auto-commit", false);

result.put("spring.data.jpa.repositories.bootstrap-mode", "deferred");
result.put("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect");
result.put("spring.jpa.properties.hibernate.jdbc.time_zone", "UTC");
result.put("spring.jpa.open-in-view", false);
result.put("spring.jpa.properties.hibernate.id.new_generator_mappings", "true");
Expand All @@ -144,7 +143,7 @@ private Map<String, Object> springProperties(String baseName, String packageName
private Map<String, Object> springPropertiesForTest(String baseName) {
TreeMap<String, Object> result = new TreeMap<>();
result.put("spring.datasource.driver-class-name", "org.testcontainers.jdbc.ContainerDatabaseDriver");
result.put("spring.datasource.url", "jdbc:tc:mysql:8.0.27:///" + baseName);
result.put("spring.datasource.url", "jdbc:tc:" + MySQL.getDockerImageName() + ":///" + baseName);
result.put("spring.datasource.username", baseName);
result.put("spring.datasource.password", "");
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: '3.8'
services:
mysql:
image: mysql:8.0.27
image: {{dockerImageName}}
# volumes:
# - ~/volumes/jhipster/{{baseName}}/mysql/:/var/lib/mysql/
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.jhipster.lite.generator.init.application.InitApplicationService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.server.springboot.core.application.SpringBootApplicationService;
import tech.jhipster.lite.generator.server.springboot.database.mysql.domain.MySQL;

@IntegrationTest
class MySQLApplicationServiceIT {
Expand Down Expand Up @@ -163,7 +164,6 @@ void shouldAddProperties() {
project,
getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES),
List.of(
"spring.datasource.driver-class-name=com.mysql.jdbc.Driver",
"spring.datasource.hikari.auto-commit=false",
"spring.datasource.hikari.poolName=Hikari",
"spring.datasource.password=",
Expand Down Expand Up @@ -191,7 +191,7 @@ void shouldAddTestcontainers() {
assertFileContent(
project,
getPath(TEST_RESOURCES, "config/application.properties"),
List.of("spring.datasource.url=jdbc:tc:mysql:8.0.27:///chips", "spring.datasource.username=chips")
List.of("spring.datasource.url=jdbc:tc:" + MySQL.getDockerImageName() + ":///chips", "spring.datasource.username=chips")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ class MySQLTest {
void shouldGetTestcontainersVersion() {
assertThat(MySQL.getTestcontainersVersion()).isEqualTo("1.16.0");
}

@Test
void shouldGetDockerImageName() {
assertThat(MySQL.getDockerImageName()).isEqualTo("mysql:8.0.27");
}
}

0 comments on commit a2488c8

Please sign in to comment.