Skip to content

Commit

Permalink
Evaluate DOCKER_HOST if no url is set (and don't use a default). Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Oct 10, 2014
1 parent 20fe2c4 commit 5e5ddcb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion samples/cargo-jolokia-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>org.jolokia</groupId>
<artifactId>docker-jolokia-demo</artifactId>
<version>0.9.9</version>
<version>0.9.10-SNAPSHOT</version>

<url>http://www.jolokia.org</url>

Expand Down
6 changes: 2 additions & 4 deletions samples/data-jolokia-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>org.jolokia</groupId>
<artifactId>docker-jolokia-demo</artifactId>
<version>0.9.9</version>
<version>0.9.10-SNAPSHOT</version>

<url>http://www.jolokia.org</url>

Expand Down Expand Up @@ -78,19 +78,17 @@
<configuration>
<!-- Docker Image to use -->
<image>${image}</image>
<url>http://192.168.59.104:2375</url>
<dataImage>jolokia/${project.artifactId}:${project.version}</dataImage>
<mergeData>false</mergeData>
<env>
<JOLOKIA_DISABLE>true</JOLOKIA_DISABLE>
<JOLOKIA_OFF>true</JOLOKIA_OFF>
<CATALINA_OPTS>-Xmx32m</CATALINA_OPTS>
</env>
<ports>
<!-- Port mappings: Container internal port (which must be exposed) will be
dynamically mapped and this (random) port will be assigned to the maven variable
${tomcat.port}. Multiple port mapping can be specified here-->
<port>jolokia.port:8080</port>
<port>jolokia.int.port:8778</port>
</ports>
<!-- The plugin waits until this URL is reachable via HTTP ... -->
<waitHttp>http://localhost:${jolokia.port}/jolokia</waitHttp>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/jolokia/docker/maven/AbstractDockerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements LogHand
protected Settings settings;

// URL to docker daemon
@Parameter(property = "docker.url",defaultValue = "http://localhost:2375")
@Parameter(property = "docker.url")
private String url;

// Name of the image for which to stop its containers. If none given, all are removed
Expand Down Expand Up @@ -72,7 +72,7 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements LogHand
public void execute() throws MojoExecutionException, MojoFailureException {
if (!skip) {
colorInit();
DockerAccess access = new DockerAccessUnirest(url.replaceFirst("^tcp:", "http:"), this);
DockerAccess access = new DockerAccessUnirest(extractUrl(), this);
access.start();
try {
executeInternal(access);
Expand All @@ -84,6 +84,15 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

// Check both, url and env DOCKER_HOST (first takes precedence)
private String extractUrl() {
String connect = url != null ? url : System.getenv("DOCKER_HOST");
if (connect == null) {
throw new IllegalArgumentException("No url given and now DOCKER_HOST environment variable set");
}
return connect.replaceFirst("^tcp:", "http:");
}

/**
* Hook for subclass for doing the real job
*
Expand Down

0 comments on commit 5e5ddcb

Please sign in to comment.