Skip to content

Commit

Permalink
Create the correct name for images (#70)
Browse files Browse the repository at this point in the history
* Fix tag replacement -> too much of the name is replaces when a port is contained in the image name

* Upgrade gradle to latest 2.x release
  • Loading branch information
guenhter authored and markelliot committed Sep 28, 2016
1 parent bce981a commit ed36c67
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,22 @@ class PalantirDockerPlugin implements Plugin<Project> {
}
}

private String computeName(String name, String tag) {
return name.replaceAll(":.*", "") + ":" + tag
private static String computeName(String name, String tag) {
int lastColon = name.lastIndexOf(':')
int lastSlash = name.lastIndexOf('/')

int endIndex;

// image_name -> this should remain
// host:port/image_name -> this should remain.
// host:port/image_name:v1 -> v1 should be replaced
if (lastColon > lastSlash) endIndex = lastColon
else endIndex = name.length()

return name.substring(0, endIndex) + ":" + tag
}

private String ucfirst(String str) {
private static String ucfirst(String str) {
StringBuffer sb = new StringBuffer(str);
sb.replace(0, 1, str.substring(0, 1).toUpperCase());
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.gradle.api.internal.artifacts.mvnsettings.DefaultMavenFileLocations
import org.gradle.api.internal.artifacts.mvnsettings.DefaultMavenSettingsProvider
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Unroll

class PalantirDockerPluginTests extends AbstractPluginTest {

Expand Down Expand Up @@ -417,5 +418,18 @@ class PalantirDockerPluginTests extends AbstractPluginTest {
execCond("docker rmi -f ${id}") || true
}

def 'check if compute name replaces the name correctly'() {
expect:
PalantirDockerPlugin.computeName(name, tag) == result

where:
name | tag | result
"v1" | "latest" | "v1:latest"
"v1:1" | "latest" | "v1:latest"
"host/v1" | "latest" | "host/v1:latest"
"host/v1:1" | "latest" | "host/v1:latest"
"host:port/v1" | "latest" | "host:port/v1:latest"
"host:port/v1:1" | "latest" | "host:port/v1:latest"
}
}

0 comments on commit ed36c67

Please sign in to comment.