mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Add properties to specify arguments to Docker Compose commands
These new properties take a List<String>: - spring.docker.compose.start.arguments - spring.docker.compose.stop.arguments Closes gh-38763
This commit is contained in:
parent
17ca0421e7
commit
6c0c9b9a80
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -48,22 +48,42 @@ class DefaultDockerCompose implements DockerCompose {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void up(LogLevel logLevel) {
|
public void up(LogLevel logLevel) {
|
||||||
this.cli.run(new DockerCliCommand.ComposeUp(logLevel));
|
up(logLevel, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up(LogLevel logLevel, List<String> arguments) {
|
||||||
|
this.cli.run(new DockerCliCommand.ComposeUp(logLevel, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void down(Duration timeout) {
|
public void down(Duration timeout) {
|
||||||
this.cli.run(new DockerCliCommand.ComposeDown(timeout));
|
down(timeout, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down(Duration timeout, List<String> arguments) {
|
||||||
|
this.cli.run(new DockerCliCommand.ComposeDown(timeout, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(LogLevel logLevel) {
|
public void start(LogLevel logLevel) {
|
||||||
this.cli.run(new DockerCliCommand.ComposeStart(logLevel));
|
start(logLevel, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(LogLevel logLevel, List<String> arguments) {
|
||||||
|
this.cli.run(new DockerCliCommand.ComposeStart(logLevel, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(Duration timeout) {
|
public void stop(Duration timeout) {
|
||||||
this.cli.run(new DockerCliCommand.ComposeStop(timeout));
|
stop(timeout, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop(Duration timeout, List<String> arguments) {
|
||||||
|
this.cli.run(new DockerCliCommand.ComposeStop(timeout, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -161,8 +161,18 @@ abstract sealed class DockerCliCommand<R> {
|
|||||||
*/
|
*/
|
||||||
static final class ComposeUp extends DockerCliCommand<Void> {
|
static final class ComposeUp extends DockerCliCommand<Void> {
|
||||||
|
|
||||||
ComposeUp(LogLevel logLevel) {
|
ComposeUp(LogLevel logLevel, List<String> arguments) {
|
||||||
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "up", "--no-color", "--detach", "--wait");
|
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, getCommand(arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] getCommand(List<String> arguments) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
result.add("up");
|
||||||
|
result.add("--no-color");
|
||||||
|
result.add("--detach");
|
||||||
|
result.add("--wait");
|
||||||
|
result.addAll(arguments);
|
||||||
|
return result.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -172,8 +182,17 @@ abstract sealed class DockerCliCommand<R> {
|
|||||||
*/
|
*/
|
||||||
static final class ComposeDown extends DockerCliCommand<Void> {
|
static final class ComposeDown extends DockerCliCommand<Void> {
|
||||||
|
|
||||||
ComposeDown(Duration timeout) {
|
ComposeDown(Duration timeout, List<String> arguments) {
|
||||||
super(Type.DOCKER_COMPOSE, Void.class, false, "down", "--timeout", Long.toString(timeout.toSeconds()));
|
super(Type.DOCKER_COMPOSE, Void.class, false, getCommand(timeout, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] getCommand(Duration timeout, List<String> arguments) {
|
||||||
|
List<String> command = new ArrayList<>();
|
||||||
|
command.add("down");
|
||||||
|
command.add("--timeout");
|
||||||
|
command.add(Long.toString(timeout.toSeconds()));
|
||||||
|
command.addAll(arguments);
|
||||||
|
return command.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -183,8 +202,15 @@ abstract sealed class DockerCliCommand<R> {
|
|||||||
*/
|
*/
|
||||||
static final class ComposeStart extends DockerCliCommand<Void> {
|
static final class ComposeStart extends DockerCliCommand<Void> {
|
||||||
|
|
||||||
ComposeStart(LogLevel logLevel) {
|
ComposeStart(LogLevel logLevel, List<String> arguments) {
|
||||||
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "start");
|
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, getCommand(arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] getCommand(List<String> arguments) {
|
||||||
|
List<String> command = new ArrayList<>();
|
||||||
|
command.add("start");
|
||||||
|
command.addAll(arguments);
|
||||||
|
return command.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -194,8 +220,17 @@ abstract sealed class DockerCliCommand<R> {
|
|||||||
*/
|
*/
|
||||||
static final class ComposeStop extends DockerCliCommand<Void> {
|
static final class ComposeStop extends DockerCliCommand<Void> {
|
||||||
|
|
||||||
ComposeStop(Duration timeout) {
|
ComposeStop(Duration timeout, List<String> arguments) {
|
||||||
super(Type.DOCKER_COMPOSE, Void.class, false, "stop", "--timeout", Long.toString(timeout.toSeconds()));
|
super(Type.DOCKER_COMPOSE, Void.class, false, getCommand(timeout, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] getCommand(Duration timeout, List<String> arguments) {
|
||||||
|
List<String> command = new ArrayList<>();
|
||||||
|
command.add("stop");
|
||||||
|
command.add("--timeout");
|
||||||
|
command.add(Long.toString(timeout.toSeconds()));
|
||||||
|
command.addAll(arguments);
|
||||||
|
return command.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -44,6 +44,15 @@ public interface DockerCompose {
|
|||||||
*/
|
*/
|
||||||
void up(LogLevel logLevel);
|
void up(LogLevel logLevel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @param arguments the arguments to pass to the up command
|
||||||
|
* @since 3.4.0
|
||||||
|
*/
|
||||||
|
void up(LogLevel logLevel, List<String> arguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run {@code docker compose down} to stop and remove any running services.
|
* 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
|
* @param timeout the amount of time to wait or {@link #FORCE_STOP} to stop without
|
||||||
@ -51,6 +60,15 @@ public interface DockerCompose {
|
|||||||
*/
|
*/
|
||||||
void down(Duration timeout);
|
void down(Duration timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* @param arguments the arguments to pass to the down command
|
||||||
|
* @since 3.4.0
|
||||||
|
*/
|
||||||
|
void down(Duration timeout, List<String> arguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run {@code docker compose start} to start services. Waits until all containers are
|
* Run {@code docker compose start} to start services. Waits until all containers are
|
||||||
* started and healthy.
|
* started and healthy.
|
||||||
@ -58,6 +76,15 @@ public interface DockerCompose {
|
|||||||
*/
|
*/
|
||||||
void start(LogLevel logLevel);
|
void start(LogLevel logLevel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @param arguments the arguments to pass to the start command
|
||||||
|
* @since 3.4.0
|
||||||
|
*/
|
||||||
|
void start(LogLevel logLevel, List<String> arguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run {@code docker compose stop} to stop any running services.
|
* 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
|
* @param timeout the amount of time to wait or {@link #FORCE_STOP} to stop without
|
||||||
@ -65,6 +92,15 @@ public interface DockerCompose {
|
|||||||
*/
|
*/
|
||||||
void stop(Duration timeout);
|
void stop(Duration timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* @param arguments the arguments to pass to the stop command
|
||||||
|
* @since 3.4.0
|
||||||
|
*/
|
||||||
|
void stop(Duration timeout, List<String> arguments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return if services have been defined in the {@link DockerComposeFile} for the
|
* Return if services have been defined in the {@link DockerComposeFile} for the
|
||||||
* active profiles.
|
* active profiles.
|
||||||
|
@ -125,13 +125,14 @@ class DockerComposeLifecycleManager {
|
|||||||
logger.info(skip.getLogMessage());
|
logger.info(skip.getLogMessage());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
|
start.getCommand().applyTo(dockerCompose, start.getLogLevel(), start.getArguments());
|
||||||
runningServices = dockerCompose.getRunningServices();
|
runningServices = dockerCompose.getRunningServices();
|
||||||
if (wait == Wait.ONLY_IF_STARTED) {
|
if (wait == Wait.ONLY_IF_STARTED) {
|
||||||
wait = Wait.ALWAYS;
|
wait = Wait.ALWAYS;
|
||||||
}
|
}
|
||||||
if (lifecycleManagement.shouldStop()) {
|
if (lifecycleManagement.shouldStop()) {
|
||||||
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
|
this.shutdownHandlers
|
||||||
|
.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout(), stop.getArguments()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.lifecycle;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -155,6 +156,11 @@ public class DockerComposeProperties {
|
|||||||
*/
|
*/
|
||||||
private Skip skip = Skip.IF_RUNNING;
|
private Skip skip = Skip.IF_RUNNING;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arguments to pass to the start command.
|
||||||
|
*/
|
||||||
|
private final List<String> arguments = new ArrayList<>();
|
||||||
|
|
||||||
public StartCommand getCommand() {
|
public StartCommand getCommand() {
|
||||||
return this.command;
|
return this.command;
|
||||||
}
|
}
|
||||||
@ -179,6 +185,10 @@ public class DockerComposeProperties {
|
|||||||
this.skip = skip;
|
this.skip = skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getArguments() {
|
||||||
|
return this.arguments;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start command skip mode.
|
* Start command skip mode.
|
||||||
*/
|
*/
|
||||||
@ -233,6 +243,11 @@ public class DockerComposeProperties {
|
|||||||
*/
|
*/
|
||||||
private Duration timeout = Duration.ofSeconds(10);
|
private Duration timeout = Duration.ofSeconds(10);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arguments to pass to the stop command.
|
||||||
|
*/
|
||||||
|
private final List<String> arguments = new ArrayList<>();
|
||||||
|
|
||||||
public StopCommand getCommand() {
|
public StopCommand getCommand() {
|
||||||
return this.command;
|
return this.command;
|
||||||
}
|
}
|
||||||
@ -249,6 +264,10 @@ public class DockerComposeProperties {
|
|||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getArguments() {
|
||||||
|
return this.arguments;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.boot.docker.compose.lifecycle;
|
package org.springframework.boot.docker.compose.lifecycle;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.docker.compose.core.DockerCompose;
|
import org.springframework.boot.docker.compose.core.DockerCompose;
|
||||||
import org.springframework.boot.logging.LogLevel;
|
import org.springframework.boot.logging.LogLevel;
|
||||||
@ -34,21 +34,23 @@ public enum StartCommand {
|
|||||||
/**
|
/**
|
||||||
* Start using {@code docker compose up}.
|
* Start using {@code docker compose up}.
|
||||||
*/
|
*/
|
||||||
UP(DockerCompose::up),
|
UP {
|
||||||
|
@Override
|
||||||
|
void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List<String> arguments) {
|
||||||
|
dockerCompose.up(logLevel, arguments);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start using {@code docker compose start}.
|
* Start using {@code docker compose start}.
|
||||||
*/
|
*/
|
||||||
START(DockerCompose::start);
|
START {
|
||||||
|
@Override
|
||||||
private final BiConsumer<DockerCompose, LogLevel> action;
|
void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List<String> arguments) {
|
||||||
|
dockerCompose.start(logLevel, arguments);
|
||||||
StartCommand(BiConsumer<DockerCompose, LogLevel> action) {
|
|
||||||
this.action = action;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void applyTo(DockerCompose dockerCompose, LogLevel logLevel) {
|
abstract void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List<String> arguments);
|
||||||
this.action.accept(dockerCompose, logLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,7 +17,7 @@
|
|||||||
package org.springframework.boot.docker.compose.lifecycle;
|
package org.springframework.boot.docker.compose.lifecycle;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.docker.compose.core.DockerCompose;
|
import org.springframework.boot.docker.compose.core.DockerCompose;
|
||||||
|
|
||||||
@ -34,21 +34,23 @@ public enum StopCommand {
|
|||||||
/**
|
/**
|
||||||
* Stop using {@code docker compose down}.
|
* Stop using {@code docker compose down}.
|
||||||
*/
|
*/
|
||||||
DOWN(DockerCompose::down),
|
DOWN {
|
||||||
|
@Override
|
||||||
|
void applyTo(DockerCompose dockerCompose, Duration timeout, List<String> arguments) {
|
||||||
|
dockerCompose.down(timeout, arguments);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop using {@code docker compose stop}.
|
* Stop using {@code docker compose stop}.
|
||||||
*/
|
*/
|
||||||
STOP(DockerCompose::stop);
|
STOP {
|
||||||
|
@Override
|
||||||
private final BiConsumer<DockerCompose, Duration> action;
|
void applyTo(DockerCompose dockerCompose, Duration timeout, List<String> arguments) {
|
||||||
|
dockerCompose.stop(timeout, arguments);
|
||||||
StopCommand(BiConsumer<DockerCompose, Duration> action) {
|
|
||||||
this.action = action;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void applyTo(DockerCompose dockerCompose, Duration timeout) {
|
abstract void applyTo(DockerCompose dockerCompose, Duration timeout, List<String> arguments);
|
||||||
this.action.accept(dockerCompose, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -51,31 +51,31 @@ class DefaultDockerComposeTests {
|
|||||||
@Test
|
@Test
|
||||||
void upRunsUpCommand() {
|
void upRunsUpCommand() {
|
||||||
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
||||||
compose.up(LogLevel.OFF);
|
compose.up(LogLevel.OFF, Collections.emptyList());
|
||||||
then(this.cli).should().run(new DockerCliCommand.ComposeUp(LogLevel.OFF));
|
then(this.cli).should().run(new DockerCliCommand.ComposeUp(LogLevel.OFF, Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void downRunsDownCommand() {
|
void downRunsDownCommand() {
|
||||||
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
||||||
Duration timeout = Duration.ofSeconds(1);
|
Duration timeout = Duration.ofSeconds(1);
|
||||||
compose.down(timeout);
|
compose.down(timeout, Collections.emptyList());
|
||||||
then(this.cli).should().run(new DockerCliCommand.ComposeDown(timeout));
|
then(this.cli).should().run(new DockerCliCommand.ComposeDown(timeout, Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void startRunsStartCommand() {
|
void startRunsStartCommand() {
|
||||||
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
||||||
compose.start(LogLevel.OFF);
|
compose.start(LogLevel.OFF, Collections.emptyList());
|
||||||
then(this.cli).should().run(new DockerCliCommand.ComposeStart(LogLevel.OFF));
|
then(this.cli).should().run(new DockerCliCommand.ComposeStart(LogLevel.OFF, Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void stopRunsStopCommand() {
|
void stopRunsStopCommand() {
|
||||||
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
|
||||||
Duration timeout = Duration.ofSeconds(1);
|
Duration timeout = Duration.ofSeconds(1);
|
||||||
compose.stop(timeout);
|
compose.stop(timeout, Collections.emptyList());
|
||||||
then(this.cli).should().run(new DockerCliCommand.ComposeStop(timeout));
|
then(this.cli).should().run(new DockerCliCommand.ComposeStop(timeout, Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -68,35 +68,37 @@ class DockerCliCommandTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void composeUp() {
|
void composeUp() {
|
||||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeUp(LogLevel.INFO);
|
DockerCliCommand<?> command = new DockerCliCommand.ComposeUp(LogLevel.INFO, List.of("--renew-anon-volumes"));
|
||||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||||
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
|
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
|
||||||
assertThat(command.getCommand()).containsExactly("up", "--no-color", "--detach", "--wait");
|
assertThat(command.getCommand()).containsExactly("up", "--no-color", "--detach", "--wait",
|
||||||
|
"--renew-anon-volumes");
|
||||||
assertThat(command.deserialize("[]")).isNull();
|
assertThat(command.deserialize("[]")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void composeDown() {
|
void composeDown() {
|
||||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeDown(Duration.ofSeconds(1));
|
DockerCliCommand<?> command = new DockerCliCommand.ComposeDown(Duration.ofSeconds(1),
|
||||||
|
List.of("--remove-orphans"));
|
||||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||||
assertThat(command.getCommand()).containsExactly("down", "--timeout", "1");
|
assertThat(command.getCommand()).containsExactly("down", "--timeout", "1", "--remove-orphans");
|
||||||
assertThat(command.deserialize("[]")).isNull();
|
assertThat(command.deserialize("[]")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void composeStart() {
|
void composeStart() {
|
||||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeStart(LogLevel.INFO);
|
DockerCliCommand<?> command = new DockerCliCommand.ComposeStart(LogLevel.INFO, List.of("--dry-run"));
|
||||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||||
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
|
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
|
||||||
assertThat(command.getCommand()).containsExactly("start");
|
assertThat(command.getCommand()).containsExactly("start", "--dry-run");
|
||||||
assertThat(command.deserialize("[]")).isNull();
|
assertThat(command.deserialize("[]")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void composeStop() {
|
void composeStop() {
|
||||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeStop(Duration.ofSeconds(1));
|
DockerCliCommand<?> command = new DockerCliCommand.ComposeStop(Duration.ofSeconds(1), List.of("--dry-run"));
|
||||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||||
assertThat(command.getCommand()).containsExactly("stop", "--timeout", "1");
|
assertThat(command.getCommand()).containsExactly("stop", "--timeout", "1", "--dry-run");
|
||||||
assertThat(command.deserialize("[]")).isNull();
|
assertThat(command.deserialize("[]")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class DockerCliIntegrationTests {
|
|||||||
DockerCliComposeConfigResponse config = cli.run(new ComposeConfig());
|
DockerCliComposeConfigResponse config = cli.run(new ComposeConfig());
|
||||||
assertThat(config.services()).containsOnlyKeys("redis");
|
assertThat(config.services()).containsOnlyKeys("redis");
|
||||||
// Run up
|
// Run up
|
||||||
cli.run(new ComposeUp(LogLevel.INFO));
|
cli.run(new ComposeUp(LogLevel.INFO, Collections.emptyList()));
|
||||||
// Run ps and use id to run inspect on the id
|
// Run ps and use id to run inspect on the id
|
||||||
ps = cli.run(new ComposePs());
|
ps = cli.run(new ComposePs());
|
||||||
assertThat(ps).hasSize(1);
|
assertThat(ps).hasSize(1);
|
||||||
@ -86,14 +86,14 @@ class DockerCliIntegrationTests {
|
|||||||
assertThat(inspect).isNotEmpty();
|
assertThat(inspect).isNotEmpty();
|
||||||
assertThat(inspect.get(0).id()).startsWith(id);
|
assertThat(inspect.get(0).id()).startsWith(id);
|
||||||
// Run stop, then run ps and verify the services are stopped
|
// Run stop, then run ps and verify the services are stopped
|
||||||
cli.run(new ComposeStop(Duration.ofSeconds(10)));
|
cli.run(new ComposeStop(Duration.ofSeconds(10), Collections.emptyList()));
|
||||||
ps = cli.run(new ComposePs());
|
ps = cli.run(new ComposePs());
|
||||||
assertThat(ps).isEmpty();
|
assertThat(ps).isEmpty();
|
||||||
// Run start, verify service is there, then run down and verify they are gone
|
// Run start, verify service is there, then run down and verify they are gone
|
||||||
cli.run(new ComposeStart(LogLevel.INFO));
|
cli.run(new ComposeStart(LogLevel.INFO, Collections.emptyList()));
|
||||||
ps = cli.run(new ComposePs());
|
ps = cli.run(new ComposePs());
|
||||||
assertThat(ps).hasSize(1);
|
assertThat(ps).hasSize(1);
|
||||||
cli.run(new ComposeDown(Duration.ofSeconds(10)));
|
cli.run(new ComposeDown(Duration.ofSeconds(10), Collections.emptyList()));
|
||||||
ps = cli.run(new ComposePs());
|
ps = cli.run(new ComposePs());
|
||||||
assertThat(ps).isEmpty();
|
assertThat(ps).isEmpty();
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ class DockerCliIntegrationTests {
|
|||||||
|
|
||||||
private static void quietComposeDown(DockerCli cli) {
|
private static void quietComposeDown(DockerCli cli) {
|
||||||
try {
|
try {
|
||||||
cli.run(new ComposeDown(Duration.ZERO));
|
cli.run(new ComposeDown(Duration.ZERO, Collections.emptyList()));
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException ex) {
|
||||||
// Ignore
|
// Ignore
|
||||||
|
@ -182,10 +182,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
assertThat(listener.getEvent()).isNull();
|
assertThat(listener.getEvent()).isNull();
|
||||||
then(this.dockerCompose).should().hasDefinedServices();
|
then(this.dockerCompose).should().hasDefinedServices();
|
||||||
then(this.dockerCompose).should(never()).up(any());
|
then(this.dockerCompose).should(never()).up(any(), any());
|
||||||
then(this.dockerCompose).should(never()).start(any());
|
then(this.dockerCompose).should(never()).start(any(), any());
|
||||||
then(this.dockerCompose).should(never()).down(any());
|
then(this.dockerCompose).should(never()).down(any(), any());
|
||||||
then(this.dockerCompose).should(never()).stop(any());
|
then(this.dockerCompose).should(never()).stop(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -197,10 +197,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should().up(any());
|
then(this.dockerCompose).should().up(any(), any());
|
||||||
then(this.dockerCompose).should(never()).start(any());
|
then(this.dockerCompose).should(never()).start(any(), any());
|
||||||
then(this.dockerCompose).should().stop(any());
|
then(this.dockerCompose).should().stop(any(), any());
|
||||||
then(this.dockerCompose).should(never()).down(any());
|
then(this.dockerCompose).should(never()).down(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -212,10 +212,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should(never()).up(any());
|
then(this.dockerCompose).should(never()).up(any(), any());
|
||||||
then(this.dockerCompose).should(never()).start(any());
|
then(this.dockerCompose).should(never()).start(any(), any());
|
||||||
then(this.dockerCompose).should(never()).down(any());
|
then(this.dockerCompose).should(never()).down(any(), any());
|
||||||
then(this.dockerCompose).should(never()).stop(any());
|
then(this.dockerCompose).should(never()).stop(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -227,10 +227,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should(never()).up(any());
|
then(this.dockerCompose).should(never()).up(any(), any());
|
||||||
then(this.dockerCompose).should(never()).start(any());
|
then(this.dockerCompose).should(never()).start(any(), any());
|
||||||
then(this.dockerCompose).should(never()).down(any());
|
then(this.dockerCompose).should(never()).down(any(), any());
|
||||||
then(this.dockerCompose).should(never()).stop(any());
|
then(this.dockerCompose).should(never()).stop(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -242,10 +242,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should().up(any());
|
then(this.dockerCompose).should().up(any(), any());
|
||||||
then(this.dockerCompose).should(never()).start(any());
|
then(this.dockerCompose).should(never()).start(any(), any());
|
||||||
then(this.dockerCompose).should(never()).down(any());
|
then(this.dockerCompose).should(never()).down(any(), any());
|
||||||
then(this.dockerCompose).should(never()).stop(any());
|
then(this.dockerCompose).should(never()).stop(any(), any());
|
||||||
this.shutdownHandlers.assertNoneAdded();
|
this.shutdownHandlers.assertNoneAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,10 +259,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should(never()).up(any());
|
then(this.dockerCompose).should(never()).up(any(), any());
|
||||||
then(this.dockerCompose).should().start(any());
|
then(this.dockerCompose).should().start(any(), any());
|
||||||
then(this.dockerCompose).should().stop(any());
|
then(this.dockerCompose).should().stop(any(), any());
|
||||||
then(this.dockerCompose).should(never()).down(any());
|
then(this.dockerCompose).should(never()).down(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -275,10 +275,10 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should().up(any());
|
then(this.dockerCompose).should().up(any(), any());
|
||||||
then(this.dockerCompose).should(never()).start(any());
|
then(this.dockerCompose).should(never()).start(any(), any());
|
||||||
then(this.dockerCompose).should(never()).stop(any());
|
then(this.dockerCompose).should(never()).stop(any(), any());
|
||||||
then(this.dockerCompose).should().down(any());
|
then(this.dockerCompose).should().down(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -292,7 +292,7 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
this.shutdownHandlers.run();
|
this.shutdownHandlers.run();
|
||||||
assertThat(listener.getEvent()).isNotNull();
|
assertThat(listener.getEvent()).isNotNull();
|
||||||
then(this.dockerCompose).should().stop(timeout);
|
then(this.dockerCompose).should().stop(timeout, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -390,7 +390,7 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||||
this.properties.getStart().setSkip(Skip.IF_RUNNING);
|
this.properties.getStart().setSkip(Skip.IF_RUNNING);
|
||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
then(this.dockerCompose).should().up(any());
|
then(this.dockerCompose).should().up(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -398,7 +398,7 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
setUpRunningServices();
|
setUpRunningServices();
|
||||||
this.properties.getStart().setSkip(Skip.IF_RUNNING);
|
this.properties.getStart().setSkip(Skip.IF_RUNNING);
|
||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
then(this.dockerCompose).should(never()).up(any());
|
then(this.dockerCompose).should(never()).up(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -406,7 +406,7 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||||
this.properties.getStart().setSkip(Skip.NEVER);
|
this.properties.getStart().setSkip(Skip.NEVER);
|
||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
then(this.dockerCompose).should().up(any());
|
then(this.dockerCompose).should().up(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -414,7 +414,7 @@ class DockerComposeLifecycleManagerTests {
|
|||||||
setUpRunningServices();
|
setUpRunningServices();
|
||||||
this.properties.getStart().setSkip(Skip.NEVER);
|
this.properties.getStart().setSkip(Skip.NEVER);
|
||||||
this.lifecycleManager.start();
|
this.lifecycleManager.start();
|
||||||
then(this.dockerCompose).should().up(any());
|
then(this.dockerCompose).should().up(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpRunningServices() {
|
private void setUpRunningServices() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.springframework.boot.docker.compose.lifecycle;
|
package org.springframework.boot.docker.compose.lifecycle;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.boot.docker.compose.core.DockerCompose;
|
import org.springframework.boot.docker.compose.core.DockerCompose;
|
||||||
@ -33,18 +36,23 @@ import static org.mockito.Mockito.mock;
|
|||||||
*/
|
*/
|
||||||
class StartCommandTests {
|
class StartCommandTests {
|
||||||
|
|
||||||
private DockerCompose dockerCompose = mock(DockerCompose.class);
|
private DockerCompose dockerCompose;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
this.dockerCompose = mock(DockerCompose.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyToWhenUp() {
|
void applyToWhenUp() {
|
||||||
StartCommand.UP.applyTo(this.dockerCompose, LogLevel.INFO);
|
StartCommand.UP.applyTo(this.dockerCompose, LogLevel.INFO, Collections.emptyList());
|
||||||
then(this.dockerCompose).should().up(LogLevel.INFO);
|
then(this.dockerCompose).should().up(LogLevel.INFO, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyToWhenStart() {
|
void applyToWhenStart() {
|
||||||
StartCommand.START.applyTo(this.dockerCompose, LogLevel.INFO);
|
StartCommand.START.applyTo(this.dockerCompose, LogLevel.INFO, Collections.emptyList());
|
||||||
then(this.dockerCompose).should().start(LogLevel.INFO);
|
then(this.dockerCompose).should().start(LogLevel.INFO, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,7 +17,9 @@
|
|||||||
package org.springframework.boot.docker.compose.lifecycle;
|
package org.springframework.boot.docker.compose.lifecycle;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.boot.docker.compose.core.DockerCompose;
|
import org.springframework.boot.docker.compose.core.DockerCompose;
|
||||||
@ -34,20 +36,25 @@ import static org.mockito.Mockito.mock;
|
|||||||
*/
|
*/
|
||||||
class StopCommandTests {
|
class StopCommandTests {
|
||||||
|
|
||||||
private DockerCompose dockerCompose = mock(DockerCompose.class);
|
private DockerCompose dockerCompose;
|
||||||
|
|
||||||
private Duration duration = Duration.ofSeconds(10);
|
private final Duration duration = Duration.ofSeconds(10);
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
this.dockerCompose = mock(DockerCompose.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyToWhenDown() {
|
void applyToWhenDown() {
|
||||||
StopCommand.DOWN.applyTo(this.dockerCompose, this.duration);
|
StopCommand.DOWN.applyTo(this.dockerCompose, this.duration, Collections.emptyList());
|
||||||
then(this.dockerCompose).should().down(this.duration);
|
then(this.dockerCompose).should().down(this.duration, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyToWhenStart() {
|
void applyToWhenStart() {
|
||||||
StopCommand.STOP.applyTo(this.dockerCompose, this.duration);
|
StopCommand.STOP.applyTo(this.dockerCompose, this.duration, Collections.emptyList());
|
||||||
then(this.dockerCompose).should().stop(this.duration);
|
then(this.dockerCompose).should().stop(this.duration, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user