Skip to content

Commit bb58dbc

Browse files
committed
fix: Podman image inspect digest for local images
When using `docker://` prefix to use a base image from the local docker daemon, Jib expects the `{{.Id}}` field from the `docker image inspect` output to contain a valid image digest prefixed with `sha256:`. However, with Podman this is not the case and such builds fail with an "Invalid digest" exception, because Podman returns only the 64-char hash value in the `{{.Id}}` field without the `sha256:` prefix. `CliDockerClient` already has the functionality to deal with the hashes without the `sha256:` prefix. A new method, `fromDigestOrgHash` has beend added to `DescriptorDigest` which first checks for the digest prefix and then checks for the hash. This allows full backwards compatibility and accepts the Podman version of the image Ids.
1 parent 45610ea commit bb58dbc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

jib-core/src/main/java/com/google/cloud/tools/jib/api/DescriptorDigest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ public static DescriptorDigest fromDigest(String digest) throws DigestException
7979
return new DescriptorDigest(hash);
8080
}
8181

82+
public static DescriptorDigest fromDigestOrHash(String digestOrHash) throws DigestException {
83+
if (digestOrHash.matches(DIGEST_REGEX)) {
84+
return fromDigest(digestOrHash);
85+
} else if (digestOrHash.matches(HASH_REGEX)) {
86+
return fromHash(digestOrHash);
87+
}
88+
throw new DigestException("Invalid digest or hash: " + digestOrHash);
89+
}
90+
8291
private DescriptorDigest(String hash) {
8392
this.hash = hash;
8493
}

jib-core/src/main/java/com/google/cloud/tools/jib/docker/CliDockerClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public long getSize() {
8181

8282
@Override
8383
public DescriptorDigest getImageId() throws DigestException {
84-
return DescriptorDigest.fromDigest(imageId);
84+
return DescriptorDigest.fromDigestOrHash(imageId);
8585
}
8686

8787
/**

0 commit comments

Comments
 (0)