fix(promote): inspect pulled image digest
This commit is contained in:
@@ -40,7 +40,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
python3 - <<'PY' >> "$GITHUB_OUTPUT"
|
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']
|
registry = os.environ['HARBOR_REGISTRY']
|
||||||
repository = f"{os.environ['HARBOR_PROJECT']}/{os.environ['HARBOR_REPOSITORY']}"
|
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)))
|
run, job = max(candidates, key=lambda item: (item[0].get('run_number', 0), item[0].get('run_attempt', 0)))
|
||||||
commit = run['head_sha']
|
commit = run['head_sha']
|
||||||
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
|
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
|
||||||
logs_url = f"{api_root}/actions/jobs/{job['id']}/logs"
|
image = f"{registry}/{repository}:{tag}"
|
||||||
request = urllib.request.Request(logs_url, headers=api_headers)
|
login = subprocess.run(
|
||||||
with urllib.request.urlopen(request, timeout=30) as response:
|
['docker', 'login', registry, '--username', os.environ['HARBOR_USERNAME'], '--password-stdin'],
|
||||||
logs = response.read().decode(errors='replace')
|
input=os.environ['HARBOR_PASSWORD'].encode(), stdout=subprocess.DEVNULL,
|
||||||
digest_match = re.search(r'Digest:\s+registry\.aeternalisgames\.com/[^@\s]+@(sha256:[0-9a-f]{64})', logs)
|
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:
|
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)
|
digest = digest_match.group(1)
|
||||||
print(f'digest={digest}')
|
print(f'digest={digest}')
|
||||||
print(f'build={digest.removeprefix("sha256:")}')
|
print(f'build={digest.removeprefix("sha256:")}')
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
python3 - <<'PY' >> "$GITHUB_OUTPUT"
|
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']
|
registry = os.environ['HARBOR_REGISTRY']
|
||||||
repository = f"{os.environ['HARBOR_PROJECT']}/{os.environ['HARBOR_REPOSITORY']}"
|
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)))
|
run, job = max(candidates, key=lambda item: (item[0].get('run_number', 0), item[0].get('run_attempt', 0)))
|
||||||
commit = run['head_sha']
|
commit = run['head_sha']
|
||||||
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
|
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
|
||||||
logs_url = f"{api_root}/actions/jobs/{job['id']}/logs"
|
image = f"{registry}/{repository}:{tag}"
|
||||||
request = urllib.request.Request(logs_url, headers=api_headers)
|
login = subprocess.run(
|
||||||
with urllib.request.urlopen(request, timeout=30) as response:
|
['docker', 'login', registry, '--username', os.environ['HARBOR_USERNAME'], '--password-stdin'],
|
||||||
logs = response.read().decode(errors='replace')
|
input=os.environ['HARBOR_PASSWORD'].encode(), stdout=subprocess.DEVNULL,
|
||||||
digest_match = re.search(r'Digest:\s+registry\.aeternalisgames\.com/[^@\s]+@(sha256:[0-9a-f]{64})', logs)
|
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:
|
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)
|
digest = digest_match.group(1)
|
||||||
print(f'digest={digest}')
|
print(f'digest={digest}')
|
||||||
print(f'build={digest.removeprefix("sha256:")}')
|
print(f'build={digest.removeprefix("sha256:")}')
|
||||||
|
|||||||
Reference in New Issue
Block a user