Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/bob/docker_hub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ defmodule Bob.DockerHub do
end

def parse(result) do
# Reject corrupt images
# Reject corrupt images, and the attestation manifest BuildKit pushes next
# to each image, which Docker Hub lists with an "unknown" architecture
images =
Enum.reject(result["images"] || [], fn image ->
image["digest"] in [nil, ""] or image["architecture"] in [nil, ""]
image["digest"] in [nil, ""] or image["architecture"] in [nil, "", "unknown"]
end)

built_at = docker_hub_timestamp(result, images)
Expand Down
40 changes: 40 additions & 0 deletions test/bob/docker_hub_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ defmodule Bob.DockerHubTest do
) == {"27.0", ["amd64", "arm64"], @image_pushed_at}
end

test "leaves attestation manifests out of the archs" do
assert DockerHub.parse(
tag_payload(%{
"last_updated" => "2025-01-02T03:04:05.123456Z",
"images" => [
image("amd64", "sha256:amd64", "2025-02-03T04:05:06Z"),
image("unknown", "sha256:attestation", "2025-02-03T04:05:06Z")
]
})
) == {"27.0", ["amd64"], @built_at}
end

test "rejects a tag holding only an attestation manifest" do
assert DockerHub.parse(
tag_payload(%{
"last_updated" => "2025-01-02T03:04:05.123456Z",
"images" => [image("unknown", "sha256:attestation", "2025-02-03T04:05:06Z")]
})
) == nil
end

test "rejects images without a digest" do
assert DockerHub.parse(
tag_payload(%{
Expand Down Expand Up @@ -173,6 +194,25 @@ defmodule Bob.DockerHubTest do
refute Bob.Job.DockerManifest.publish?("erlang", "27.0", [{"amd64", @built_at}], fetch)
end

test "adds an arch to a manifest that carries an attestation manifest" do
body =
JSON.encode!(
tag_payload(%{
"last_updated" => "2025-01-02T03:04:05.123456Z",
"images" => [
image("amd64", "sha256:amd64", "2025-01-02T03:04:05Z"),
image("unknown", "sha256:attestation", "2025-01-02T03:04:05Z")
]
})
)

opts = request_opts([{:ok, 200, [], body}])
fetch = fn repo, tag -> DockerHub.fetch_tag(repo, tag, opts) end
sources = [{"amd64", @built_at}, {"arm64", @image_pushed_at}]

assert Bob.Job.DockerManifest.publish?("erlang", "27.0", sources, fetch)
end

test "does not publish a partial manifest when a source lookup fails" do
opts = request_opts(List.duplicate({:error, :closed}, 10))
fetch = fn repo, tag -> DockerHub.fetch_tag(repo, tag, opts) end
Expand Down
Loading