Skip to content

Commit

Permalink
Update documentation and minor fix (#610)
Browse files Browse the repository at this point in the history
Signed-off-by: Roland Huß <roland@ro14nd.de>
  • Loading branch information
rhuss committed Nov 17, 2016
1 parent 7f7ec29 commit 827281c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
8 changes: 8 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
- Fix issue with log statements which use a single argument form
- Fix bug in HTTP wait configuration when using an external property handler (#613)
- Fix NPE for "docker:log" when the container to log has already been stopped (#612)
- Allow a protocol (tcp/udp) for the specification of a port (#610)

The following variables in the assembly configuration has been renamed for consistencies sake:

* `basedir` --> `targetDir`
* `expoetBasedir` --> `exportTargetDir`

The old variable names are still accepted but will be removed for release 1.0

* **0.17.2** (2016-11-3)
- Fix issues with an empty Docker config file
Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/inc/build/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ a| Definition of a health check as described in <<build-healthcheck, Healthcheck
| if set to true then it will compress all the `runCmds` into a single `RUN` directive so that only one image layer is created.

| *ports*
| The exposed ports which is a list of `<port>` elements, one for each port to expose.
| The exposed ports which is a list of `<port>` elements, one for each port to expose. The format can be either pure numerical ("8080") or with the protocol attached ("8080/tcp"),

| *runCmds*
| Commands to be run during the build process. It contains *run* elements which are passed to the shell. The run commands are inserted right after the assembly and after *workdir* in to the Dockerfile. This tag is not to be confused with the `<run>` section for this image which specifies the runtime behaviour when starting containers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,48 +237,29 @@ private String quote(String value) {

private void addPorts(StringBuilder b) {
if (ports.size() > 0) {
String[] portsS = ports.toArray(new String[]{});
String[] portsS = new String[ports.size()];
int i = 0;
for(String port : portsS) {
validatePortMapping(port);
portsS[i++] = validatePortExposure(port);
}
DockerFileKeyword.EXPOSE.addTo(b, portsS);
}
}

// Pattern for splitting of the protocol part of the port.
private static final Pattern PROTOCOL_SPLIT_PATTERN = Pattern.compile("(.*?)(?:/(tcp|udp))?$");
private void validatePortMapping(String input) throws IllegalArgumentException {

private String validatePortExposure(String input) throws IllegalArgumentException {
try {
Matcher matcher = PROTOCOL_SPLIT_PATTERN.matcher(input);
Matcher matcher = Pattern.compile("(.*?)(?:/(tcp|udp))?$", Pattern.CASE_INSENSITIVE).matcher(input);
// Matches always. If there is a tcp/udp protocol, should end up in the second group
// and get factored out. If it's something invalid, it should get stuck to the first group.
// and get factored out. If it's something invalid, it should get stuck to the first group.
matcher.matches();

// First group is the port mapping.
// It may be split with a : in a variety of ways.
String mapping = matcher.group(1);
String[] mappingParts = mapping.split(":", 3);
if(mappingParts.length == 1) {
// Single port should be an integer.
Integer.valueOf(mappingParts[0]);
} else if (mappingParts.length == 2) {
// Map of port to external port. Both should be integers.
Integer.valueOf(mappingParts[0]);
Integer.valueOf(mappingParts[1]);
} else {
// If length is 3, then our first chunk is a hostname or IP address.
// Can't really validate that, but the 2nd and 3rd parts should be ports and therefore integers.
Integer.valueOf(mappingParts[1]);
Integer.valueOf(mappingParts[2]);
}


Integer.valueOf(matcher.group(1));
return input.toLowerCase();
} catch (NumberFormatException exp) {
throw new IllegalArgumentException("\nInvalid port mapping '" + input + "'\n" +
"Required format: '<hostIP>:<hostPort>:<containerPort>(/tcp|udp)'\n" +
"Required format: '<hostIP>(/tcp|udp)'\n" +
"See the reference manual for more details");
}
}
}

private void addOptimisation() {
if (runCmds != null && !runCmds.isEmpty() && shouldOptimise) {
Expand Down

0 comments on commit 827281c

Please sign in to comment.