Skip to content

Commit a215103

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents 5722c14 + 31ff7f1 commit a215103

File tree

1 file changed

+52
-1
lines changed
  • spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript

1 file changed

+52
-1
lines changed

spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.InputStream;
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
25+
import java.util.Collections;
2526
import java.util.List;
2627
import java.util.concurrent.TimeUnit;
2728
import java.util.regex.Pattern;
@@ -32,7 +33,9 @@
3233
import javax.ws.rs.client.WebTarget;
3334

3435
import com.github.dockerjava.api.DockerClient;
36+
import com.github.dockerjava.api.DockerClientException;
3537
import com.github.dockerjava.api.command.DockerCmd;
38+
import com.github.dockerjava.api.model.BuildResponseItem;
3639
import com.github.dockerjava.api.model.Frame;
3740
import com.github.dockerjava.core.CompressArchiveUtil;
3841
import com.github.dockerjava.core.DockerClientBuilder;
@@ -265,10 +268,58 @@ private DockerClient createClient() {
265268
}
266269

267270
private String buildImage(DockerClient docker) {
268-
BuildImageResultCallback resultCallback = new BuildImageResultCallback();
269271
String dockerfile = "src/test/resources/conf/" + this.os + "/" + this.version
270272
+ "/Dockerfile";
271273
String tag = "spring-boot-it/" + this.os.toLowerCase() + ":" + this.version;
274+
BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
275+
276+
private List<BuildResponseItem> items = new ArrayList<BuildResponseItem>();
277+
278+
@Override
279+
public void onNext(BuildResponseItem item) {
280+
super.onNext(item);
281+
this.items.add(item);
282+
}
283+
284+
@Override
285+
public String awaitImageId() {
286+
try {
287+
awaitCompletion();
288+
}
289+
catch (InterruptedException ex) {
290+
throw new DockerClientException(
291+
"Interrupted while waiting for image id", ex);
292+
}
293+
return getImageId();
294+
}
295+
296+
@SuppressWarnings("deprecation")
297+
private String getImageId() {
298+
if (this.items.isEmpty()) {
299+
throw new DockerClientException("Could not build image");
300+
}
301+
String imageId = extractImageId();
302+
if (imageId == null) {
303+
throw new DockerClientException("Could not build image: "
304+
+ this.items.get(this.items.size() - 1).getError());
305+
}
306+
return imageId;
307+
}
308+
309+
private String extractImageId() {
310+
Collections.reverse(this.items);
311+
for (BuildResponseItem item : this.items) {
312+
if (item.isErrorIndicated() || item.getStream() == null) {
313+
return null;
314+
}
315+
if (item.getStream().contains("Successfully built")) {
316+
return item.getStream().replace("Successfully built", "").trim();
317+
}
318+
}
319+
return null;
320+
}
321+
322+
};
272323
docker.buildImageCmd(new File(dockerfile)).withTag(tag).exec(resultCallback);
273324
String imageId = resultCallback.awaitImageId();
274325
return imageId;

0 commit comments

Comments
 (0)