fix(ci): route production code-only release through safe locked deployment without migrations
Deploy Canina / deploy (push) Failing after 10s

This commit is contained in:
Canina Automation committed 2026-10-26 20:17:27 +00:00
1 parent 9ae839138c
commit 53fccc2d3c
5 files changed
+355 -198

No files matched your search

+23 -15
View File
@@ -31,27 +31,34 @@ def labels(values):
return {key: value for key, value in values.items() if key.startswith('traefik.')}
def verify(base, planned, live, nginx, live_nginx):
def verify(base, planned, live, nginx, live_nginx, environment="stage"):
if environment not in ("stage", "prod"):
raise ValueError("unsupported environment")
backend, frontend = "backend_" + environment, "frontend_" + environment
"""Return property/key mismatches, never configuration values."""
errors = []
# Validate resolved Compose environment, not env_file input: environment
# entries can override a provisioned secret. Match provisioner's format.
secrets = [planned['services'][name]['environment'].get('REVALIDATION_SECRET')
for name in ('backend_stage', 'frontend_stage')]
for name, secret in zip(('backend_stage', 'frontend_stage'), secrets):
for name in (backend, frontend)]
for name, secret in zip((backend, frontend), secrets):
if not isinstance(secret, str) or not re.fullmatch(r'[A-Za-z0-9_+/=-]{32,256}', secret):
errors.append(name + '.environment.REVALIDATION_SECRET')
if secrets[0] != secrets[1]:
errors.extend(name + '.environment.REVALIDATION_SECRET'
for name in ('backend_stage', 'frontend_stage'))
for name in (backend, frontend))
# Intentional rotation is permitted: do not compare these values to live.
allowed = {'REVALIDATION_SECRET', 'FRONTEND_INTERNAL_URL', 'INTERNAL_API_URL'}
if environment == 'prod':
allowed.add('NEXT_PUBLIC_SITE_URL')
if planned['services'][frontend]['environment'].get('NEXT_PUBLIC_SITE_URL') != 'https://canina.ir':
errors.append(frontend + '.environment.NEXT_PUBLIC_SITE_URL')
defaults = {'PATH', 'NODE_VERSION', 'YARN_VERSION', 'PRISMA_HIDE_UPDATE_MESSAGE'}
for name in ('backend_stage', 'frontend_stage'):
for name in (backend, frontend):
required_args = {'NPM_REGISTRY': 'https://registry.parsaaghayi.ir/repository/npm/'}
if name == 'frontend_stage':
required_args.update(NEXT_PUBLIC_API_URL='https://stageapi.canina.ir/api',
VITE_API_URL='https://stageapi.canina.ir')
if name == frontend:
api_origin = 'https://stageapi.canina.ir' if environment == 'stage' else 'https://api.canina.ir'
required_args.update(NEXT_PUBLIC_API_URL=api_origin + '/api', VITE_API_URL=api_origin)
args = planned['services'][name].get('build', {}).get('args', {})
for key, expected_value in required_args.items():
if args.get(key) != expected_value:
@@ -114,7 +121,7 @@ def verify(base, planned, live, nginx, live_nginx):
if key not in expected or key not in actual_labels or expected[key] != actual_labels[key]:
errors.append(name + '.labels.' + key)
if nginx != live_nginx:
errors.append('frontend_stage.nginx.bytes')
errors.append(frontend + '.nginx.bytes')
return sorted(set(errors))
@@ -125,6 +132,7 @@ def main(argv=None):
parser.add_argument('--project-directory', required=True)
parser.add_argument('--project-name', default='stage')
parser.add_argument('--nginx', required=True)
parser.add_argument('--environment', choices=('stage', 'prod'), default='stage')
options = parser.parse_args(argv)
# Subprocess diagnostics may contain interpolated credentials. Capture them
# and never include exceptions, argv, config, or values in diagnostics.
@@ -140,14 +148,14 @@ def main(argv=None):
for override in options.override:
planned_command.extend(['-f', override])
planned = json.loads(capture(planned_command + ['config', '--format', 'json']))
inspected = json.loads(capture(['docker', 'inspect', 'canino_backend_stage',
'canino_frontend_stage']))
backend, frontend = 'backend_' + options.environment, 'frontend_' + options.environment
inspected = json.loads(capture(['docker', 'inspect', 'canino_' + backend, 'canino_' + frontend]))
if not isinstance(inspected, list) or len(inspected) != 2:
raise ValueError()
live = dict(zip(('backend_stage', 'frontend_stage'), inspected))
live_nginx = capture(['docker', 'exec', 'canino_frontend_stage', 'cat',
live = dict(zip((backend, frontend), inspected))
live_nginx = capture(['docker', 'exec', 'canino_' + frontend, 'cat',
'/etc/nginx/conf.d/default.conf'])
errors = verify(base, planned, live, Path(options.nginx).read_bytes(), live_nginx)
errors = verify(base, planned, live, Path(options.nginx).read_bytes(), live_nginx, environment=options.environment)
except (OSError, subprocess.SubprocessError, ValueError, KeyError, TypeError, AttributeError):
print('authority.input unavailable or malformed', file=sys.stderr)
return 1
@@ -156,7 +164,7 @@ def main(argv=None):
print('authority mismatch: ' + re.sub(r'[^a-zA-Z0-9_.-]', '?', error), file=sys.stderr)
if errors:
return 1
print('Stage runtime authority verified')
print(options.environment + ' runtime authority verified')
return 0