Change DockerComposeProperties shut down default to stop

Closes gh-35239
This commit is contained in:
Andy Wilkinson
2023-05-04 21:09:16 +01:00
parent 6a39b497ad
commit 4f9616c2f9
18 changed files with 157 additions and 157 deletions

View File

@@ -33,35 +33,35 @@ import org.springframework.boot.logging.LogLevel;
public interface DockerCompose {
/**
* Timeout duration used to request a forced shutdown.
* Timeout duration used to request a forced stop.
*/
Duration FORCE_SHUTDOWN = Duration.ZERO;
Duration FORCE_STOP = Duration.ZERO;
/**
* Run {@code docker compose up} to startup services. Waits until all contains are
* started and healthy.
* Run {@code docker compose up} to create and start services. Waits until all
* contains are started and healthy.
* @param logLevel the log level used to report progress
*/
void up(LogLevel logLevel);
/**
* Run {@code docker compose down} to shut down any running services.
* @param timeout the amount of time to wait or {@link #FORCE_SHUTDOWN} to shut down
* without waiting.
* Run {@code docker compose down} to stop and remove any running services.
* @param timeout the amount of time to wait or {@link #FORCE_STOP} to stop without
* waiting.
*/
void down(Duration timeout);
/**
* Run {@code docker compose start} to startup services. Waits until all contains are
* Run {@code docker compose start} to start services. Waits until all containers are
* started and healthy.
* @param logLevel the log level used to report progress
*/
void start(LogLevel logLevel);
/**
* Run {@code docker compose stop} to shut down any running services.
* @param timeout the amount of time to wait or {@link #FORCE_SHUTDOWN} to shut down
* without waiting.
* Run {@code docker compose stop} to stop any running services.
* @param timeout the amount of time to wait or {@link #FORCE_STOP} to stop without
* waiting.
*/
void stop(Duration timeout);

View File

@@ -29,8 +29,8 @@ import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.docker.compose.core.DockerCompose;
import org.springframework.boot.docker.compose.core.DockerComposeFile;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Shutdown;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Startup;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Start;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Stop;
import org.springframework.boot.docker.compose.readiness.ServiceReadinessChecks;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
@@ -89,30 +89,30 @@ class DockerComposeLifecycleManager {
: new ServiceReadinessChecks(this.classLoader, applicationContext.getEnvironment(), binder);
}
void startup() {
void start() {
if (!this.properties.isEnabled()) {
logger.trace("Docker compose support not enabled");
logger.trace("Docker Compose support not enabled");
return;
}
if (this.skipCheck.shouldSkip(this.classLoader, this.properties.getSkip())) {
logger.trace("Docker compose support skipped");
logger.trace("Docker Compose support skipped");
return;
}
DockerComposeFile composeFile = getComposeFile();
Set<String> activeProfiles = this.properties.getProfiles().getActive();
DockerCompose dockerCompose = getDockerCompose(composeFile, activeProfiles);
if (!dockerCompose.hasDefinedServices()) {
logger.warn(LogMessage.format("No services defined in docker compose file '%s' with active profiles %s",
logger.warn(LogMessage.format("No services defined in Docker Compose file '%s' with active profiles %s",
composeFile, activeProfiles));
return;
}
LifecycleManagement lifecycleManagement = this.properties.getLifecycleManagement();
Startup startup = this.properties.getStartup();
Shutdown shutdown = this.properties.getShutdown();
if (lifecycleManagement.shouldStartup() && !dockerCompose.hasRunningServices()) {
startup.getCommand().applyTo(dockerCompose, startup.getLogLevel());
if (lifecycleManagement.shouldShutdown()) {
this.shutdownHandlers.add(() -> shutdown.getCommand().applyTo(dockerCompose, shutdown.getTimeout()));
Start start = this.properties.getStart();
Stop stop = this.properties.getStop();
if (lifecycleManagement.shouldStart() && !dockerCompose.hasRunningServices()) {
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
if (lifecycleManagement.shouldStop()) {
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
}
}
List<RunningService> runningServices = new ArrayList<>(dockerCompose.getRunningServices());
@@ -124,7 +124,7 @@ class DockerComposeLifecycleManager {
protected DockerComposeFile getComposeFile() {
DockerComposeFile composeFile = (this.properties.getFile() != null)
? DockerComposeFile.of(this.properties.getFile()) : DockerComposeFile.find(this.workingDirectory);
logger.info(LogMessage.format("Found docker compose file '%s'", composeFile));
logger.info(LogMessage.format("Found Docker Compose file '%s'", composeFile));
return composeFile;
}

View File

@@ -50,7 +50,7 @@ class DockerComposeListener implements ApplicationListener<ApplicationPreparedEv
Binder binder = Binder.get(applicationContext.getEnvironment());
DockerComposeProperties properties = DockerComposeProperties.get(binder);
Set<ApplicationListener<?>> eventListeners = event.getSpringApplication().getListeners();
createDockerComposeLifecycleManager(applicationContext, binder, properties, eventListeners).startup();
createDockerComposeLifecycleManager(applicationContext, binder, properties, eventListeners).start();
}
protected DockerComposeLifecycleManager createDockerComposeLifecycleManager(

View File

@@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.LogLevel;
/**
* Configuration properties for the 'docker compose'.
* Configuration properties for Docker Compose.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
@@ -61,12 +61,12 @@ public class DockerComposeProperties {
/**
* Start configuration.
*/
private final Startup startup = new Startup();
private final Start start = new Start();
/**
* Stop configuration.
*/
private final Shutdown shutdown = new Shutdown();
private final Stop stop = new Stop();
/**
* Profiles configuration.
@@ -107,12 +107,12 @@ public class DockerComposeProperties {
this.host = host;
}
public Startup getStartup() {
return this.startup;
public Start getStart() {
return this.start;
}
public Shutdown getShutdown() {
return this.shutdown;
public Stop getStop() {
return this.stop;
}
public Profiles getProfiles() {
@@ -128,25 +128,25 @@ public class DockerComposeProperties {
}
/**
* Startup properties.
* Start properties.
*/
public static class Startup {
public static class Start {
/**
* Command used to start docker compose.
*/
private StartupCommand command = StartupCommand.UP;
private StartCommand command = StartCommand.UP;
/**
* Log level for output.
*/
private LogLevel logLevel = LogLevel.INFO;
public StartupCommand getCommand() {
public StartCommand getCommand() {
return this.command;
}
public void setCommand(StartupCommand command) {
public void setCommand(StartCommand command) {
this.command = command;
}
@@ -161,25 +161,25 @@ public class DockerComposeProperties {
}
/**
* Shutdown properties.
* Stop properties.
*/
public static class Shutdown {
public static class Stop {
/**
* Command used to stop docker compose.
*/
private ShutdownCommand command = ShutdownCommand.DOWN;
private StopCommand command = StopCommand.STOP;
/**
* Timeout for stopping docker compose. Use '0' for forced stop.
* Timeout for stopping Docker Compose. Use '0' for forced stop.
*/
private Duration timeout = Duration.ofSeconds(10);
public ShutdownCommand getCommand() {
public StopCommand getCommand() {
return this.command;
}
public void setCommand(ShutdownCommand command) {
public void setCommand(StopCommand command) {
this.command = command;
}

View File

@@ -24,9 +24,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
/**
* {@link ApplicationEvent} published when docker compose {@link RunningService} instances
* are available. This event is published from the {@link ApplicationPreparedEvent} that
* performs the docker compose startup.
* {@link ApplicationEvent} published when Docker Compose {@link RunningService} instances
* are available. This event is published from the {@link ApplicationPreparedEvent}
* listener that starts Docker Compose.
*
* @author Moritz Halbritter
* @author Andy Wilkinson

View File

@@ -24,7 +24,7 @@ import org.springframework.boot.SpringApplicationAotProcessor;
import org.springframework.util.ClassUtils;
/**
* Checks if docker compose support should be skipped.
* Checks if Docker Compose support should be skipped.
*
* @author Phillip Webb
*/

View File

@@ -17,7 +17,7 @@
package org.springframework.boot.docker.compose.lifecycle;
/**
* Docker compose lifecycle management.
* Docker Compose lifecycle management.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
@@ -27,43 +27,43 @@ package org.springframework.boot.docker.compose.lifecycle;
public enum LifecycleManagement {
/**
* Don't start or stop docker compose.
* Don't start or stop Docker Compose.
*/
NONE(false, false),
/**
* Only start docker compose if it's not running.
* Start Docker Compose if it's not running.
*/
START_ONLY(true, false),
/**
* Start and stop docker compose if it's not running.
* Start Docker Compose if it's not running and stop it when the JVM exits.
*/
START_AND_STOP(true, true);
private final boolean startup;
private final boolean start;
private final boolean shutdown;
private final boolean stop;
LifecycleManagement(boolean startup, boolean shutdown) {
this.startup = startup;
this.shutdown = shutdown;
LifecycleManagement(boolean start, boolean stop) {
this.start = start;
this.stop = stop;
}
/**
* Return whether docker compose should be started.
* @return whether docker compose should be started
* Return whether Docker Compose should be started.
* @return whether Docker Compose should be started
*/
boolean shouldStartup() {
return this.startup;
boolean shouldStart() {
return this.start;
}
/**
* Return whether docker compose should be stopped.
* @return whether docker compose should be stopped
* Return whether Docker Compose should be stopped.
* @return whether Docker Compose should be stopped
*/
boolean shouldShutdown() {
return this.shutdown;
boolean shouldStop() {
return this.stop;
}
}

View File

@@ -22,28 +22,28 @@ import org.springframework.boot.docker.compose.core.DockerCompose;
import org.springframework.boot.logging.LogLevel;
/**
* Command used to startup docker compose.
* Command used to start Docker Compose.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.1.0
*/
public enum StartupCommand {
public enum StartCommand {
/**
* Startup using {@code docker compose up}.
* Start using {@code docker compose up}.
*/
UP(DockerCompose::up),
/**
* Startup using {@code docker compose start}.
* Start using {@code docker compose start}.
*/
START(DockerCompose::start);
private final BiConsumer<DockerCompose, LogLevel> action;
StartupCommand(BiConsumer<DockerCompose, LogLevel> action) {
StartCommand(BiConsumer<DockerCompose, LogLevel> action) {
this.action = action;
}

View File

@@ -22,28 +22,28 @@ import java.util.function.BiConsumer;
import org.springframework.boot.docker.compose.core.DockerCompose;
/**
* Command used to shut down docker compose.
* Command used to stop Docker Compose.
*
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.1.0
*/
public enum ShutdownCommand {
public enum StopCommand {
/**
* Shutdown using {@code docker compose down}.
* Stop using {@code docker compose down}.
*/
DOWN(DockerCompose::down),
/**
* Shutdown using {@code docker compose stop}.
* Stop using {@code docker compose stop}.
*/
STOP(DockerCompose::stop);
private final BiConsumer<DockerCompose, Duration> action;
ShutdownCommand(BiConsumer<DockerCompose, Duration> action) {
StopCommand(BiConsumer<DockerCompose, Duration> action) {
this.action = action;
}

View File

@@ -15,6 +15,6 @@
*/
/**
* Lifecycle management for docker compose with the context of a Spring application.
* Lifecycle management for Docker Compose with the context of a Spring application.
*/
package org.springframework.boot.docker.compose.lifecycle;