Skip to content

Commit dab8bb5

Browse files
committed
Fix ImageId retrieval (search from the end of the list of build-infos)
Relates to gesellix/docker-client#58 Relates to gesellix/gradle-docker-plugin#62
1 parent 79dc9e9 commit dab8bb5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,20 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro
270270
}
271271

272272
fun getImageId(buildInfos: List<BuildInfo>): ImageID? {
273-
val firstAux = buildInfos.stream()
273+
val reversedInfos = buildInfos.reversed()
274+
val firstAux = reversedInfos.stream()
274275
.filter { (_, _, _, _, _, _, _, aux): BuildInfo -> aux != null }
275276
.findFirst()
276277
if (firstAux.isPresent) {
277278
return firstAux.get().aux
278279
} else {
279-
val idFromStream = buildInfos.stream()
280+
val idFromStream = reversedInfos.stream()
280281
.filter { (_, stream): BuildInfo -> stream?.contains("Successfully built ")!! }
281282
.findFirst()
282283
return if (idFromStream.isPresent) {
283284
ImageID(idFromStream.get().stream!!.removePrefix("Successfully built ").replaceAfter('\n', "").trim())
284285
} else {
285-
val tagFromStream = buildInfos.stream()
286+
val tagFromStream = reversedInfos.stream()
286287
.filter { (_, stream): BuildInfo -> stream?.contains("Successfully tagged ")!! }
287288
.findFirst()
288289
tagFromStream.map { (_, stream): BuildInfo ->

api-client/src/test/java/de/gesellix/docker/remote/api/client/ImageApiTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void setup() {
2424
public void getImageIdFromAux() {
2525
List<BuildInfo> infos = new ArrayList<>();
2626
infos.add(new BuildInfo(null, null, null, null, null, null, null, new ImageID("sha256:expected-id")));
27+
infos.add(new BuildInfo(null, "Successfully built the wind\ncaught it", null, null, null, null, null, null));
2728
infos.add(new BuildInfo(null, "Successfully built f9d5f290d048\nfoo bar", null, null, null, null, null, null));
2829
infos.add(new BuildInfo(null, "Successfully tagged image:tag\nbar baz", null, null, null, null, null, null));
2930

@@ -35,6 +36,7 @@ public void getImageIdFromAux() {
3536
@Test
3637
public void getImageIdFromStreamWithBuildMessage() {
3738
List<BuildInfo> infos = new ArrayList<>();
39+
infos.add(new BuildInfo(null, "Successfully built the wind\ncaught it", null, null, null, null, null, null));
3840
infos.add(new BuildInfo(null, "Successfully built f9d5f290d048\nfoo bar", null, null, null, null, null, null));
3941
infos.add(new BuildInfo(null, "Successfully tagged image:tag\nbar baz", null, null, null, null, null, null));
4042

0 commit comments

Comments
 (0)