Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
Closes gh-38661
  • Loading branch information
mhalbritter committed Dec 5, 2023
2 parents 8e3f9cb + 3f29c7f commit de70b4f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,19 @@ void start() {
Stop stop = this.properties.getStop();
Wait wait = this.properties.getReadiness().getWait();
List<RunningService> runningServices = dockerCompose.getRunningServices();
if (lifecycleManagement.shouldStart() && runningServices.isEmpty()) {
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
runningServices = dockerCompose.getRunningServices();
if (wait == Wait.ONLY_IF_STARTED) {
wait = Wait.ALWAYS;
if (lifecycleManagement.shouldStart()) {
if (runningServices.isEmpty()) {
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
runningServices = dockerCompose.getRunningServices();
if (wait == Wait.ONLY_IF_STARTED) {
wait = Wait.ALWAYS;
}
if (lifecycleManagement.shouldStop()) {
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
}
}
if (lifecycleManagement.shouldStop()) {
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
else {
logger.info("There are already Docker Compose services running, skipping startup");
}
}
List<RunningService> relevantServices = new ArrayList<>(runningServices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;

import org.springframework.aot.AotDetector;
Expand All @@ -38,6 +39,8 @@
import org.springframework.boot.docker.compose.core.DockerComposeFile;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Readiness.Wait;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.GenericApplicationContext;
Expand All @@ -59,6 +62,7 @@
* @author Phillip Webb
* @author Scott Frederick
*/
@ExtendWith(OutputCaptureExtension.class)
class DockerComposeLifecycleManagerTests {

@TempDir
Expand Down Expand Up @@ -365,6 +369,21 @@ void startPublishesEvent() {
assertThat(event.getRunningServices()).isEqualTo(this.runningServices);
}

@Test
void shouldLogIfServicesAreAlreadyRunning(CapturedOutput output) {
setUpRunningServices();
this.lifecycleManager.start();
assertThat(output).contains("There are already Docker Compose services running, skipping startup");
}

@Test
void shouldNotLogIfThereAreNoServicesRunning(CapturedOutput output) {
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
given(this.dockerCompose.getRunningServices()).willReturn(Collections.emptyList());
this.lifecycleManager.start();
assertThat(output).doesNotContain("There are already Docker Compose services running, skipping startup");
}

private void setUpRunningServices() {
setUpRunningServices(true);
}
Expand Down

0 comments on commit de70b4f

Please sign in to comment.