Skip to content

Commit

Permalink
fix: Podman image inspect digest for local images
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mihalyr committed Aug 22, 2024
1 parent 45610ea commit bb58dbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public static DescriptorDigest fromDigest(String digest) throws DigestException
return new DescriptorDigest(hash);
}

public static DescriptorDigest fromDigestOrHash(String digestOrHash) throws DigestException {
if (digestOrHash.matches(DIGEST_REGEX)) {
return fromDigest(digestOrHash);
} else if (digestOrHash.matches(HASH_REGEX)) {
return fromHash(digestOrHash);
}
throw new DigestException("Invalid digest or hash: " + digestOrHash);
}

private DescriptorDigest(String hash) {
this.hash = hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public long getSize() {

@Override
public DescriptorDigest getImageId() throws DigestException {
return DescriptorDigest.fromDigest(imageId);
return DescriptorDigest.fromDigestOrHash(imageId);
}

/**
Expand Down

0 comments on commit bb58dbc

Please sign in to comment.