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:
Moritz Halbritter 2024-06-18 12:27:18 +02:00
parent 17ca0421e7
commit 6c0c9b9a80
13 changed files with 244 additions and 112 deletions

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -48,22 +48,42 @@ class DefaultDockerCompose implements DockerCompose {
@Override
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
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
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
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

View File

@ -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");
* 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> {
ComposeUp(LogLevel logLevel) {
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "up", "--no-color", "--detach", "--wait");
ComposeUp(LogLevel logLevel, List<String> arguments) {
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> {
ComposeDown(Duration timeout) {
super(Type.DOCKER_COMPOSE, Void.class, false, "down", "--timeout", Long.toString(timeout.toSeconds()));
ComposeDown(Duration timeout, List<String> arguments) {
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> {
ComposeStart(LogLevel logLevel) {
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "start");
ComposeStart(LogLevel logLevel, List<String> arguments) {
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> {
ComposeStop(Duration timeout) {
super(Type.DOCKER_COMPOSE, Void.class, false, "stop", "--timeout", Long.toString(timeout.toSeconds()));
ComposeStop(Duration timeout, List<String> arguments) {
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);
}
}

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -44,6 +44,15 @@ public interface DockerCompose {
*/
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.
* @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);
/**
* 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
* started and healthy.
@ -58,6 +76,15 @@ public interface DockerCompose {
*/
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.
* @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);
/**
* 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
* active profiles.

View File

@ -125,13 +125,14 @@ class DockerComposeLifecycleManager {
logger.info(skip.getLogMessage());
}
else {
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
start.getCommand().applyTo(dockerCompose, start.getLogLevel(), start.getArguments());
runningServices = dockerCompose.getRunningServices();
if (wait == Wait.ONLY_IF_STARTED) {
wait = Wait.ALWAYS;
}
if (lifecycleManagement.shouldStop()) {
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
this.shutdownHandlers
.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout(), stop.getArguments()));
}
}
}

View File

@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.lifecycle;
import java.io.File;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -155,6 +156,11 @@ public class DockerComposeProperties {
*/
private Skip skip = Skip.IF_RUNNING;
/**
* Arguments to pass to the start command.
*/
private final List<String> arguments = new ArrayList<>();
public StartCommand getCommand() {
return this.command;
}
@ -179,6 +185,10 @@ public class DockerComposeProperties {
this.skip = skip;
}
public List<String> getArguments() {
return this.arguments;
}
/**
* Start command skip mode.
*/
@ -233,6 +243,11 @@ public class DockerComposeProperties {
*/
private Duration timeout = Duration.ofSeconds(10);
/**
* Arguments to pass to the stop command.
*/
private final List<String> arguments = new ArrayList<>();
public StopCommand getCommand() {
return this.command;
}
@ -249,6 +264,10 @@ public class DockerComposeProperties {
this.timeout = timeout;
}
public List<String> getArguments() {
return this.arguments;
}
}
/**

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
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.logging.LogLevel;
@ -34,21 +34,23 @@ public enum StartCommand {
/**
* 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(DockerCompose::start);
START {
@Override
void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List<String> arguments) {
dockerCompose.start(logLevel, arguments);
}
};
private final BiConsumer<DockerCompose, LogLevel> action;
StartCommand(BiConsumer<DockerCompose, LogLevel> action) {
this.action = action;
}
void applyTo(DockerCompose dockerCompose, LogLevel logLevel) {
this.action.accept(dockerCompose, logLevel);
}
abstract void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List<String> arguments);
}

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -17,7 +17,7 @@
package org.springframework.boot.docker.compose.lifecycle;
import java.time.Duration;
import java.util.function.BiConsumer;
import java.util.List;
import org.springframework.boot.docker.compose.core.DockerCompose;
@ -34,21 +34,23 @@ public enum StopCommand {
/**
* 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(DockerCompose::stop);
STOP {
@Override
void applyTo(DockerCompose dockerCompose, Duration timeout, List<String> arguments) {
dockerCompose.stop(timeout, arguments);
}
};
private final BiConsumer<DockerCompose, Duration> action;
StopCommand(BiConsumer<DockerCompose, Duration> action) {
this.action = action;
}
void applyTo(DockerCompose dockerCompose, Duration timeout) {
this.action.accept(dockerCompose, timeout);
}
abstract void applyTo(DockerCompose dockerCompose, Duration timeout, List<String> arguments);
}

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -51,31 +51,31 @@ class DefaultDockerComposeTests {
@Test
void upRunsUpCommand() {
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
compose.up(LogLevel.OFF);
then(this.cli).should().run(new DockerCliCommand.ComposeUp(LogLevel.OFF));
compose.up(LogLevel.OFF, Collections.emptyList());
then(this.cli).should().run(new DockerCliCommand.ComposeUp(LogLevel.OFF, Collections.emptyList()));
}
@Test
void downRunsDownCommand() {
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
Duration timeout = Duration.ofSeconds(1);
compose.down(timeout);
then(this.cli).should().run(new DockerCliCommand.ComposeDown(timeout));
compose.down(timeout, Collections.emptyList());
then(this.cli).should().run(new DockerCliCommand.ComposeDown(timeout, Collections.emptyList()));
}
@Test
void startRunsStartCommand() {
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
compose.start(LogLevel.OFF);
then(this.cli).should().run(new DockerCliCommand.ComposeStart(LogLevel.OFF));
compose.start(LogLevel.OFF, Collections.emptyList());
then(this.cli).should().run(new DockerCliCommand.ComposeStart(LogLevel.OFF, Collections.emptyList()));
}
@Test
void stopRunsStopCommand() {
DefaultDockerCompose compose = new DefaultDockerCompose(this.cli, HOST);
Duration timeout = Duration.ofSeconds(1);
compose.stop(timeout);
then(this.cli).should().run(new DockerCliCommand.ComposeStop(timeout));
compose.stop(timeout, Collections.emptyList());
then(this.cli).should().run(new DockerCliCommand.ComposeStop(timeout, Collections.emptyList()));
}
@Test

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -68,35 +68,37 @@ class DockerCliCommandTests {
@Test
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.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();
}
@Test
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.getCommand()).containsExactly("down", "--timeout", "1");
assertThat(command.getCommand()).containsExactly("down", "--timeout", "1", "--remove-orphans");
assertThat(command.deserialize("[]")).isNull();
}
@Test
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.getLogLevel()).isEqualTo(LogLevel.INFO);
assertThat(command.getCommand()).containsExactly("start");
assertThat(command.getCommand()).containsExactly("start", "--dry-run");
assertThat(command.deserialize("[]")).isNull();
}
@Test
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.getCommand()).containsExactly("stop", "--timeout", "1");
assertThat(command.getCommand()).containsExactly("stop", "--timeout", "1", "--dry-run");
assertThat(command.deserialize("[]")).isNull();
}

View File

@ -77,7 +77,7 @@ class DockerCliIntegrationTests {
DockerCliComposeConfigResponse config = cli.run(new ComposeConfig());
assertThat(config.services()).containsOnlyKeys("redis");
// 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
ps = cli.run(new ComposePs());
assertThat(ps).hasSize(1);
@ -86,14 +86,14 @@ class DockerCliIntegrationTests {
assertThat(inspect).isNotEmpty();
assertThat(inspect.get(0).id()).startsWith(id);
// 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());
assertThat(ps).isEmpty();
// 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());
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());
assertThat(ps).isEmpty();
}
@ -105,7 +105,7 @@ class DockerCliIntegrationTests {
private static void quietComposeDown(DockerCli cli) {
try {
cli.run(new ComposeDown(Duration.ZERO));
cli.run(new ComposeDown(Duration.ZERO, Collections.emptyList()));
}
catch (RuntimeException ex) {
// Ignore

View File

@ -182,10 +182,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
assertThat(listener.getEvent()).isNull();
then(this.dockerCompose).should().hasDefinedServices();
then(this.dockerCompose).should(never()).up(any());
then(this.dockerCompose).should(never()).start(any());
then(this.dockerCompose).should(never()).down(any());
then(this.dockerCompose).should(never()).stop(any());
then(this.dockerCompose).should(never()).up(any(), any());
then(this.dockerCompose).should(never()).start(any(), any());
then(this.dockerCompose).should(never()).down(any(), any());
then(this.dockerCompose).should(never()).stop(any(), any());
}
@Test
@ -197,10 +197,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should().up(any());
then(this.dockerCompose).should(never()).start(any());
then(this.dockerCompose).should().stop(any());
then(this.dockerCompose).should(never()).down(any());
then(this.dockerCompose).should().up(any(), any());
then(this.dockerCompose).should(never()).start(any(), any());
then(this.dockerCompose).should().stop(any(), any());
then(this.dockerCompose).should(never()).down(any(), any());
}
@Test
@ -212,10 +212,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should(never()).up(any());
then(this.dockerCompose).should(never()).start(any());
then(this.dockerCompose).should(never()).down(any());
then(this.dockerCompose).should(never()).stop(any());
then(this.dockerCompose).should(never()).up(any(), any());
then(this.dockerCompose).should(never()).start(any(), any());
then(this.dockerCompose).should(never()).down(any(), any());
then(this.dockerCompose).should(never()).stop(any(), any());
}
@Test
@ -227,10 +227,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should(never()).up(any());
then(this.dockerCompose).should(never()).start(any());
then(this.dockerCompose).should(never()).down(any());
then(this.dockerCompose).should(never()).stop(any());
then(this.dockerCompose).should(never()).up(any(), any());
then(this.dockerCompose).should(never()).start(any(), any());
then(this.dockerCompose).should(never()).down(any(), any());
then(this.dockerCompose).should(never()).stop(any(), any());
}
@Test
@ -242,10 +242,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should().up(any());
then(this.dockerCompose).should(never()).start(any());
then(this.dockerCompose).should(never()).down(any());
then(this.dockerCompose).should(never()).stop(any());
then(this.dockerCompose).should().up(any(), any());
then(this.dockerCompose).should(never()).start(any(), any());
then(this.dockerCompose).should(never()).down(any(), any());
then(this.dockerCompose).should(never()).stop(any(), any());
this.shutdownHandlers.assertNoneAdded();
}
@ -259,10 +259,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should(never()).up(any());
then(this.dockerCompose).should().start(any());
then(this.dockerCompose).should().stop(any());
then(this.dockerCompose).should(never()).down(any());
then(this.dockerCompose).should(never()).up(any(), any());
then(this.dockerCompose).should().start(any(), any());
then(this.dockerCompose).should().stop(any(), any());
then(this.dockerCompose).should(never()).down(any(), any());
}
@Test
@ -275,10 +275,10 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should().up(any());
then(this.dockerCompose).should(never()).start(any());
then(this.dockerCompose).should(never()).stop(any());
then(this.dockerCompose).should().down(any());
then(this.dockerCompose).should().up(any(), any());
then(this.dockerCompose).should(never()).start(any(), any());
then(this.dockerCompose).should(never()).stop(any(), any());
then(this.dockerCompose).should().down(any(), any());
}
@Test
@ -292,7 +292,7 @@ class DockerComposeLifecycleManagerTests {
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(listener.getEvent()).isNotNull();
then(this.dockerCompose).should().stop(timeout);
then(this.dockerCompose).should().stop(timeout, Collections.emptyList());
}
@Test
@ -390,7 +390,7 @@ class DockerComposeLifecycleManagerTests {
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
this.properties.getStart().setSkip(Skip.IF_RUNNING);
this.lifecycleManager.start();
then(this.dockerCompose).should().up(any());
then(this.dockerCompose).should().up(any(), any());
}
@Test
@ -398,7 +398,7 @@ class DockerComposeLifecycleManagerTests {
setUpRunningServices();
this.properties.getStart().setSkip(Skip.IF_RUNNING);
this.lifecycleManager.start();
then(this.dockerCompose).should(never()).up(any());
then(this.dockerCompose).should(never()).up(any(), any());
}
@Test
@ -406,7 +406,7 @@ class DockerComposeLifecycleManagerTests {
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
this.properties.getStart().setSkip(Skip.NEVER);
this.lifecycleManager.start();
then(this.dockerCompose).should().up(any());
then(this.dockerCompose).should().up(any(), any());
}
@Test
@ -414,7 +414,7 @@ class DockerComposeLifecycleManagerTests {
setUpRunningServices();
this.properties.getStart().setSkip(Skip.NEVER);
this.lifecycleManager.start();
then(this.dockerCompose).should().up(any());
then(this.dockerCompose).should().up(any(), any());
}
private void setUpRunningServices() {

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -16,6 +16,9 @@
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.springframework.boot.docker.compose.core.DockerCompose;
@ -33,18 +36,23 @@ import static org.mockito.Mockito.mock;
*/
class StartCommandTests {
private DockerCompose dockerCompose = mock(DockerCompose.class);
private DockerCompose dockerCompose;
@BeforeEach
void setUp() {
this.dockerCompose = mock(DockerCompose.class);
}
@Test
void applyToWhenUp() {
StartCommand.UP.applyTo(this.dockerCompose, LogLevel.INFO);
then(this.dockerCompose).should().up(LogLevel.INFO);
StartCommand.UP.applyTo(this.dockerCompose, LogLevel.INFO, Collections.emptyList());
then(this.dockerCompose).should().up(LogLevel.INFO, Collections.emptyList());
}
@Test
void applyToWhenStart() {
StartCommand.START.applyTo(this.dockerCompose, LogLevel.INFO);
then(this.dockerCompose).should().start(LogLevel.INFO);
StartCommand.START.applyTo(this.dockerCompose, LogLevel.INFO, Collections.emptyList());
then(this.dockerCompose).should().start(LogLevel.INFO, Collections.emptyList());
}
}

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -17,7 +17,9 @@
package org.springframework.boot.docker.compose.lifecycle;
import java.time.Duration;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.docker.compose.core.DockerCompose;
@ -34,20 +36,25 @@ import static org.mockito.Mockito.mock;
*/
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
void applyToWhenDown() {
StopCommand.DOWN.applyTo(this.dockerCompose, this.duration);
then(this.dockerCompose).should().down(this.duration);
StopCommand.DOWN.applyTo(this.dockerCompose, this.duration, Collections.emptyList());
then(this.dockerCompose).should().down(this.duration, Collections.emptyList());
}
@Test
void applyToWhenStart() {
StopCommand.STOP.applyTo(this.dockerCompose, this.duration);
then(this.dockerCompose).should().stop(this.duration);
StopCommand.STOP.applyTo(this.dockerCompose, this.duration, Collections.emptyList());
then(this.dockerCompose).should().stop(this.duration, Collections.emptyList());
}
}