Skip to content

Commit

Permalink
Fix Testcontainers regression
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneLimburg committed Mar 12, 2022
1 parent 6ea86f7 commit 3d57b33
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<maven.compiler.target>11</maven.compiler.target>

<jupiter.version>5.6.2</jupiter.version>
<testcontainers.version>1.16.2</testcontainers.version>
<testcontainers.version>1.16.3</testcontainers.version>
<flyway.version>8.4.3</flyway.version>

<sonar.projectKey>ArneLimburg_testflight</sonar.projectKey>
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/space/testflight/InContainerDataMySqlContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ public InContainerDataMySqlContainer(String image) {
.from(image)
.run("mkdir -p /var/lib/mysql-data && chown -R mysql:mysql /var/lib/mysql-data")
.build()));
initCommand();
}

private void initCommand() {
withClasspathResourceMapping("/space/testflight/mysql/mysql.cnf", "/etc/mysql/conf.d/mysql.cnf", BindMode.READ_ONLY);
exposeContainerPort();
}

@Override
Expand All @@ -51,4 +48,19 @@ public String getDefaultImageName() {
public void addFixedPort(int hostPort, int containerPort) {
super.addFixedExposedPort(hostPort, containerPort, InternetProtocol.TCP);
}

private void exposeContainerPort() {
// withCreateContainerCmdModifier(cmd -> {
// List<ExposedPort> exposedPorts = new ArrayList<>();
// for (ExposedPort p : cmd.getExposedPorts()) {
// exposedPorts.add(p);
// }
// exposedPorts.add(ExposedPort.tcp(getContainerPort()));
// cmd.withExposedPorts(exposedPorts);
//
// Ports ports = cmd.getHostConfig().getPortBindings();
// ports.bind(ExposedPort.tcp(getContainerPort()), Ports.Binding.empty());
// cmd.getHostConfig().withPortBindings(ports);
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class InContainerDataPostgreSqlContainer extends PostgreSQLContainer<InCo
public InContainerDataPostgreSqlContainer(String dockerImage) {
super(dockerImage);
withEnv("PGDATA", "/var/lib/postgresql/data-local");
exposeContainerPort();
}

@Override
Expand All @@ -40,4 +41,19 @@ public int getContainerPort() {
public void addFixedPort(int hostPort, int containerPort) {
super.addFixedExposedPort(hostPort, containerPort, InternetProtocol.TCP);
}

private void exposeContainerPort() {
// withCreateContainerCmdModifier(cmd -> {
// List<ExposedPort> exposedPorts = new ArrayList<>();
// for (ExposedPort p : cmd.getExposedPorts()) {
// exposedPorts.add(p);
// }
// exposedPorts.add(ExposedPort.tcp(getContainerPort()));
// cmd.withExposedPorts(exposedPorts);
//
// Ports ports = cmd.getHostConfig().getPortBindings();
// ports.bind(ExposedPort.tcp(getContainerPort()), Ports.Binding.empty());
// cmd.getHostConfig().withPortBindings(ports);
// });
}
}

0 comments on commit 3d57b33

Please sign in to comment.