Skip to content

Commit

Permalink
modify image resolve behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
anda-ren committed Feb 10, 2023
1 parent c35baaf commit 755236d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public class DockerImage {
public DockerImage(String imageNameFull) {
Matcher matcher = PATTERN_IMAGE_FULL.matcher(imageNameFull);
if (!matcher.matches()) {
this.registry = null;
this.registry = "";
this.image = imageNameFull;
} else {
String candidateRegistry = matcher.group(1);
if (isDomain(candidateRegistry)) {
this.registry = candidateRegistry;
image = matcher.group(2);
} else {
this.registry = null;
this.registry = "";
this.image = imageNameFull;
}

Expand All @@ -71,7 +71,7 @@ private static boolean isDomain(String candidate) {

public String resolve(String newRegistry) {
if (!StringUtils.hasText(newRegistry)) {
return image;
newRegistry = this.registry;
}
return StringUtils.trimTrailingCharacter(newRegistry, '/') + SLASH + image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@ public void testIpPortConstructor() {
@Test
public void testOnlyNameConstructor() {
DockerImage dockerImage = new DockerImage("star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507");
Assertions.assertEquals(new DockerImage(null, "star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507"),
Assertions.assertEquals(new DockerImage("", "star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507"),
dockerImage);

dockerImage = new DockerImage("star-whale/starwhale:latest");
Assertions.assertEquals(new DockerImage(null, "star-whale/starwhale:latest"), dockerImage);
Assertions.assertEquals(new DockerImage("", "star-whale/starwhale:latest"), dockerImage);

dockerImage = new DockerImage("star-whale/starwhale");
Assertions.assertEquals(new DockerImage(null, "star-whale/starwhale"), dockerImage);
Assertions.assertEquals(new DockerImage("", "star-whale/starwhale"), dockerImage);

}

@Test
public void testResolve() {
Map<String, String> images = Map.of("", "star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507",
Map<String, String> images = Map.of(
"docker.io", "docker.io/star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507",
"docker.io/", "docker.io/star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507",
"ghcr.io", "ghcr.io/star-whale/starwhale:0.3.0-rc.6-nightly-20220920-016d5507",
Expand Down Expand Up @@ -161,6 +161,8 @@ public void testResolve() {
.resolve(k)
));

images.forEach((k, v) -> Assertions.assertEquals(v, new DockerImage(v).resolve("")));

}

}

0 comments on commit 755236d

Please sign in to comment.