Skip to content
This repository has been archived by the owner on Aug 21, 2021. It is now read-only.

Commit

Permalink
allow multiple subcomponents in image names, fixing fabric8io#459
Browse files Browse the repository at this point in the history
  • Loading branch information
dweomer authored and Jacob L E Blain Christen committed May 26, 2016
1 parent eb872ba commit 04fb590
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/fabric8/maven/docker/util/ImageName.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public static void validate(String image) {
// https://github.com/docker/docker/blob/master/vendor/src/github.com/docker/distribution/reference/regexp.go
// https://github.com/docker/docker/blob/master/vendor/src/github.com/docker/distribution/reference/reference.go
private final Pattern NAME_COMP_REGEXP = Pattern.compile("[a-z0-9]+(?:(?:[._]|__|[-]*)[a-z0-9]+)*");
private final Pattern COMP_PATH_REGEXP = Pattern.compile("([/]?[a-z0-9]+(?:(?:[._]|__|[-]*)[a-z0-9]+)*)*");
private final String hPartPattern = "(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])";
private final Pattern REGISTRY_REGEXP = Pattern.compile("^" + hPartPattern + "(?:\\." + hPartPattern + ")*(?::[0-9]+)?$");
private final Pattern TAG_REGEXP = Pattern.compile("^[\\w][\\w.-]{0,127}$");
Expand All @@ -216,7 +217,7 @@ private void doValidate() {
String image = user != null ? repository.substring(user.length() + 1) : repository;
Object[] checks = new Object[] {
"registry",REGISTRY_REGEXP, registry,
"image", NAME_COMP_REGEXP, image,
"image", COMP_PATH_REGEXP, image,
"user", NAME_COMP_REGEXP, user,
"tag", TAG_REGEXP, tag
};
Expand Down
73 changes: 65 additions & 8 deletions src/test/java/io/fabric8/maven/docker/util/ImageNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,78 @@ public void simple() {
Object[] data = {
"jolokia/jolokia_demo",
r().repository("jolokia/jolokia_demo")
.fullName("jolokia/jolokia_demo").fullNameWithTag("jolokia/jolokia_demo:latest"),
.fullName("jolokia/jolokia_demo").fullNameWithTag("jolokia/jolokia_demo:latest"),

"jolokia/jolokia_demo:0.9.6",
r().repository("jolokia/jolokia_demo").tag("0.9.6")
.fullName("jolokia/jolokia_demo").fullNameWithTag("jolokia/jolokia_demo:0.9.6"),
.fullName("jolokia/jolokia_demo").fullNameWithTag("jolokia/jolokia_demo:0.9.6"),

"test.org/jolokia/jolokia_demo:0.9.6",
r().registry("test.org").repository("jolokia/jolokia_demo").tag("0.9.6")
.fullName("test.org/jolokia/jolokia_demo").fullNameWithTag("test.org/jolokia/jolokia_demo:0.9.6"),
.fullName("test.org/jolokia/jolokia_demo").fullNameWithTag("test.org/jolokia/jolokia_demo:0.9.6"),

"test.org/jolokia/jolokia_demo",
r().registry("test.org").repository("jolokia/jolokia_demo")
.fullName("test.org/jolokia/jolokia_demo").fullNameWithTag("test.org/jolokia/jolokia_demo:latest"),
.fullName("test.org/jolokia/jolokia_demo").fullNameWithTag("test.org/jolokia/jolokia_demo:latest"),

"test.org:8000/jolokia/jolokia_demo:8.0",
r().registry("test.org:8000").repository("jolokia/jolokia_demo").tag("8.0")
.fullName("test.org:8000/jolokia/jolokia_demo").fullNameWithTag("test.org:8000/jolokia/jolokia_demo:8.0"),
.fullName("test.org:8000/jolokia/jolokia_demo").fullNameWithTag("test.org:8000/jolokia/jolokia_demo:8.0"),

"jolokia_demo",
r().repository("jolokia_demo")
.fullName("jolokia_demo").fullNameWithTag("jolokia_demo:latest"),
.fullName("jolokia_demo").fullNameWithTag("jolokia_demo:latest"),

"jolokia_demo:0.9.6",
r().repository("jolokia_demo").tag("0.9.6")
.fullName("jolokia_demo").fullNameWithTag("jolokia_demo:0.9.6"),
.fullName("jolokia_demo").fullNameWithTag("jolokia_demo:0.9.6"),

"consol/tomcat-8.0:8.0.9",
r().repository("consol/tomcat-8.0").tag("8.0.9")
.fullName("consol/tomcat-8.0").fullNameWithTag("consol/tomcat-8.0:8.0.9")
.fullName("consol/tomcat-8.0").fullNameWithTag("consol/tomcat-8.0:8.0.9")
};

for (int i = 0; i < data.length; i += 2) {
ImageName name = new ImageName((String) data[i]);
Res res = (Res) data[i+1];
assertEquals("Registry " + i,res.registry,name.getRegistry());
assertEquals("Repository " + i,res.repository,name.getRepository());
assertEquals("Tag " + i,res.tag,name.getTag());
assertEquals("RepoWithRegistry " + i,res.fullName, name.getNameWithoutTag(null));
assertEquals("FullName " + i,res.fullNameWithTag,name.getFullName(null));
}
}

@Test
public void testMultipleSubComponents() {
Object[] data = {
"org/jolokia/jolokia_demo",
r().repository("org/jolokia/jolokia_demo")
.fullName("org/jolokia/jolokia_demo").fullNameWithTag("org/jolokia/jolokia_demo:latest"),

"org/jolokia/jolokia_demo:0.9.6",
r().repository("org/jolokia/jolokia_demo").tag("0.9.6")
.fullName("org/jolokia/jolokia_demo").fullNameWithTag("org/jolokia/jolokia_demo:0.9.6"),

"repo.example.com/org/jolokia/jolokia_demo:0.9.6",
r().registry("repo.example.com").repository("org/jolokia/jolokia_demo").tag("0.9.6")
.fullName("repo.example.com/org/jolokia/jolokia_demo").fullNameWithTag("repo.example.com/org/jolokia/jolokia_demo:0.9.6"),

"repo.example.com/org/jolokia/jolokia_demo",
r().registry("repo.example.com").repository("org/jolokia/jolokia_demo")
.fullName("repo.example.com/org/jolokia/jolokia_demo").fullNameWithTag("repo.example.com/org/jolokia/jolokia_demo:latest"),

"repo.example.com:8000/org/jolokia/jolokia_demo:8.0",
r().registry("repo.example.com:8000").repository("org/jolokia/jolokia_demo").tag("8.0")
.fullName("repo.example.com:8000/org/jolokia/jolokia_demo").fullNameWithTag("repo.example.com:8000/org/jolokia/jolokia_demo:8.0"),

"org/jolokia_demo",
r().repository("org/jolokia_demo")
.fullName("org/jolokia_demo").fullNameWithTag("org/jolokia_demo:latest"),

"org/jolokia_demo:0.9.6",
r().repository("org/jolokia_demo").tag("0.9.6")
.fullName("org/jolokia_demo").fullNameWithTag("org/jolokia_demo:0.9.6"),
};

for (int i = 0; i < data.length; i += 2) {
Expand Down Expand Up @@ -69,6 +112,20 @@ public void testRegistryNaming() throws Exception {
new ImageName("docker.jolokia.org/jolokia/jolokia_demo").getFullName(null));
}

@Test
public void testRegistryNamingExtended() throws Exception {
assertEquals("docker.jolokia.org/org/jolokia/jolokia_demo:0.18",
new ImageName("org/jolokia/jolokia_demo:0.18").getFullName("docker.jolokia.org"));
assertEquals("docker.jolokia.org/org/jolokia/jolokia_demo:latest",
new ImageName("org/jolokia/jolokia_demo").getFullName("docker.jolokia.org"));
assertEquals("org/jolokia/jolokia_demo:latest",
new ImageName("org/jolokia/jolokia_demo").getFullName(null));
assertEquals("docker.jolokia.org/org/jolokia/jolokia_demo:latest",
new ImageName("docker.jolokia.org/org/jolokia/jolokia_demo").getFullName("another.registry.org"));
assertEquals("docker.jolokia.org/org/jolokia/jolokia_demo:latest",
new ImageName("docker.jolokia.org/org/jolokia/jolokia_demo").getFullName(null));
}


@Test(expected = IllegalArgumentException.class)
public void testIllegalFormat() throws Exception {
Expand Down

0 comments on commit 04fb590

Please sign in to comment.