Skip to content

Commit 358f68a

Browse files
authored
Handle Created empty field from image inspect (#8302)
- For docker engine versions up to 24.0.x: Created="0001-01-01T00:00:00Z" for all API versions (max 1.43) - For docker engine versions 25.0.0-25.0.3: Created="" for all API versions (max 1.44) => this is considered a bug - For docker engine versions 25.0.4+: - Created="0001-01-01T00:00:00Z" for API versions up to 1.43 (backwards compatibility) - Created is absent for API versions 1.44+
1 parent 5926769 commit 358f68a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

core/src/main/java/org/testcontainers/images/ImageData.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ public class ImageData {
1717
Instant createdAt;
1818

1919
static ImageData from(InspectImageResponse inspectImageResponse) {
20-
return ImageData
21-
.builder()
22-
.createdAt(ZonedDateTime.parse(inspectImageResponse.getCreated()).toInstant())
23-
.build();
20+
final String created = inspectImageResponse.getCreated();
21+
final Instant createdInstant = ((created == null) || created.isEmpty())
22+
? Instant.EPOCH
23+
: ZonedDateTime.parse(created).toInstant();
24+
return ImageData.builder().createdAt(createdInstant).build();
2425
}
2526

2627
static ImageData from(Image image) {
27-
return ImageData.builder().createdAt(Instant.ofEpochSecond(image.getCreated())).build();
28+
final Long created = image.getCreated();
29+
final Instant createdInstant = (created == null) ? Instant.EPOCH : Instant.ofEpochSecond(created);
30+
return ImageData.builder().createdAt(createdInstant).build();
2831
}
2932
}

0 commit comments

Comments
 (0)