-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ContainerNetworking section with Aliases for custom network RunIm…
…ageConfigurations. Fixes #466 Signed-off-by: Daniel Wegener <daniel@wegener.me>
- Loading branch information
1 parent
7e1af5b
commit 6471c19
Showing
12 changed files
with
238 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<!-- | ||
Sample project for demonstrating the custom network mode | ||
Call it with 'mvn install'. | ||
It will automatically create the custom network "test-network" and create two automatically named containers that can | ||
talk to each other via their netAlias names. | ||
--> | ||
|
||
<parent> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>dmp-sample-parent</artifactId> | ||
<version>0.15.12</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>dmp-custom-net</artifactId> | ||
<version>0.15.12</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<configuration> | ||
<autoCreateCustomNetworks>true</autoCreateCustomNetworks> | ||
<watchInterval>500</watchInterval> | ||
<logDate>default</logDate> | ||
<verbose>true</verbose> | ||
<autoPull>always</autoPull> | ||
<images> | ||
<image> | ||
<alias>box1</alias> | ||
<name>busybox</name> | ||
<run> | ||
<net>test-network</net> | ||
<networkAlias>box1,box1-alternative</networkAlias> | ||
<namingStrategy>none</namingStrategy> | ||
<cmd> | ||
<exec> | ||
<args>sh</args> | ||
<args>-c</args> | ||
<args>tail -f /dev/null</args> | ||
</exec> | ||
</cmd> | ||
<log> | ||
<prefix>1</prefix> <color>cyan</color> | ||
</log> | ||
</run> | ||
</image> | ||
<image> | ||
<alias>box2</alias> | ||
<name>busybox</name> | ||
<run> | ||
<net>test-network</net> | ||
<networkAlias>box2</networkAlias> | ||
<namingStrategy>none</namingStrategy> | ||
<cmd> | ||
<exec> | ||
<args>sh</args> | ||
<args>-c</args> | ||
<args>nslookup box1-alternative; tail -f /dev/null</args> | ||
</exec> | ||
</cmd> | ||
<wait> | ||
<log>box1.test-network</log> | ||
</wait> | ||
<log> | ||
<prefix>2</prefix> <color>blue</color> | ||
</log> | ||
</run> | ||
</image> | ||
</images> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>start</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>stop</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/io/fabric8/maven/docker/access/ContainerNetworkingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.fabric8.maven.docker.access; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ContainerNetworkingConfig { | ||
|
||
final JSONObject startConfig = new JSONObject(); | ||
|
||
public ContainerNetworkingConfig() {} | ||
|
||
public ContainerNetworkingConfig endpointsConfig(Map<String, ContainerNetworkingEndpointsConfig> endpointsConfig) { | ||
final JSONObject endpointConfigMap = new JSONObject(); | ||
for (Map.Entry<String, ContainerNetworkingEndpointsConfig> entry : endpointsConfig.entrySet()) { | ||
endpointConfigMap.put(entry.getKey(), entry.getValue().toJsonObject()); | ||
} | ||
return add("EndpointsConfig", endpointConfigMap); | ||
} | ||
|
||
/** | ||
* Get JSON which is used for <em>starting</em> a container | ||
* | ||
* @return string representation for JSON representing the configuration for starting a container | ||
*/ | ||
public String toJson() { | ||
return startConfig.toString(); | ||
} | ||
|
||
public Object toJsonObject() { | ||
return startConfig; | ||
} | ||
|
||
ContainerNetworkingConfig addAsArray(String propKey, List<String> props) { | ||
if (props != null) { | ||
startConfig.put(propKey, new JSONArray(props)); | ||
} | ||
return this; | ||
} | ||
|
||
private ContainerNetworkingConfig add(String name, Object value) { | ||
if (value != null) { | ||
startConfig.put(name, value); | ||
} | ||
return this; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/io/fabric8/maven/docker/access/ContainerNetworkingEndpointsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.fabric8.maven.docker.access; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.util.List; | ||
|
||
public class ContainerNetworkingEndpointsConfig { | ||
|
||
final JSONObject startConfig = new JSONObject(); | ||
|
||
public ContainerNetworkingEndpointsConfig() {} | ||
|
||
public ContainerNetworkingEndpointsConfig aliases(List<String> aliases) { | ||
return addAsArray("Aliases", aliases); | ||
} | ||
|
||
|
||
/** | ||
* Get JSON which is used for <em>starting</em> a container | ||
* | ||
* @return string representation for JSON representing the configuration for starting a container | ||
*/ | ||
public String toJson() { | ||
return startConfig.toString(); | ||
} | ||
|
||
public Object toJsonObject() { | ||
return startConfig; | ||
} | ||
|
||
ContainerNetworkingEndpointsConfig addAsArray(String propKey, List<String> props) { | ||
if (props != null) { | ||
startConfig.put(propKey, new JSONArray(props)); | ||
} | ||
return this; | ||
} | ||
|
||
private ContainerNetworkingEndpointsConfig add(String name, Object value) { | ||
if (value != null) { | ||
startConfig.put(name, value); | ||
} | ||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters