From 6c0c9b9a80cb2cf00e754bfc66e314bf242547f3 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 18 Jun 2024 12:27:18 +0200 Subject: [PATCH] Add properties to specify arguments to Docker Compose commands These new properties take a List: - spring.docker.compose.start.arguments - spring.docker.compose.stop.arguments Closes gh-38763 --- .../compose/core/DefaultDockerCompose.java | 30 +++++++-- .../docker/compose/core/DockerCliCommand.java | 53 ++++++++++++--- .../docker/compose/core/DockerCompose.java | 38 ++++++++++- .../DockerComposeLifecycleManager.java | 5 +- .../lifecycle/DockerComposeProperties.java | 19 ++++++ .../compose/lifecycle/StartCommand.java | 28 ++++---- .../docker/compose/lifecycle/StopCommand.java | 28 ++++---- .../core/DefaultDockerComposeTests.java | 18 ++--- .../compose/core/DockerCliCommandTests.java | 20 +++--- .../core/DockerCliIntegrationTests.java | 10 +-- .../DockerComposeLifecycleManagerTests.java | 66 +++++++++---------- .../compose/lifecycle/StartCommandTests.java | 20 ++++-- .../compose/lifecycle/StopCommandTests.java | 21 ++++-- 13 files changed, 244 insertions(+), 112 deletions(-) diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java index ff13762364f..e50340605b1 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java @@ -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 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 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 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 arguments) { + this.cli.run(new DockerCliCommand.ComposeStop(timeout, arguments)); } @Override diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliCommand.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliCommand.java index feb2d8dd6aa..e5a52215137 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliCommand.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliCommand.java @@ -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 { */ static final class ComposeUp extends DockerCliCommand { - ComposeUp(LogLevel logLevel) { - super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "up", "--no-color", "--detach", "--wait"); + ComposeUp(LogLevel logLevel, List arguments) { + super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, getCommand(arguments)); + } + + private static String[] getCommand(List arguments) { + List 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 { */ static final class ComposeDown extends DockerCliCommand { - ComposeDown(Duration timeout) { - super(Type.DOCKER_COMPOSE, Void.class, false, "down", "--timeout", Long.toString(timeout.toSeconds())); + ComposeDown(Duration timeout, List arguments) { + super(Type.DOCKER_COMPOSE, Void.class, false, getCommand(timeout, arguments)); + } + + private static String[] getCommand(Duration timeout, List arguments) { + List 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 { */ static final class ComposeStart extends DockerCliCommand { - ComposeStart(LogLevel logLevel) { - super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "start"); + ComposeStart(LogLevel logLevel, List arguments) { + super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, getCommand(arguments)); + } + + private static String[] getCommand(List arguments) { + List command = new ArrayList<>(); + command.add("start"); + command.addAll(arguments); + return command.toArray(String[]::new); } } @@ -194,8 +220,17 @@ abstract sealed class DockerCliCommand { */ static final class ComposeStop extends DockerCliCommand { - ComposeStop(Duration timeout) { - super(Type.DOCKER_COMPOSE, Void.class, false, "stop", "--timeout", Long.toString(timeout.toSeconds())); + ComposeStop(Duration timeout, List arguments) { + super(Type.DOCKER_COMPOSE, Void.class, false, getCommand(timeout, arguments)); + } + + private static String[] getCommand(Duration timeout, List arguments) { + List command = new ArrayList<>(); + command.add("stop"); + command.add("--timeout"); + command.add(Long.toString(timeout.toSeconds())); + command.addAll(arguments); + return command.toArray(String[]::new); } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCompose.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCompose.java index de27b8298c7..dc85888e965 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCompose.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCompose.java @@ -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 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 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 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 arguments); + /** * Return if services have been defined in the {@link DockerComposeFile} for the * active profiles. diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManager.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManager.java index 7b7a0952248..a93d5d4b4e6 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManager.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManager.java @@ -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())); } } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeProperties.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeProperties.java index df56f712379..e7042b78028 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeProperties.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeProperties.java @@ -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 arguments = new ArrayList<>(); + public StartCommand getCommand() { return this.command; } @@ -179,6 +185,10 @@ public class DockerComposeProperties { this.skip = skip; } + public List 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 arguments = new ArrayList<>(); + public StopCommand getCommand() { return this.command; } @@ -249,6 +264,10 @@ public class DockerComposeProperties { this.timeout = timeout; } + public List getArguments() { + return this.arguments; + } + } /** diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java index 6f3c86daa72..b33bb370290 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StartCommand.java @@ -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 arguments) { + dockerCompose.up(logLevel, arguments); + } + }, /** * Start using {@code docker compose start}. */ - START(DockerCompose::start); + START { + @Override + void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments) { + dockerCompose.start(logLevel, arguments); + } + }; - private final BiConsumer action; - - StartCommand(BiConsumer action) { - this.action = action; - } - - void applyTo(DockerCompose dockerCompose, LogLevel logLevel) { - this.action.accept(dockerCompose, logLevel); - } + abstract void applyTo(DockerCompose dockerCompose, LogLevel logLevel, List arguments); } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java index 942bab7b13e..839b1dc2390 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/lifecycle/StopCommand.java @@ -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 arguments) { + dockerCompose.down(timeout, arguments); + } + }, /** * Stop using {@code docker compose stop}. */ - STOP(DockerCompose::stop); + STOP { + @Override + void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments) { + dockerCompose.stop(timeout, arguments); + } + }; - private final BiConsumer action; - - StopCommand(BiConsumer action) { - this.action = action; - } - - void applyTo(DockerCompose dockerCompose, Duration timeout) { - this.action.accept(dockerCompose, timeout); - } + abstract void applyTo(DockerCompose dockerCompose, Duration timeout, List arguments); } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeTests.java index cb1bbf13d21..a03ff984dc1 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeTests.java @@ -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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliCommandTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliCommandTests.java index 4ed1d983bd1..6cafcb8bdf7 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliCommandTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliCommandTests.java @@ -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(); } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java index 409793e1930..c7bdc989636 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java @@ -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 diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java index 6d4cad8d69e..7e7a933e84b 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java @@ -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() { diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StartCommandTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StartCommandTests.java index e1c3dd20d5a..b44599c79db 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StartCommandTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StartCommandTests.java @@ -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()); } } diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StopCommandTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StopCommandTests.java index 59f5c816943..34fe5977d6b 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StopCommandTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/StopCommandTests.java @@ -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()); } }