ci: arm64-attach workflow - restore an arm64 entry on an existing tag without touching amd64
New manual workflow arm64-attach.yaml (cac / cac-fpm, one php leg per run, serialised): builds ONLY arm64 (QEMU, push by digest, same Dockerfile and build-args), checks the ELF machine type of the arm64 entry (AArch64) and of the existing amd64 entry (x86-64), checks PHP version parity, then re-creates the tag index from the existing amd64 entries (carried over by digest) + the new arm64 via scripts/attach-arm64-index.sh. The amd64 manifest digest is verified identical afterwards (previous index restored if not). Refuses when the tag already has arm64 unless force=true, and when the tag moved since the plan. - scripts/attach-arm64-index.sh (+ stub-registry test) - scripts/verify-image-arch.py (+ test): ELF e_machine check via docker cp, nothing is executed; idea from haproxy-manager-base PR #22 - multiarch-workflow.test.py: static wiring checks for the new workflow - Shell-Checks: new scripts and tests added Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
935b02eae4
commit
02de5c6568
7 files changed
+824
No files matched your search
@@ -323,5 +323,93 @@ class SingleLegDispatch(unittest.TestCase):
|
||||
self.assertIn('plan-legs:', err, only)
|
||||
|
||||
|
||||
# ---- arm64-attach.yaml: restore arm64 on an existing tag without touching amd64 --------------
|
||||
ATTACH_WF = os.path.join(ROOT, '.gitea', 'workflows', 'arm64-attach.yaml')
|
||||
|
||||
|
||||
class AttachWorkflow(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
with open(ATTACH_WF) as f:
|
||||
cls.text = f.read()
|
||||
cls.job = cls.text.split('\njobs:\n', 1)[1]
|
||||
|
||||
def test_manual_only_never_on_push_or_pr(self):
|
||||
head = self.text.split('\njobs:\n')[0]
|
||||
self.assertRegex(head, r'(?m)^on:\n workflow_dispatch:\n inputs:')
|
||||
self.assertNotRegex(head, r'(?m)^ (push|pull_request|schedule|workflow_run)\b')
|
||||
|
||||
def test_inputs_are_strings_and_runs_are_serialised(self):
|
||||
head = self.text.split('\njobs:\n')[0]
|
||||
for name in ('image', 'phpver', 'force'):
|
||||
self.assertRegex(head, r'(?m)^ %s:\n(?: .*\n)*? type: string' % name)
|
||||
self.assertRegex(head, r'(?m)^concurrency:\n group: arm64-attach\n cancel-in-progress: false$')
|
||||
|
||||
def test_inputs_never_interpolated_into_shell(self):
|
||||
for blk in re.findall(r'(?ms)^ run: .*?(?=^ - |\Z)', self.job):
|
||||
self.assertNotIn('${{', blk) # everything reaches the script through env:
|
||||
self.assertNotIn('github.event.inputs', self.job.split('Validate inputs', 1)[1].split('Login to Gitea', 1)[1])
|
||||
|
||||
def test_only_images_cac_and_cac_fpm_and_php82_to_86(self):
|
||||
v = step(self.job, 'Validate inputs')
|
||||
self.assertRegex(v, r'cac\)\s+dockerfile=Dockerfile;')
|
||||
self.assertRegex(v, r'cac-fpm\)\s+dockerfile=Dockerfile\.fpm;')
|
||||
self.assertIn('^8[2-6]$', v)
|
||||
self.assertEqual(re.findall(r'(?m)^ ([a-z-]+)\)', v), ['cac', 'cac-fpm'])
|
||||
self.assertNotIn('litespeed', v)
|
||||
self.assertNotIn('lsphp', v)
|
||||
|
||||
def test_arm64_only_push_by_digest_no_tags(self):
|
||||
self.assertEqual(len(re.findall(r'platforms: linux/', self.job)), 1)
|
||||
st = step(self.job, 'Build arm64')
|
||||
self.assertIn('platforms: linux/arm64\n', st)
|
||||
self.assertIn('push-by-digest=true,name-canonical=true,push=true', st)
|
||||
self.assertNotRegex(st, r'(?m)^\s+tags:')
|
||||
self.assertNotRegex(st, r'(?m)^\s+push: true')
|
||||
self.assertNotIn('continue-on-error', st) # the run exists only for this build
|
||||
self.assertNotIn('linux/amd64', st)
|
||||
self.assertNotIn('Build amd64', self.job)
|
||||
|
||||
def test_nothing_but_the_script_writes_a_tag(self):
|
||||
for bad in ('imagetools create', 'docker push', 'docker tag', '/cac:latest', '/cac-fpm:latest', 'ghcr.io', 'docker buildx build'):
|
||||
self.assertNotIn(bad, self.job, bad)
|
||||
self.assertEqual(self.job.count('scripts/attach-arm64-index.sh'), 2) # plan (read-only) + attach
|
||||
self.assertIn('--plan-only', step(self.job, 'Plan'))
|
||||
self.assertNotIn('--arm64', step(self.job, 'Plan'))
|
||||
|
||||
def test_step_order(self):
|
||||
names = [n for n, _ in steps(self.job)]
|
||||
order = ['Validate inputs', 'Login to Gitea', 'Plan', 'Build arm64', 'Verify ELF', 'PHP version parity', 'Attach']
|
||||
idx = [next(i for i, n in enumerate(names) if n.startswith(o)) for o in order]
|
||||
self.assertEqual(idx, sorted(idx))
|
||||
|
||||
def test_attach_step_guards(self):
|
||||
st = step(self.job, 'Attach')
|
||||
for need in ('--expect-index "$BEFORE"', '--arm64 "$ARM64_DIGEST"', '${{ steps.plan.outputs.before_index }}',
|
||||
'${{ steps.arm64.outputs.digest }}'):
|
||||
self.assertIn(need, st)
|
||||
self.assertNotIn('continue-on-error', st)
|
||||
|
||||
def test_both_platforms_elf_checked_before_attach(self):
|
||||
st = step(self.job, 'Verify ELF')
|
||||
self.assertIn('--platform linux/arm64', st)
|
||||
self.assertIn('--platform linux/amd64', st)
|
||||
self.assertIn('verify-image-arch.py', st)
|
||||
self.assertIn('/usr/sbin/httpd /usr/bin/php', step(self.job, 'Validate inputs'))
|
||||
self.assertIn('/usr/sbin/php-fpm /usr/bin/php', step(self.job, 'Validate inputs'))
|
||||
|
||||
def test_secrets_only_in_login_action(self):
|
||||
self.assertEqual(self.text.count('secrets.'), 2)
|
||||
lg = step(self.job, 'Login to Gitea')
|
||||
self.assertIn('secrets.CI_USER', lg)
|
||||
self.assertIn('secrets.CI_TOKEN', lg)
|
||||
self.assertNotIn('echo', lg)
|
||||
|
||||
def test_job_timeout_covers_the_leg_timeout(self):
|
||||
jt = int(re.search(r'(?m)^ timeout-minutes: (\d+)$', self.job).group(1))
|
||||
at = int(re.search(r'timeout-minutes: (\d+)', step(self.job, 'Build arm64')).group(1))
|
||||
self.assertGreater(jt, at + 20)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
Reference in new issue
Block a user