feat(cms-deploy): restore exact registered Node base

This commit is contained in:
DCCONSTRUCTIONS
2026-11-05 10:09:53 +03:00
parent 06b722160c
commit 6cf7a91147
10 changed files with 437 additions and 16 deletions
+5
View File
@@ -52,3 +52,8 @@ aa507dc as predecessor. The existing automatic controller then replans queued
r41; no manual Docker action, image pull, failed-run replay or new application
commit is required. A successful canonical application receipt remains required
before the multisite migration and public Mission Core publication.
Post-promotion: 4dce749 was installed and verified. At 06:41:31 UTC the scoped
lookup reported parentCount 0, nodeCount 5, all rejected on layers. The label
fix therefore did not resolve the missing matching base. The next bounded
policy is [registered exact-base acquisition](R41_NODE_BASE_ACQUISITION.md).
@@ -0,0 +1,86 @@
# CMS r41: exact registered Node base acquisition
Installed runner `4dce7493d61efe67b49337fa7eab3fc441988b22b625181f1547fa72d6fce75b`
was verified by the operator. Its status at 2026-11-05 06:41:31 UTC was
`cms-base-missing`, parentCount 0, nodeCount 5, rejected.layers 5. All five local
Node references failed the filesystem-prefix check, before label comparison.
r41 is still staged, with matching SHA and no applied/failed record or backup.
The Compose-label defect was real but did not by itself resolve NAS base lookup.
The original runtime reconstruction proved Node 24.18.0 and Yarn 1.22.22.
Neither the preserved env-file nor Compose overrides those variables. The
official public `node:24.18.0-alpine` metadata for linux/amd64 was retrieved and
verified locally. The mutable tag was used for discovery only; the policy pins:
- Manifest: `sha256:4ba75f835bb8802193e4c114572113d4b26f95f6f094f4b5229d2a77773e0afc`.
- OCI config: `sha256:91d56b2d4e1cf23103d90b0b024c1f489c288f9c3aba1042dd7279503b367de6`.
- Four filesystem layers; compressed size 57633665 bytes; created 2026-06-24.
Exact public bytes are committed as node24-base-manifest.json and
node24-base-config.json and embedded as data in the reviewed root runner. They
contain no application/private data or executable artifact hook. Hash checks
bind the manifest to the config and its immutable image identity.
This is an additive, source-registered base-acquisition policy within
dc-cms-release. Application manifests cannot select images, platforms, network
policy, commands or roots. Read-only preflight first tries the existing cache.
If none match, it checks the registered public metadata against the accepted
CMS image: complete strict RootFS prefix, platform, Node 24, exact inherited Env
and configuration, and the already-defined Compose label additions. A matching
version alone never suffices. The official image has WorkingDir `/`; the
predicate now admits that default root as well as empty/default values, before
the fixed Dockerfile sets `/app`. Only known absent-vs-empty OCI User/Variant
defaults are projected when comparing public metadata with Docker 24's API;
runtime fingerprints and full post-build comparison are not normalized.
Preflight performs no pull or registry request. On an exact match its proof
names registeredBase=node24-alpine-amd64-v1 and the fixed digest/config pair.
Canonical apply re-proves the full record against the accepted image. Only an
exact missing-image error for that reference permits:
`docker pull --platform linux/amd64 docker.io/library/node@sha256:4ba75f835bb8802193e4c114572113d4b26f95f6f094f4b5229d2a77773e0afc`
An already cached registered image needs no network. Pull is bounded to 300s;
permission, daemon, registry or timeout failures never select another image.
After acquisition the actual RepoDigest, pinned image identity, full layers and
inherited config are checked again before build. Classic Docker image identity
is the registered OCI config digest; containerd image stores use the registered
manifest digest. Both must still have the exact pinned repository digest and
filesystem/config proof. No arbitrary identity is admitted.
The existing clean temporary Dockerfile uses that proved local ID with
DOCKER_BUILDKIT=0 and --pull=false. The source Dockerfile is unchanged. Full
post-build configuration and runtime acceptance remain exact. Compose itself
still uses --no-build --pull never --no-deps and selects only cms-app. Source,
sites/projects, authentication, other services, databases, mounts, ports and
secrets retain the same checks and rollback. A downloaded immutable base may
remain in Docker cache after rollback; it is never pruned or used as authority
to bypass application acceptance. No old application image/layers are reused
as a build base.
When registered metadata fails, public status gives only a fixed rejection
category and the first four accepted layer digests, alongside candidate counts.
It never exports Env values, label values, file contents or arbitrary stderr.
This supports an exact follow-up if the NAS base differs from this public
candidate. NAS matching remains unproven until its own preflight succeeds.
Validation: 104 CMS tests, 95 Device Core tests, Python 3.8 AST and diff checks.
Focused tests cover no pull in preflight, source-byte integrity, exact proof,
wrong source/reference/config/layers/repository, cached/missing image behavior,
both store identities, missing-image aliases, timeouts and redacted diagnostics.
Existing canonical failed-build tests retain the automatic rollback path.
A real local integration builds original CMS source 4c6f133 with actual Compose
and this official base, removes only its newly acquired digest reference, then
invokes the actual resolver and builder on candidate source 4369f0a. Preflight
does not restore the image; apply acquires only the pinned digest. Candidate
build passes exact inherited configuration/Compose labels, unchanged source
Dockerfile, identical base layers, exported-layer exclusion of old/new private
project fixtures, adm-zip 0.6.1 and Node syntax checks. Local Docker Desktop uses
containerd identities; NAS classic-store identity is covered by focused tests.
Only isolated test tags and ephemeral network-disabled verification containers
are used. This test does not prove NAS layer equality or NAS registry access.
After root runner promotion the existing controller replans queued r41. No new
CMS artifact, bootstrap or failed-release replay is required. A canonical
application receipt is still required before migrating/publishing the two sites.
+5 -1
View File
@@ -70,4 +70,8 @@ no bootstrap or failed-release replay is needed.
The scoped runner was installed; its preflight reported no matching base.
The [Compose-label correction](R41_COMPOSE_LABELS.md) accounts for the three
labels added by Compose, reproduces them during build, and retains exact
post-build configuration comparison. Deployment is still pending its promotion.
post-build configuration comparison. That runner was installed; all five local
Node candidates still failed the filesystem-prefix check. The
[registered base-acquisition policy](R41_NODE_BASE_ACQUISITION.md) can restore
one pinned public Node base only after exact preflight ancestry/config proof.
Deployment is pending promotion of that policy and actual NAS acceptance.
+1
View File
@@ -8,6 +8,7 @@ END='# END GENERATED CMS DEPLOYMENT\n'
def section():
release=(ROOT/'release_runtime.py').read_text().replace('__CMS_BASELINE__',repr(json.loads((ROOT/'baseline.json').read_text()))).replace('__CMS_FOUNDATION__',repr(json.loads((ROOT/'foundation.json').read_text())))
release=release.replace('__CMS_NODE_BASE_CONFIG__',repr((ROOT/'node24-base-config.json').read_text())).replace('__CMS_NODE_BASE_MANIFEST__',repr((ROOT/'node24-base-manifest.json').read_text()))
ci=(ROOT/'ci_runtime.py').read_text().replace('__CMS_CI_HASHES__',repr(json.loads((ROOT/'ci-source-sha256.json').read_text())))
auto=(ROOT/'autodeploy_runtime.py').read_text()
library='def cms_autodeploy_library():\n'
File diff suppressed because one or more lines are too long
@@ -0,0 +1,41 @@
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:91d56b2d4e1cf23103d90b0b024c1f489c288f9c3aba1042dd7279503b367de6",
"size": 6522
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:55afa1ecc21d2bb5e5045f32dafee56272ffd89860bac26f6c32123439af26a4",
"size": 3846391
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:7e2a5e2761f53b694faaee16c5ad1e400cb41224f693337aac52e74bee3b2f65",
"size": 52524717
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:57eb903fc7a4b0006b1253f877823b15c51433ccd41a20392812682211c46a6c",
"size": 1262109
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:21af007bacf625b557dda6dbce062088808612be54a955980b3d8efb8ea7d082",
"size": 448
}
],
"annotations": {
"com.docker.official-images.bashbrew.arch": "amd64",
"org.opencontainers.image.base.digest": "sha256:79ff19e9084a00eece421b2523fb93e22d730e2c0e525905de047e848e56d95f",
"org.opencontainers.image.base.name": "alpine:3.24",
"org.opencontainers.image.created": "2026-06-24T18:11:03Z",
"org.opencontainers.image.revision": "303e6c3be0be8010403376712d3018fb99809f86",
"org.opencontainers.image.source": "https://github.com/nodejs/docker-node.git#303e6c3be0be8010403376712d3018fb99809f86:24/alpine3.24",
"org.opencontainers.image.url": "https://hub.docker.com/_/node",
"org.opencontainers.image.version": "24-alpine"
}
}
+94 -7
View File
@@ -5,6 +5,11 @@ CMS_RELEASE_SERVICES = ('cms-app',)
CMS_BASELINE = __CMS_BASELINE__
CMS_FOUNDATION = __CMS_FOUNDATION__
CMS_DEPENDENCY_FILES = ('package.json', 'package-lock.json')
CMS_NODE_BASE_MANIFEST = 'sha256:4ba75f835bb8802193e4c114572113d4b26f95f6f094f4b5229d2a77773e0afc'
CMS_NODE_BASE_CONFIG = 'sha256:91d56b2d4e1cf23103d90b0b024c1f489c288f9c3aba1042dd7279503b367de6'
CMS_NODE_BASE_REF = 'docker.io/library/node@'+CMS_NODE_BASE_MANIFEST
CMS_NODE_BASE_CONFIG_JSON = __CMS_NODE_BASE_CONFIG__
CMS_NODE_BASE_MANIFEST_JSON = __CMS_NODE_BASE_MANIFEST__
def cms_release_path(rel, *, directory=False):
@@ -183,18 +188,26 @@ CMS_BUILD_BASE_ERROR_CODES = frozenset((
'cms-base-parent-invalid','cms-base-parent-cycle','cms-base-parent-depth',
'cms-base-parent-layers','cms-base-parent-platform','cms-base-inventory-format',
'cms-base-inventory-limit','cms-base-missing','cms-base-ambiguous','cms-base-build-labels',
'cms-base-image-not-found','cms-base-registered-mismatch','cms-base-registered-proof',
'cms-base-registered-image','cms-base-fetch-failed','cms-base-fetch-timeout',
))
CMS_BASE_REJECTION_CODES = frozenset(('layers','platform','base-shape','inherited-config','labels','environment','node-version'))
def cms_base_public_diagnostic(value):
# Public counts only, never arbitrary keys/values from image inspection.
if not isinstance(value,dict) or set(value)!={'parentCount','nodeCount','rejected'}:return None
if not isinstance(value,dict) or set(value) not in ({'parentCount','nodeCount','rejected'},{'parentCount','nodeCount','rejected','registeredRejection','acceptedPrefix'}):return None
if any(type(value[k]) is not int or not 0<=value[k]<=384 for k in ('parentCount','nodeCount')):return None
rejected=value['rejected']
if not isinstance(rejected,dict) or not set(rejected)<=CMS_BASE_REJECTION_CODES:return None
if any(type(v) is not int or not 0<=v<=384 for v in rejected.values()):return None
return {'parentCount':value['parentCount'],'nodeCount':value['nodeCount'],'rejected':dict(rejected)}
result={'parentCount':value['parentCount'],'nodeCount':value['nodeCount'],'rejected':dict(rejected)}
if 'registeredRejection' in value:
prefix=value['acceptedPrefix']
if (not isinstance(value['registeredRejection'],str) or value['registeredRejection'] not in CMS_BASE_REJECTION_CODES or not isinstance(prefix,list) or len(prefix)>4
or any(not isinstance(v,str) or not re.fullmatch('sha256:[a-f0-9]{64}',v) for v in prefix)):return None
result.update(registeredRejection=value['registeredRejection'],acceptedPrefix=list(prefix))
return result
class CmsBuildBaseError(DeployError):
@@ -212,7 +225,15 @@ def cms_base_docker_json(args, *, lines=False):
proc=subprocess.run([str(DOCKER),*args],capture_output=True,text=True,check=True,timeout=30)
except subprocess.TimeoutExpired:
raise CmsBuildBaseError('cms-base-docker-timeout') from None
except subprocess.CalledProcessError:
except subprocess.CalledProcessError as error:
missing_names=([args[2]] if len(args)==3 else [])
if len(args)==3 and args[2]==CMS_NODE_BASE_REF:
missing_names += [prefix+'@'+CMS_NODE_BASE_MANIFEST for prefix in ('node','library/node')]
if (len(args)==3 and args[:2]==['image','inspect']
and (re.fullmatch('sha256:[a-f0-9]{64}',args[2]) or args[2]==CMS_NODE_BASE_REF)
and error.returncode==1 and (error.stdout or '').strip()=='[]'
and (error.stderr or '').strip() in [prefix+name for prefix in ('Error response from daemon: No such image: ','Error: No such image: ') for name in missing_names]):
raise CmsBuildBaseError('cms-base-image-not-found') from None
raise CmsBuildBaseError('cms-base-docker-failed') from None
except (OSError,UnicodeError):
raise CmsBuildBaseError('cms-base-docker-unavailable') from None
@@ -276,7 +297,7 @@ def cms_node_base_rejection(image, accepted):
return 'platform'
config=image.get('Config') or {};old=accepted.get('Config') or {}
if (image.get('Os')!='linux' or config.get('Cmd')!=['node']
or config.get('WorkingDir') not in ('',None)
or config.get('WorkingDir') not in ('',None,'/')
or config.get('OnBuild') not in (None,[]) or config.get('Volumes') not in (None,{})
or config.get('ExposedPorts') not in (None,{})):
return 'base-shape'
@@ -296,6 +317,61 @@ def cms_node_base_matches(image, accepted):
return cms_node_base_rejection(image,accepted) is None
def cms_registered_node_image(accepted):
# Source-registered public OCI bytes, never supplied by an app artifact.
if ('sha256:'+hashlib.sha256(CMS_NODE_BASE_CONFIG_JSON.encode()).hexdigest()!=CMS_NODE_BASE_CONFIG
or 'sha256:'+hashlib.sha256(CMS_NODE_BASE_MANIFEST_JSON.encode()).hexdigest()!=CMS_NODE_BASE_MANIFEST):
raise CmsBuildBaseError('cms-base-registered-proof')
manifest=json.loads(CMS_NODE_BASE_MANIFEST_JSON);config=json.loads(CMS_NODE_BASE_CONFIG_JSON)
if (manifest['config']['digest']!=CMS_NODE_BASE_CONFIG or config['os']!='linux' or config['architecture']!='amd64'
or len(config['rootfs']['diff_ids'])!=4 or len(manifest['layers'])!=4):
raise CmsBuildBaseError('cms-base-registered-proof')
image={'Id':CMS_NODE_BASE_CONFIG,'Os':'linux','Architecture':'amd64',
'Config':config['config'],'RootFS':{'Type':'layers','Layers':config['rootfs']['diff_ids']}}
# Docker 24 serializes the default User/Variant as empty strings; newer
# image APIs omit them. Project only these known OCI defaults for comparison.
old=accepted.get('Config') or {}
if 'User' not in image['Config'] and old.get('User')=='':image['Config']['User']=''
if accepted.get('Variant')=='':image['Variant']=''
return image
def cms_registered_node_proof(accepted):
image=cms_registered_node_image(accepted)
return {'registeredBase':'node24-alpine-amd64-v1','registryReference':CMS_NODE_BASE_REF,
'configDigest':CMS_NODE_BASE_CONFIG,'acceptedImageId':accepted['Id'],
'layersSha256':cms_audit_digest(image['RootFS']['Layers'])}
def cms_materialize_registered_node(proof, accepted):
# The read-only preflight has already proved this exact source base. Reprove
# before the sole allowed pull, then verify actual local bytes before build.
if proof!=cms_registered_node_proof(accepted) or not cms_node_base_matches(cms_registered_node_image(accepted),accepted):
raise CmsBuildBaseError('cms-base-registered-proof')
try:rows=cms_base_docker_json(['image','inspect',CMS_NODE_BASE_REF])
except CmsBuildBaseError as error:
if error.code!='cms-base-image-not-found':raise
print('cms_build_base_acquire=registered-digest;reference='+CMS_NODE_BASE_REF+';platform=linux/amd64')
try:
subprocess.run([str(DOCKER),'pull','--platform','linux/amd64',CMS_NODE_BASE_REF],
capture_output=True,text=True,check=True,timeout=300)
except subprocess.TimeoutExpired:raise CmsBuildBaseError('cms-base-fetch-timeout') from None
except (subprocess.CalledProcessError,OSError):raise CmsBuildBaseError('cms-base-fetch-failed') from None
rows=cms_base_docker_json(['image','inspect',CMS_NODE_BASE_REF])
if not isinstance(rows,list) or len(rows)!=1 or not isinstance(rows[0],dict):
raise CmsBuildBaseError('cms-base-registered-image')
image=rows[0]
# Classic Docker uses the OCI config ID, containerd stores the manifest ID.
# Both identities are pinned to the exact registered manifest/config pair.
aliases={prefix+'@'+CMS_NODE_BASE_MANIFEST for prefix in ('node','library/node','docker.io/library/node')}
if (image.get('Id') not in (CMS_NODE_BASE_CONFIG,CMS_NODE_BASE_MANIFEST)
or not aliases.intersection(image.get('RepoDigests') or [])
or (image.get('RootFS') or {}).get('Layers')!=cms_registered_node_image(accepted)['RootFS']['Layers']
or not cms_node_base_matches(image,accepted)):
raise CmsBuildBaseError('cms-base-registered-image')
return image
def cms_resolve_build_base(runtime):
accepted=cms_inspect_image(runtime['imageId'])
diagnostic={'parentCount':0,'nodeCount':0,'rejected':{}}
@@ -343,7 +419,14 @@ def cms_resolve_build_base(runtime):
for identity in sorted(set(rows)):
image=cms_inspect_image(identity)
if matches(image,'nodeCount'):found.append(image)
if not found:raise CmsBuildBaseError('cms-base-missing',diagnostic)
if not found:
registered=cms_registered_node_image(accepted)
reason=cms_node_base_rejection(registered,accepted)
if reason is not None:
diagnostic.update(registeredRejection=reason,acceptedPrefix=((accepted.get('RootFS') or {}).get('Layers') or [])[:4])
raise CmsBuildBaseError('cms-base-registered-mismatch',diagnostic)
print('cms_build_base=registered-node24-base-v1;reference='+CMS_NODE_BASE_REF+';acquire=apply-only')
return cms_registered_node_proof(accepted)
if len(found)!=1:raise CmsBuildBaseError('cms-base-ambiguous',diagnostic)
base=found[0];method='node-cache'
proof={'imageId':base['Id'],'acceptedImageId':accepted['Id'],
@@ -374,10 +457,14 @@ def build_cms_release(before):
proof=before['buildBase']
if proof.get('acceptedImageId')!=before['runtime']['imageId']:
die('CMS build base predecessor changed')
base=cms_inspect_image(proof['imageId']);accepted=cms_inspect_image(proof['acceptedImageId'])
registered=proof.get('registeredBase') is not None
if registered:
accepted=cms_inspect_image(proof['acceptedImageId']);base=cms_materialize_registered_node(proof,accepted)
else:
base=cms_inspect_image(proof['imageId']);accepted=cms_inspect_image(proof['acceptedImageId'])
if (not cms_node_base_matches(base,accepted)
or cms_audit_digest(base['RootFS']['Layers'])!=proof['layersSha256']
or cms_audit_digest(base['Config'])!=proof['configSha256']):
or (not registered and cms_audit_digest(base['Config'])!=proof['configSha256'])):
die('CMS build base differs from its preflight proof')
dockerfile=(CMS_ROOT/'Dockerfile').read_bytes()
if hashlib.sha256(dockerfile).hexdigest()!=CMS_FOUNDATION['Dockerfile'] or not dockerfile.startswith(b'FROM node:24-alpine\n'):
+109
View File
@@ -0,0 +1,109 @@
import copy
from contextlib import redirect_stdout
import io
import unittest
from unittest.mock import patch
from test_runner import r
from test_build_base import compose_labels
def registered_images():
base=r.cms_registered_node_image({'Config':{'User':''}})
base['RepoDigests']=['node@'+r.CMS_NODE_BASE_MANIFEST]
accepted=copy.deepcopy(base);accepted['Id']='sha256:'+'b'*64
accepted['RootFS']['Layers'].append('sha256:'+'e'*64)
accepted['Config'].update(Cmd=['npm','run','admin'],WorkingDir='/app',ExposedPorts={'8090/tcp':{}},Labels=compose_labels())
accepted['Config']['Env']+=['HOST=0.0.0.0','PORT=8090']
return base,accepted
class CmsBaseAcquisitionTests(unittest.TestCase):
def test_registered_public_bytes_and_docker24_default_projection(self):
base,accepted=registered_images()
self.assertEqual(base['Config']['WorkingDir'],'/')
self.assertEqual(base['Config']['User'],'')
self.assertTrue(r.cms_node_base_matches(base,accepted))
newer=copy.deepcopy(accepted);newer['Config'].pop('User')
self.assertNotIn('User',r.cms_registered_node_image(newer)['Config'])
self.assertTrue(r.cms_node_base_matches(r.cms_registered_node_image(newer),newer))
with patch.object(r,'CMS_NODE_BASE_CONFIG_JSON',r.CMS_NODE_BASE_CONFIG_JSON+' '):
with self.assertRaisesRegex(r.CmsBuildBaseError,'registered-proof'):r.cms_registered_node_image(accepted)
def test_preflight_proves_registered_base_without_pull_or_image_mutation(self):
base,accepted=registered_images()
with patch.object(r,'cms_inspect_image',return_value=accepted),patch.object(r,'cms_base_docker_json',return_value=[]),patch.object(r.subprocess,'run') as run,redirect_stdout(io.StringIO()):
proof=r.cms_resolve_build_base({'imageId':accepted['Id']})
self.assertEqual(proof,r.cms_registered_node_proof(accepted));run.assert_not_called()
self.assertEqual(proof['registryReference'],r.CMS_NODE_BASE_REF)
def test_registered_mismatch_reports_only_fixed_reason_and_base_layer_prefix(self):
for field in ('layers','environment'):
base,accepted=registered_images()
if field=='layers':accepted['RootFS']['Layers'][0]='sha256:'+'f'*64
else:accepted['Config']['Env'].append('SECRET=private-fixture')
with patch.object(r,'cms_inspect_image',return_value=accepted),patch.object(r,'cms_base_docker_json',return_value=[]),patch.object(r.subprocess,'run') as run:
with self.assertRaises(r.CmsBuildBaseError) as error:r.cms_resolve_build_base({'imageId':accepted['Id']})
run.assert_not_called();status=r.cms_autodeploy_error_status(error.exception,())
self.assertEqual(status['reason'],'cms-base-registered-mismatch')
self.assertEqual(status['baseLookup']['registeredRejection'],field)
self.assertNotIn('private-fixture',str(status));self.assertNotIn('SECRET',str(status))
def test_only_exact_missing_image_response_can_trigger_acquisition(self):
args=['image','inspect',r.CMS_NODE_BASE_REF]
for stderr,expected in [('Error response from daemon: No such image: '+r.CMS_NODE_BASE_REF,'cms-base-image-not-found'),
('Error: No such image: '+r.CMS_NODE_BASE_REF,'cms-base-image-not-found'),
('Error response from daemon: No such image: node@'+r.CMS_NODE_BASE_MANIFEST,'cms-base-image-not-found'),
('permission denied private-fixture','cms-base-docker-failed')]:
error=r.subprocess.CalledProcessError(1,['docker'],output='[]\n',stderr=stderr)
with patch.object(r.subprocess,'run',side_effect=error):
with self.assertRaisesRegex(r.CmsBuildBaseError,expected):r.cms_base_docker_json(args)
def test_cached_registered_image_uses_no_network_for_both_image_store_identities(self):
for identity in (r.CMS_NODE_BASE_CONFIG,r.CMS_NODE_BASE_MANIFEST):
base,accepted=registered_images();base['Id']=identity
with patch.object(r,'cms_base_docker_json',return_value=[base]),patch.object(r.subprocess,'run') as run:
self.assertEqual(r.cms_materialize_registered_node(r.cms_registered_node_proof(accepted),accepted),base)
run.assert_not_called()
def test_missing_registered_base_pulls_only_fixed_digest_then_reproves_local_image(self):
base,accepted=registered_images()
with patch.object(r,'cms_base_docker_json',side_effect=[r.CmsBuildBaseError('cms-base-image-not-found'),[base]]) as inspect,patch.object(r.subprocess,'run') as run,redirect_stdout(io.StringIO()):
self.assertEqual(r.cms_materialize_registered_node(r.cms_registered_node_proof(accepted),accepted),base)
self.assertEqual(inspect.call_count,2)
run.assert_called_once_with([str(r.DOCKER),'pull','--platform','linux/amd64',r.CMS_NODE_BASE_REF],capture_output=True,text=True,check=True,timeout=300)
def test_forged_proof_or_changed_accepted_base_stops_before_docker(self):
base,accepted=registered_images();proof=r.cms_registered_node_proof(accepted)
for key in proof:
with patch.object(r,'cms_base_docker_json') as inspect,patch.object(r.subprocess,'run') as run:
with self.assertRaisesRegex(r.CmsBuildBaseError,'registered-proof'):r.cms_materialize_registered_node({**proof,key:'private-fixture'},accepted)
inspect.assert_not_called();run.assert_not_called()
accepted['RootFS']['Layers'][0]='sha256:'+'0'*64
with patch.object(r,'cms_base_docker_json') as inspect:
with self.assertRaisesRegex(r.CmsBuildBaseError,'registered-proof'):r.cms_materialize_registered_node(proof,accepted)
inspect.assert_not_called()
def test_local_image_identity_layers_environment_and_repository_are_not_substitutable(self):
for field in ('Id','RepoDigests','Layers','Env'):
base,accepted=registered_images();proof=r.cms_registered_node_proof(accepted)
if field=='Id':base['Id']='sha256:'+'f'*64
elif field=='RepoDigests':base['RepoDigests']=['other@'+r.CMS_NODE_BASE_MANIFEST]
elif field=='Layers':base['RootFS']['Layers'][0]='sha256:'+'f'*64
else:base['Config']['Env'].append('SECRET=private-fixture')
with patch.object(r,'cms_base_docker_json',return_value=[base]),patch.object(r.subprocess,'run') as run:
with self.assertRaisesRegex(r.CmsBuildBaseError,'registered-image'):r.cms_materialize_registered_node(proof,accepted)
run.assert_not_called()
def test_unavailable_docker_and_registry_errors_never_choose_another_base(self):
base,accepted=registered_images();proof=r.cms_registered_node_proof(accepted)
with patch.object(r,'cms_base_docker_json',side_effect=r.CmsBuildBaseError('cms-base-docker-failed')),patch.object(r.subprocess,'run') as run:
with self.assertRaisesRegex(r.CmsBuildBaseError,'docker-failed'):r.cms_materialize_registered_node(proof,accepted)
run.assert_not_called()
for error,code in [(r.subprocess.TimeoutExpired(['private-fixture'],300),'fetch-timeout'),
(r.subprocess.CalledProcessError(1,['private-fixture'],stderr='private-fixture'),'fetch-failed')]:
with patch.object(r,'cms_base_docker_json',side_effect=r.CmsBuildBaseError('cms-base-image-not-found')),patch.object(r.subprocess,'run',side_effect=error),redirect_stdout(io.StringIO()):
with self.assertRaisesRegex(r.CmsBuildBaseError,code) as caught:r.cms_materialize_registered_node(proof,accepted)
self.assertNotIn('private-fixture',str(caught.exception))
if __name__=='__main__':unittest.main()
+1 -1
View File
@@ -168,7 +168,7 @@ class CmsBuildBaseTests(unittest.TestCase):
with patch.object(r,'cms_inspect_image',side_effect=inventory.__getitem__),patch.object(r,'cms_base_docker_json',return_value=[base['Id']]):
with self.assertRaises(r.CmsBuildBaseError) as error:r.cms_resolve_build_base({'imageId':old['Id']})
status=r.cms_autodeploy_error_status(error.exception,())
self.assertEqual(status['baseLookup'],{'parentCount':0,'nodeCount':1,'rejected':{'labels':1}})
self.assertEqual(status['baseLookup'],{'parentCount':0,'nodeCount':1,'rejected':{'labels':1},'registeredRejection':'layers','acceptedPrefix':old['RootFS']['Layers']})
self.assertNotIn('private-fixture',json.dumps(status));self.assertNotIn('never-export',json.dumps(status))
for value in [None,{}, {'parentCount':0,'nodeCount':1,'rejected':{'private-fixture':1}},
{'parentCount':0,'nodeCount':1,'rejected':{'labels':'private-fixture'}},
File diff suppressed because one or more lines are too long