Skip to content

Commit 58ca0ed

Browse files
authored
Fix Docker Manifest path for collecting build-info (#643)
1 parent 2fbf187 commit 58ca0ed

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

build-info-extractor-docker/src/main/java/org/jfrog/build/extractor/docker/DockerUtils.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,19 @@ public static void downloadMarkerLayer(String repo, String imageName, String ima
256256
}
257257

258258
/**
259-
* @param imagePath - path to an image in artifactory without proxy e.g. image/image-tag
260-
* @param repo - target repo to search
261-
* @param cmd - docker push cmd/ docker pull cmd
259+
* @param imagePath - path to an image in artifactory without proxy e.g. hello-world/latest.
260+
* @param repo - The repository to use for searching.
261+
* @param cmd - docker push cmd/ docker pull cmd.
262262
* @return All possible paths in Artifactory in order to find image manifest using proxy.
263263
*/
264264
public static List<String> getArtManifestPath(String imagePath, String repo, CommandType cmd) {
265265
ArrayList<String> paths = new ArrayList<>();
266-
// Assuming reverse proxy e.g. ecosysjfrog-docker-local.jfrog.io.
266+
// If the docker tag is reverse proxy, e.g. ecosysjfrog-docker-local.jfrog.io/hello-world:latest
267+
// then the correct path is: repo = docker-local, imagePath = hello-world:latest
267268
paths.add(repo + "/" + imagePath);
268269

269-
// Assuming proxy-less e.g. orgab.jfrog.team/docker-local.
270+
// If the docker tag is proxy-less e.g. orgab.jfrog.team/docker-local/hello-world:latest
271+
// hen the correct path is: imagePath = docker-local/hello-world/latest
270272
paths.add(imagePath);
271273

272274
int totalSlash = org.apache.commons.lang3.StringUtils.countMatches(imagePath, "/");
@@ -277,7 +279,7 @@ public static List<String> getArtManifestPath(String imagePath, String repo, Com
277279
paths.add(repo + "/library/" + imagePath);
278280

279281
// Assume proxy-less - this time with 'library' as part of the path.
280-
int secondSlash = StringUtils.ordinalIndexOf(imagePath, "/", 2);
282+
int secondSlash = StringUtils.ordinalIndexOf(imagePath, "/", 1);
281283
paths.add(repo + "/library/" + imagePath.substring(secondSlash + 1));
282284

283285
return paths;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.jfrog.build.extractor.docker.extractor;
2+
3+
import org.jfrog.build.extractor.docker.DockerUtils;
4+
import org.testng.annotations.Test;
5+
6+
import java.util.List;
7+
import java.util.stream.Stream;
8+
9+
import static org.testng.Assert.assertEqualsNoOrder;
10+
11+
@Test
12+
public class DockerUtilsTest {
13+
@Test
14+
public void getArtManifestPathTest() {
15+
String imagePath = "hello-world:latest";
16+
String repository = "docker-local";
17+
DockerUtils.CommandType cmdType = DockerUtils.CommandType.Push;
18+
List<String> results = DockerUtils.getArtManifestPath(imagePath, repository, cmdType);
19+
assertEqualsNoOrder(results.toArray(), Stream.of("docker-local/hello-world:latest", "hello-world:latest").toArray());
20+
21+
cmdType = DockerUtils.CommandType.Pull;
22+
imagePath = "docker-local/hello-world:latest";
23+
results = DockerUtils.getArtManifestPath(imagePath, repository, cmdType);
24+
assertEqualsNoOrder(results.toArray(), Stream.of("docker-local/docker-local/hello-world:latest", "docker-local/hello-world:latest", "docker-local/library/docker-local/hello-world:latest", "docker-local/library/hello-world:latest").toArray());
25+
}
26+
}

0 commit comments

Comments
 (0)