Skip to content

Commit

Permalink
[stable/2023.1] Fix collection builds (#1399)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammed Naser <[email protected]>
  • Loading branch information
vexxhost-bot and mnaser authored Jun 20, 2024
1 parent 0c1bdf9 commit c66b9cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 24 additions & 12 deletions build/pin-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@


def get_digest(image_ref, token=None):
url = f"https://{image_ref.domain()}/v2/{image_ref.path()}/manifests/{image_ref['tag']}"

headers = {}
if token:
headers["Authorization"] = f"Bearer {token}"
else:
r = requests.get(url, timeout=5, verify=False)
auth_header = r.headers.get("Www-Authenticate")
if auth_header:
realm = auth_header.split(",")[0].split("=")[1].strip('"')

r = requests.get(
realm,
timeout=5,
params={"scope": f"repository:{image_ref.path()}:pull"},
verify=False,
)
r.raise_for_status()

headers["Authorization"] = f"Bearer {r.json()['token']}"

try:
headers["Accept"] = "application/vnd.docker.distribution.manifest.v2+json"
Expand All @@ -27,6 +44,7 @@ def get_digest(image_ref, token=None):
f"https://{image_ref.domain()}/v2/{image_ref.path()}/manifests/{image_ref['tag']}",
timeout=5,
headers=headers,
verify=False,
)
r.raise_for_status()
return r.headers["Docker-Content-Digest"]
Expand All @@ -37,6 +55,7 @@ def get_digest(image_ref, token=None):
f"https://{image_ref.domain()}/v2/{image_ref.path()}/manifests/{image_ref['tag']}",
timeout=5,
headers=headers,
verify=False,
)
r.raise_for_status()
return r.headers["Docker-Content-Digest"]
Expand All @@ -46,12 +65,6 @@ def get_digest(image_ref, token=None):
def get_pinned_image(image_src):
image_ref = reference.Reference.parse(image_src)

if image_ref.domain() in (
"registry.k8s.io",
"us-docker.pkg.dev",
):
digest = get_digest(image_ref)

if image_ref.domain() == "registry.atmosphere.dev":
# Get token for docker.io
r = requests.get(
Expand All @@ -66,17 +79,15 @@ def get_pinned_image(image_src):
token = r.json()["token"]

digest = get_digest(image_ref, token=token)

if image_ref.domain() == "quay.io":
elif image_ref.domain() == "quay.io":
r = requests.get(
f"https://quay.io/api/v1/repository/{image_ref.path()}/tag/",
timeout=5,
params={"specificTag": image_ref["tag"]},
)
r.raise_for_status()
digest = r.json()["tags"][0]["manifest_digest"]

if image_ref.domain() == "docker.io":
elif image_ref.domain() == "docker.io":
# Get token for docker.io
r = requests.get(
"https://auth.docker.io/token",
Expand All @@ -99,8 +110,7 @@ def get_pinned_image(image_src):
)
r.raise_for_status()
digest = r.headers["Docker-Content-Digest"]

if image_ref.domain() == "ghcr.io":
elif image_ref.domain() == "ghcr.io":
# Get token for docker.io
r = requests.get(
"https://ghcr.io/token",
Expand All @@ -114,6 +124,8 @@ def get_pinned_image(image_src):
token = r.json()["token"]

digest = get_digest(image_ref, token=token)
else:
digest = get_digest(image_ref)

return f"{image_ref.domain()}/{image_ref.path()}:{image_ref['tag']}@{digest}"

Expand Down
4 changes: 4 additions & 0 deletions zuul.d/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
soft: true
- name: atmosphere-build-container-image-ironic
soft: true
- name: atmosphere-build-container-image-keepalived
soft: true
- name: atmosphere-build-container-image-keystone
soft: true
- name: atmosphere-build-container-image-kubernetes-entrypoint
Expand Down Expand Up @@ -102,6 +104,8 @@
soft: true
- name: atmosphere-upload-container-image-ironic
soft: true
- name: atmosphere-upload-container-image-keepalived
soft: true
- name: atmosphere-upload-container-image-keystone
soft: true
- name: atmosphere-upload-container-image-kubernetes-entrypoint
Expand Down

0 comments on commit c66b9cd

Please sign in to comment.