Skip to content

Commit 3bb93b3

Browse files
committed
Remove --detach and --wait flags from docker compose start command
Closes gh-36908
1 parent 490c6d7 commit 3bb93b3

File tree

5 files changed

+138
-49
lines changed

5 files changed

+138
-49
lines changed

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static final class ComposeDown extends DockerCliCommand<Void> {
184184
static final class ComposeStart extends DockerCliCommand<Void> {
185185

186186
ComposeStart(LogLevel logLevel) {
187-
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "start", "--detach", "--wait");
187+
super(Type.DOCKER_COMPOSE, logLevel, Void.class, false, "start");
188188
}
189189

190190
}

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliCommandTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void composeStart() {
8888
DockerCliCommand<?> command = new DockerCliCommand.ComposeStart(LogLevel.INFO);
8989
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
9090
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
91-
assertThat(command.getCommand()).containsExactly("start", "--detach", "--wait");
91+
assertThat(command.getCommand()).containsExactly("start");
9292
assertThat(command.deserialize("[]")).isNull();
9393
}
9494

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docker.compose.core;
18+
19+
import java.io.File;
20+
import java.io.FileReader;
21+
import java.io.FileWriter;
22+
import java.io.IOException;
23+
import java.nio.file.Path;
24+
import java.time.Duration;
25+
import java.util.Collections;
26+
import java.util.List;
27+
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.io.TempDir;
30+
31+
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposeConfig;
32+
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposeDown;
33+
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposePs;
34+
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposeStart;
35+
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposeStop;
36+
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposeUp;
37+
import org.springframework.boot.docker.compose.core.DockerCliCommand.Inspect;
38+
import org.springframework.boot.logging.LogLevel;
39+
import org.springframework.boot.testsupport.process.DisabledIfProcessUnavailable;
40+
import org.springframework.boot.testsupport.testcontainers.DisabledIfDockerUnavailable;
41+
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
42+
import org.springframework.core.io.ClassPathResource;
43+
import org.springframework.util.FileCopyUtils;
44+
45+
import static org.assertj.core.api.Assertions.assertThat;
46+
47+
/**
48+
* Tests for {@link DockerCli}.
49+
*
50+
* @author Moritz Halbritter
51+
* @author Andy Wilkinson
52+
* @author Phillip Webb
53+
*/
54+
@DisabledIfDockerUnavailable
55+
@DisabledIfProcessUnavailable({ "docker", "compose" })
56+
class DockerCliIntegrationTests {
57+
58+
@TempDir
59+
private static Path tempDir;
60+
61+
@Test
62+
void runBasicCommand() {
63+
DockerCli cli = new DockerCli(null, null, Collections.emptySet());
64+
List<DockerCliContextResponse> context = cli.run(new DockerCliCommand.Context());
65+
assertThat(context).isNotEmpty();
66+
}
67+
68+
@Test
69+
void runLifecycle() throws IOException {
70+
File composeFile = createComposeFile();
71+
DockerCli cli = new DockerCli(null, DockerComposeFile.of(composeFile), Collections.emptySet());
72+
try {
73+
// Verify that no services are running (this is a fresh compose project)
74+
List<DockerCliComposePsResponse> ps = cli.run(new ComposePs());
75+
assertThat(ps).isEmpty();
76+
// List the config and verify that redis is there
77+
DockerCliComposeConfigResponse config = cli.run(new ComposeConfig());
78+
assertThat(config.services()).containsOnlyKeys("redis");
79+
// Run up
80+
cli.run(new ComposeUp(LogLevel.INFO));
81+
// Run ps and use id to run inspect on the id
82+
ps = cli.run(new ComposePs());
83+
assertThat(ps).hasSize(1);
84+
String id = ps.get(0).id();
85+
List<DockerCliInspectResponse> inspect = cli.run(new Inspect(List.of(id)));
86+
assertThat(inspect).isNotEmpty();
87+
assertThat(inspect.get(0).id()).isEqualTo(id);
88+
// Run stop, then run ps and verify the services are stopped
89+
cli.run(new ComposeStop(Duration.ofSeconds(10)));
90+
ps = cli.run(new ComposePs());
91+
assertThat(ps).isEmpty();
92+
// Run start, verify that service is there, then run down and verify they are
93+
// gone
94+
cli.run(new ComposeStart(LogLevel.INFO));
95+
ps = cli.run(new ComposePs());
96+
assertThat(ps).hasSize(1);
97+
cli.run(new ComposeDown(Duration.ofSeconds(10)));
98+
ps = cli.run(new ComposePs());
99+
assertThat(ps).isEmpty();
100+
}
101+
finally {
102+
// Clean up in any case
103+
quietComposeDown(cli);
104+
}
105+
}
106+
107+
private static void quietComposeDown(DockerCli cli) {
108+
try {
109+
cli.run(new ComposeDown(Duration.ZERO));
110+
}
111+
catch (RuntimeException ex) {
112+
// Ignore
113+
}
114+
}
115+
116+
private static File createComposeFile() throws IOException {
117+
File composeFile = new ClassPathResource("redis-compose.yaml", DockerCliIntegrationTests.class).getFile();
118+
File tempComposeFile = Path.of(tempDir.toString(), composeFile.getName()).toFile();
119+
String composeFileContent;
120+
try (FileReader reader = new FileReader(composeFile)) {
121+
composeFileContent = FileCopyUtils.copyToString(reader);
122+
}
123+
composeFileContent = composeFileContent.replace("{imageName}",
124+
DockerImageNames.redis().asCanonicalNameString());
125+
try (FileWriter writer = new FileWriter(tempComposeFile)) {
126+
FileCopyUtils.copy(composeFileContent, writer);
127+
}
128+
return tempComposeFile;
129+
}
130+
131+
}

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliTests.java

-47
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
redis:
3+
image: '{imageName}'
4+
ports:
5+
- '6379'

0 commit comments

Comments
 (0)