Print detailed information about docker build command
See: https://www.pivotaltracker.com/story/show/175202648
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.eclipse.boot.dash.docker.runtarget;
|
||||
|
||||
public class CommandUtil {
|
||||
|
||||
public static String escape(String[] command) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String piece : command) {
|
||||
if (!first) {
|
||||
buf.append(" ");
|
||||
}
|
||||
for (int i = 0; i < piece.length(); i++) {
|
||||
char c = piece.charAt(i);
|
||||
if (needsEscape(c)) {
|
||||
buf.append("\\");
|
||||
}
|
||||
buf.append(c);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static boolean needsEscape(char c) {
|
||||
return Character.isWhitespace(c) || c=='"' || c=='\\';
|
||||
}
|
||||
}
|
||||
@@ -85,8 +85,6 @@ import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class DockerApp extends AbstractDisposable implements App, ChildBearing, Deletable, ProjectRelatable, DesiredInstanceCount, SystemPropertySupport, LogSource, DevtoolsConnectable {
|
||||
|
||||
|
||||
|
||||
private static final String DOCKER_IO_LIBRARY = "docker.io/library/";
|
||||
private static final String[] NO_STRINGS = new String[0];
|
||||
private DockerClient client;
|
||||
@@ -312,9 +310,6 @@ public class DockerApp extends AbstractDisposable implements App, ChildBearing,
|
||||
ImmutableList.Builder<PortBinding> portBindings = ImmutableList.builder();
|
||||
|
||||
CreateContainerCmd cb = client.createContainerCmd(image);
|
||||
// cb.withHostName(getName());
|
||||
// cb.withNetworkMode("bridge");
|
||||
// cb.withAliases(getName());
|
||||
|
||||
int appLocalPort = PortFinder.findFreePort();
|
||||
int appContainerPort = 8080;
|
||||
@@ -392,7 +387,6 @@ public class DockerApp extends AbstractDisposable implements App, ChildBearing,
|
||||
}
|
||||
|
||||
private static final Pattern BUILT_IMAGE_MESSAGE = Pattern.compile("Successfully built image.*\\'(.*)\\'");
|
||||
// private static final Pattern BUILT_IMAGE_MESSAGE = Pattern.compile("Successfully built image");
|
||||
|
||||
private String build(AppConsole console) throws Exception {
|
||||
AtomicReference<String> image = new AtomicReference<>();
|
||||
@@ -400,8 +394,11 @@ public class DockerApp extends AbstractDisposable implements App, ChildBearing,
|
||||
String[] command = getBuildCommand(directory);
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder(command).directory(directory);
|
||||
builder.environment().put("JAVA_HOME", getJavaHome());
|
||||
|
||||
String jhome = getJavaHome();
|
||||
builder.environment().put("JAVA_HOME", jhome);
|
||||
console.write("build.env.JAVA_HOME="+jhome, LogType.STDOUT);
|
||||
console.write("build.directory="+directory, LogType.STDOUT);
|
||||
console.write("build.command="+CommandUtil.escape(command), LogType.STDOUT);
|
||||
Process process = builder.start();
|
||||
LineBasedStreamGobler outputGobler = new LineBasedStreamGobler(process.getInputStream(), (line) -> {
|
||||
System.out.println(line);
|
||||
|
||||
Reference in New Issue
Block a user