Skip to content

Commit

Permalink
fabric8io#970 postStart exec breakOnError should fail fast
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Praet <jimmy.praet@ksz-bcss.fgov.be>
  • Loading branch information
jpraet committed Mar 26, 2018
1 parent 689b7e0 commit f9bba93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* **0.24-SNAPSHOT**
- Fix possible NPE when logging to a file and the parent directory does not exist yet (#911) (#940)
- PostStart exec breakOnError now fails fast (#970)

* **0.24.0** (2018-02-07)
- Respect system properties for ECR authentication ([#897](https://github.com/fabric8io/docker-maven-plugin/issues/897))
Expand Down
38 changes: 25 additions & 13 deletions src/main/java/io/fabric8/maven/docker/StartMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,14 @@ public synchronized void executeInternal(final ServiceHub hub) throws DockerAcce
// Move from waiting to starting status
imagesStarting.add(image);
imagesWaitingToStart.remove(image);

if (!startParallel) {
waitForStartedContainer(hub, containerStartupService, startedContainerAliases, imagesStarting);
}
}

// Wait for the next container to finish startup
final Future<StartedContainer> startedContainerFuture = containerStartupService.take();
try {
final StartedContainer startedContainer = startedContainerFuture.get();
final ImageConfiguration imageConfig = startedContainer.imageConfig;

updateAliasesSet(startedContainerAliases, imageConfig.getAlias());
exposeContainerProps(hub.getQueryService(), startedContainer);

// All done with this image
imagesStarting.remove(imageConfig);
} catch (ExecutionException e) {
rethrowCause(e);
if (startParallel) {
waitForStartedContainer(hub, containerStartupService, startedContainerAliases, imagesStarting);
}
}

Expand Down Expand Up @@ -184,6 +177,25 @@ public synchronized void executeInternal(final ServiceHub hub) throws DockerAcce
}
}

private void waitForStartedContainer(final ServiceHub hub,
final ExecutorCompletionService<StartedContainer> containerStartupService,
final Set<String> startedContainerAliases, final Queue<ImageConfiguration> imagesStarting)
throws InterruptedException, DockerAccessException, IOException, ExecException {
final Future<StartedContainer> startedContainerFuture = containerStartupService.take();
try {
final StartedContainer startedContainer = startedContainerFuture.get();
final ImageConfiguration imageConfig = startedContainer.imageConfig;

updateAliasesSet(startedContainerAliases, imageConfig.getAlias());
exposeContainerProps(hub.getQueryService(), startedContainer);

// All done with this image
imagesStarting.remove(imageConfig);
} catch (ExecutionException e) {
rethrowCause(e);
}
}

protected Boolean followLogs() {
return Boolean.valueOf(System.getProperty("docker.follow", "false"));
}
Expand Down

0 comments on commit f9bba93

Please sign in to comment.