Skip to content

Commit

Permalink
#128 Optimized Dockerfile HEALTHCHECK for Vanilla MySQL-server and Zo…
Browse files Browse the repository at this point in the history
…okeeper
  • Loading branch information
cer committed Dec 16, 2022
1 parent 926159c commit af9f531
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 1 deletion.
9 changes: 9 additions & 0 deletions eventuate-common-flyway/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies {
testImplementation "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
testImplementation "org.flywaydb:flyway-core:$flywayVersion"
testImplementation "org.flywaydb:flyway-mysql:$flywayVersion"
testImplementation project(":eventuate-common-spring-jdbc")
testImplementation project(":eventuate-common-testcontainers")
testImplementation "org.testcontainers:testcontainers:$testContainersVersion"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.eventuate.common.flyway;

import io.eventuate.common.spring.jdbc.EventuateCommonJdbcOperationsConfiguration;
import io.eventuate.common.testcontainers.DatabaseContainerFactory;
import io.eventuate.common.testcontainers.EventuateDatabaseContainer;
import io.eventuate.common.testcontainers.PropertyProvidingContainer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@SpringBootTest(classes = FlywayTest.Config.class)
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(properties="spring.flyway.locations=classpath:flyway/{vendor}")
public class FlywayTest {

public static EventuateDatabaseContainer<?> database = DatabaseContainerFactory.makeVanillaDatabaseContainerFromDockerFile();

@DynamicPropertySource
static void registerMySqlProperties(DynamicPropertyRegistry registry) {
PropertyProvidingContainer.startAndProvideProperties(registry, database);
}


@Configuration
@EnableAutoConfiguration
@Import(EventuateCommonJdbcOperationsConfiguration.class)
public static class Config {
}

@Test
public void shouldInitializationDatabase() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void registerProperties(BiConsumer<String, Supplier<Object>> registry) {
registry.accept("spring.datasource.url", this::getLocalJdbcUrl);
registry.accept("spring.datasource.username", () -> "mysqluser");
registry.accept("spring.datasource.password", () -> "mysqlpw");
registry.accept("spring.datasource.driver-class-name", () -> "com.mysql.cj.jdbc.Driver");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void registerProperties(BiConsumer<String, Supplier<Object>> registry) {
registry.accept("spring.datasource.url", this::getLocalJdbcUrl);
registry.accept("spring.datasource.username", () -> "postgresuser");
registry.accept("spring.datasource.password", () -> "postgrespw");
registry.accept("spring.datasource.driver-class-name", () -> "org.postgresql.Driver");

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.eventuate.common.testcontainers;

import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.images.builder.ImageFromDockerfile;

import java.nio.file.Path;
Expand All @@ -20,6 +21,7 @@ public EventuateZookeeperContainer(Path path) {

private void withConfiguration() {
withExposedPorts(2181);
waitingFor(Wait.forHealthcheck());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.eventuate.common.testcontainers;

import org.junit.ClassRule;
import org.junit.Test;

import java.nio.file.FileSystems;

public class EventuateZookeeperContainerTest {

@ClassRule
public static EventuateZookeeperContainer container = new EventuateZookeeperContainer(FileSystems.getDefault().getPath("../zookeeper/Dockerfile"));

@Test
public void shouldStart() {
}


}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ springDataR2dbcVersion=1.3.0
assertjVersion=3.23.1
testContainersVersion=1.17.3
jacksonVersion=2.13.4
flywayVersion=8.5.13

removeContainers=false

Expand Down
2 changes: 2 additions & 0 deletions mysql/Dockerfile-vanilla-mysql8
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ COPY 0.configure-root-user.sh /docker-entrypoint-initdb.d
RUN touch /docker-entrypoint-initdb.d/6.configure-users.sql

RUN chown mysql -R /docker-entrypoint-initdb.d

HEALTHCHECK --interval=2s --retries=30 CMD /healthcheck.sh
2 changes: 1 addition & 1 deletion zookeeper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ VOLUME ["/usr/local/apache-zookeeper-3.5.6-bin/conf", "/usr/local/zookeeper-data
COPY run-zk.sh .
ENTRYPOINT ["./run-zk.sh"]
CMD ["start-foreground"]
HEALTHCHECK --start-period=20s --interval=15s CMD (echo ruok | nc localhost 2181) || exit 1
HEALTHCHECK --interval=3s --retries=30 CMD (echo ruok | nc localhost 2181) || exit 1

0 comments on commit af9f531

Please sign in to comment.