Skip to content

Commit 5cfaee5

Browse files
viktorgunnarsonrohanKanojia
authored andcommitted
Fix: Use wait config if no docker compose healthcheck
If no healthcheck is specified in the docker compose file, use the specified wait config if available. Signed-off-by: Viktor Thell <3408082+viktorgunnarson@users.noreply.github.com>
1 parent b66319d commit 5cfaee5

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/io/fabric8/maven/docker/config/handler/compose/DockerComposeServiceWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ WaitConfiguration getWaitConfiguration() {
305305
} else if (successExitWaitRequested) {
306306
return new WaitConfiguration.Builder().exit(0).build();
307307
}
308-
return null;
308+
return enclosingImageConfig.getRunConfiguration() == null ? null :
309+
enclosingImageConfig.getRunConfiguration().getWaitConfiguration();
309310
}
310311

311312
List<String> getDns() {

src/test/java/io/fabric8/maven/docker/config/handler/compose/DockerComposeConfigHandlerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ void negativeVersionTest() throws IOException, MavenFilteringException {
227227

228228
}
229229

230+
@Test
231+
void testWaitConfig() throws IOException, MavenFilteringException {
232+
setupComposeExpectations("docker-compose_2.4.yml");
233+
WaitConfiguration wait = new WaitConfiguration.Builder()
234+
.url("http://localhost:8080/health")
235+
.method("GET")
236+
.status("200..399")
237+
.build();
238+
Mockito.when(unresolved.getRunConfiguration()).thenReturn(new RunImageConfiguration.Builder().wait(wait).build());
239+
240+
List<ImageConfiguration> configs = handler.resolve(unresolved, project, session);
241+
RunImageConfiguration runConfig = findRunConfigurationByAlias(configs, "service");
242+
Assertions.assertNotNull(runConfig.getWaitConfiguration());
243+
Assertions.assertSame(wait, runConfig.getWaitConfiguration());
244+
}
245+
230246
private void setupComposeExpectations(final String file) throws IOException, MavenFilteringException {
231247
final File input = getAsFile("/compose/" + file);
232248

0 commit comments

Comments
 (0)