Skip to content

Commit

Permalink
Merge pull request #810 from chonton/master
Browse files Browse the repository at this point in the history
Allow comma separated list of container names in dependsOn elements
  • Loading branch information
rhuss authored Jul 11, 2017
2 parents 5143cab + e95f9cb commit e771c09
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion samples/custom-net/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<alias>box2</alias>
</network>
<dependsOn>
<dependsOn>box1</dependsOn>
<container>box1</container>
</dependsOn>
<namingStrategy>none</namingStrategy>
<cmd>
Expand Down
1 change: 1 addition & 0 deletions src/main/asciidoc/inc/start/_depends-on.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Your containers should preferably be able to deal with temporarily unresolvable

The `<dependsOn>` configuration can be used to expresses custom network dependencies between your containers. `docker:start` will ensure that all dependencies a container depends on are completely started (fulfilling all `<wait>` conditions) before the depending container is started.

Additionally, each `<container>` element can specify a comma separated set of containers. Comma (and whitespace) can be used to separate containers since valid docker container names contain only characters, digits, underscores, periods and dashes.

.Example
[source,xml]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void addVolumes(RunImageConfiguration runConfig, List<String> ret) {

private void addLinks(RunImageConfiguration runConfig, List<String> ret) {
// Custom networks can have circular links, no need to be considered for the starting order.
if (runConfig.getLinks() != null && !runConfig.getNetworkingConfig().isCustomNetwork()) {
if (!runConfig.getNetworkingConfig().isCustomNetwork()) {
for (String[] link : EnvUtil.splitOnLastColon(runConfig.getLinks())) {
ret.add(link[0]);
}
Expand All @@ -114,7 +114,7 @@ private void addContainerNetwork(RunImageConfiguration runConfig, List<String> r

private void addDependsOn(RunImageConfiguration runConfig, List<String> ret) {
// Only used in custom networks.
if (runConfig.getDependsOn() != null && runConfig.getNetworkingConfig().isCustomNetwork()) {
if (runConfig.getNetworkingConfig().isCustomNetwork()) {
for (String link : runConfig.getDependsOn()) {
ret.add(link);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import io.fabric8.maven.docker.util.EnvUtil;

import javax.annotation.Nonnull;

/**
* @author roland
* @since 02.09.14
Expand Down Expand Up @@ -189,8 +191,9 @@ public String getDomainname() {
return domainname;
}

@Nonnull
public List<String> getDependsOn() {
return dependsOn;
return EnvUtil.splitAtCommasAndTrim(dependsOn);
}

public String getUser() {
Expand Down Expand Up @@ -271,6 +274,7 @@ public RunVolumeConfiguration getVolumeConfiguration() {
return volumes;
}

@Nonnull
public List<String> getLinks() {
return EnvUtil.splitAtCommasAndTrim(links);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/fabric8/maven/docker/util/EnvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;

import static java.util.concurrent.TimeUnit.*;

/**
Expand Down Expand Up @@ -124,6 +126,7 @@ public Iterable<String> apply(String input) {
* @param input Iterable over strings.
* @return An Iterable over string which breaks down each input element at comma boundaries
*/
@Nonnull
public static List<String> splitAtCommasAndTrim(Iterable<String> input) {
if(input==null) {
return Collections.emptyList();
Expand Down

0 comments on commit e771c09

Please sign in to comment.