fix(promote): inspect pulled image digest

This commit is contained in:
aevolution-gitops-bot
2026-10-01 09:28:35 -04:00
parent 00a7eeb020
commit d105cbf5e7
2 changed files with 30 additions and 14 deletions
+15 -7
View File
@@ -40,7 +40,7 @@ jobs:
run: |
set -eu
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import base64, json, os, re, urllib.parse, urllib.request
import base64, json, os, re, subprocess, urllib.parse, urllib.request
registry = os.environ['HARBOR_REGISTRY']
repository = f"{os.environ['HARBOR_PROJECT']}/{os.environ['HARBOR_REPOSITORY']}"
@@ -66,13 +66,21 @@ jobs:
run, job = max(candidates, key=lambda item: (item[0].get('run_number', 0), item[0].get('run_attempt', 0)))
commit = run['head_sha']
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
logs_url = f"{api_root}/actions/jobs/{job['id']}/logs"
request = urllib.request.Request(logs_url, headers=api_headers)
with urllib.request.urlopen(request, timeout=30) as response:
logs = response.read().decode(errors='replace')
digest_match = re.search(r'Digest:\s+registry\.aeternalisgames\.com/[^@\s]+@(sha256:[0-9a-f]{64})', logs)
image = f"{registry}/{repository}:{tag}"
login = subprocess.run(
['docker', 'login', registry, '--username', os.environ['HARBOR_USERNAME'], '--password-stdin'],
input=os.environ['HARBOR_PASSWORD'].encode(), stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, check=False,
)
if login.returncode:
raise SystemExit(f'docker login failed with status {login.returncode}')
subprocess.run(['docker', 'pull', image], check=True)
repo_digest = subprocess.check_output(
['docker', 'image', 'inspect', '--format', '{{index .RepoDigests 0}}', image], text=True
).strip()
digest_match = re.search(r'@(sha256:[0-9a-f]{64})$', repo_digest)
if not digest_match:
raise SystemExit(f'No published digest found in successful server-image job {job["id"]}')
raise SystemExit(f'No immutable digest found after pulling {image}')
digest = digest_match.group(1)
print(f'digest={digest}')
print(f'build={digest.removeprefix("sha256:")}')
+15 -7
View File
@@ -40,7 +40,7 @@ jobs:
run: |
set -eu
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import base64, json, os, re, urllib.parse, urllib.request
import base64, json, os, re, subprocess, urllib.parse, urllib.request
registry = os.environ['HARBOR_REGISTRY']
repository = f"{os.environ['HARBOR_PROJECT']}/{os.environ['HARBOR_REPOSITORY']}"
@@ -66,13 +66,21 @@ jobs:
run, job = max(candidates, key=lambda item: (item[0].get('run_number', 0), item[0].get('run_attempt', 0)))
commit = run['head_sha']
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
logs_url = f"{api_root}/actions/jobs/{job['id']}/logs"
request = urllib.request.Request(logs_url, headers=api_headers)
with urllib.request.urlopen(request, timeout=30) as response:
logs = response.read().decode(errors='replace')
digest_match = re.search(r'Digest:\s+registry\.aeternalisgames\.com/[^@\s]+@(sha256:[0-9a-f]{64})', logs)
image = f"{registry}/{repository}:{tag}"
login = subprocess.run(
['docker', 'login', registry, '--username', os.environ['HARBOR_USERNAME'], '--password-stdin'],
input=os.environ['HARBOR_PASSWORD'].encode(), stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, check=False,
)
if login.returncode:
raise SystemExit(f'docker login failed with status {login.returncode}')
subprocess.run(['docker', 'pull', image], check=True)
repo_digest = subprocess.check_output(
['docker', 'image', 'inspect', '--format', '{{index .RepoDigests 0}}', image], text=True
).strip()
digest_match = re.search(r'@(sha256:[0-9a-f]{64})$', repo_digest)
if not digest_match:
raise SystemExit(f'No published digest found in successful server-image job {job["id"]}')
raise SystemExit(f'No immutable digest found after pulling {image}')
digest = digest_match.group(1)
print(f'digest={digest}')
print(f'build={digest.removeprefix("sha256:")}')