Skip to content

Commit 0e51d76

Browse files
committed
#8 Added option to delay the verification step (and thereby delay relinquishing control to Spring Boot), so that on slow systems, Postgres has the chance to be ready before Liquibase requires a connection. Set after-verification-wait: [value] to introduce the extra sleep.
1 parent 4964cb5 commit 0e51d76

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22
<modelVersion>4.0.0</modelVersion>
33
<artifactId>spring-boot-docker-postgres</artifactId>
4-
<version>0.3.1</version>
4+
<version>0.4.0-SNAPSHOT</version>
55
<packaging>jar</packaging>
66
<groupId>nl.42</groupId>
77

src/main/java/nl/_42/boot/docker/postgres/DockerPostgresBootSequence.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public DockerPostgresBootSequence(DockerPostgresProperties properties) {
1515
this.properties = properties;
1616
}
1717

18-
public DockerPostgresContainer execute() throws IOException {
18+
public DockerPostgresContainer execute() throws IOException, InterruptedException {
1919

2020
LOGGER.info("| Docker Postgres Properties");
2121
LOGGER.info("| * Image name: " + properties.getImageName());
@@ -50,6 +50,7 @@ public DockerPostgresContainer execute() throws IOException {
5050
DockerPostgresContainer postgresContainer = new DockerPostgresContainer(properties, imageDownloaded);
5151
postgresContainer.start();
5252
if (postgresContainer.verify()) {
53+
applyAfterVerificationWait(properties.getAfterVerificationWait());
5354
LOGGER.info("| Postgres container successfully started");
5455
} else {
5556
LOGGER.error("| Postgres failed to initialize");
@@ -59,4 +60,11 @@ public DockerPostgresContainer execute() throws IOException {
5960
return postgresContainer;
6061
}
6162

63+
private void applyAfterVerificationWait(Integer afterVerificationWait) throws InterruptedException {
64+
if (afterVerificationWait > 0) {
65+
LOGGER.info("| Applying after verification wait of " + afterVerificationWait + "ms");
66+
Thread.sleep(afterVerificationWait);
67+
}
68+
}
69+
6270
}

src/main/java/nl/_42/boot/docker/postgres/DockerPostgresProperties.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class DockerPostgresProperties {
3232

3333
private boolean forceClean = false;
3434

35+
private Integer afterVerificationWait = 0;
36+
3537
private Map<String, String> customVariables = new HashMap<>();
3638

3739
public boolean isEnabled() {
@@ -138,6 +140,14 @@ public void setCustomVariables(Map<String, String> customVariables) {
138140
this.customVariables = customVariables;
139141
}
140142

143+
public Integer getAfterVerificationWait() {
144+
return afterVerificationWait;
145+
}
146+
147+
public void setAfterVerificationWait(Integer afterVerificationWait) {
148+
this.afterVerificationWait = afterVerificationWait;
149+
}
150+
141151
public Map<String, String> getProperties() {
142152
Map<String,String> properties = new HashMap<>();
143153
properties.put("stdOutFilename", getStdOutFilename());
@@ -151,6 +161,7 @@ public Map<String, String> getProperties() {
151161
properties.put("startupVerificationText", getStartupVerificationText());
152162
properties.put("dockerCommand", getDockerCommand());
153163
properties.put("forceClean", Boolean.toString(isForceClean()));
164+
properties.put("afterVerificationWait", Boolean.toString(isForceClean()));
154165
properties.putAll(getCustomVariables());
155166
return properties;
156167
}

0 commit comments

Comments
 (0)