ci: separate protected source integration from explicit production deployment
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 12m54s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 3s
CI / Deploy (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 12m54s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 3s
CI / Deploy (pull_request) Skipped
This commit is contained in:
1 parent
44774883a0
commit
4e7440f25e
4 files changed
+271
-3
No files matched your search
@@ -11,6 +11,12 @@ on:
|
|||||||
options: [story, feature]
|
options: [story, feature]
|
||||||
default: story
|
default: story
|
||||||
required: true
|
required: true
|
||||||
|
deploy_target:
|
||||||
|
description: Deployment target for this run
|
||||||
|
type: choice
|
||||||
|
options: [none, production]
|
||||||
|
default: none
|
||||||
|
required: true
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -499,7 +505,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
- required-checks
|
- required-checks
|
||||||
if: ${{ gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' }}
|
if: ${{ gitea.event_name == 'workflow_dispatch' && gitea.ref == 'refs/heads/main' && inputs.validation_level == 'feature' && inputs.deploy_target == 'production' }}
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.itexp.me
|
REGISTRY: git.itexp.me
|
||||||
IMAGE_TAG: ${{ gitea.sha }}
|
IMAGE_TAG: ${{ gitea.sha }}
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ feature jobs должны быть `skipped` для story и `success` для fe
|
|||||||
У Crank и FreeHub полный Rust clippy/workspace test и тяжёлые feature/security
|
У Crank и FreeHub полный Rust clippy/workspace test и тяжёлые feature/security
|
||||||
проверки выполняются только на feature. UI build и быстрые UI unit tests остаются
|
проверки выполняются только на feature. UI build и быстрые UI unit tests остаются
|
||||||
на story, Playwright E2E — на feature. Crank image build/scan/compose smoke — на
|
на story, Playwright E2E — на feature. Crank image build/scan/compose smoke — на
|
||||||
feature; фактический Deploy остаётся отдельным push-main job со своими build,
|
feature; фактический Deploy запускается только явным workflow_dispatch на main
|
||||||
scan, health и требованием успешного SHA. Тег релиза по умолчанию запускает story
|
с validation_level=feature и deploy_target=production после успешных feature gates.
|
||||||
|
Обычный merge/push не выкатывает production. Порядок: delivery-and-deploy.md. Тег релиза по умолчанию запускает story
|
||||||
ATDD, сборку бинарных/UI артефактов, security audit и image scan. Полный release
|
ATDD, сборку бинарных/UI артефактов, security audit и image scan. Полный release
|
||||||
clippy/workspace/E2E доступен через ручной dispatch с `validation_level: feature`;
|
clippy/workspace/E2E доступен через ручной dispatch с `validation_level: feature`;
|
||||||
отчёт evidence прикладывается только если такой E2E был выполнен. FreeHub
|
отчёт evidence прикладывается только если такой E2E был выполнен. FreeHub
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# Delivery и production deploy
|
||||||
|
|
||||||
|
## Разделение merge и выкатки
|
||||||
|
|
||||||
|
Push в `main` запускает только source CI: story-проверки, UI build и
|
||||||
|
`Required Checks`. Он не запускает production deploy и не загружает секреты
|
||||||
|
OpenBao. PR, метка `feature-ready`, story dispatch и dispatch без явно выбранного
|
||||||
|
production также не выкатывают production.
|
||||||
|
|
||||||
|
Production deploy выполняет только job `Deploy` workflow `CI` и только при
|
||||||
|
одновременном выполнении условий:
|
||||||
|
|
||||||
|
- событие `workflow_dispatch`;
|
||||||
|
- ref `refs/heads/main`;
|
||||||
|
- `validation_level: feature`;
|
||||||
|
- `deploy_target: production`;
|
||||||
|
- успешный `Required Checks`, включая feature jobs `Rust Feature Validation`,
|
||||||
|
`Frontend E2E` и `Community Image Smoke`.
|
||||||
|
|
||||||
|
Любая другая комбинация оставляет deploy пропущенным, поэтому принятый merge в
|
||||||
|
`main` больше не блокируется ожиданием production-выкатки.
|
||||||
|
|
||||||
|
## Ручной запуск
|
||||||
|
|
||||||
|
В Gitea UI: `Actions` -> workflow `CI` -> `Run workflow`.
|
||||||
|
|
||||||
|
Указать точные входные значения:
|
||||||
|
|
||||||
|
| Input | Значение | Обязателен |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Branch / ref | `main` | да |
|
||||||
|
| `validation_level` | `feature` | да |
|
||||||
|
| `deploy_target` | `production` | да |
|
||||||
|
|
||||||
|
`validation_level: story`, `deploy_target: none` или отсутствие `deploy_target`
|
||||||
|
дают только source CI либо feature-проверки без deploy. Нельзя запускать
|
||||||
|
production deploy из PR, с другой ветки или через push в `main`.
|
||||||
|
|
||||||
|
## Approval и runbook
|
||||||
|
|
||||||
|
Сам по себе ручной dispatch не является автоматическим разрешением на
|
||||||
|
production. Перед запуском release owner или DevOps явно подтверждает:
|
||||||
|
|
||||||
|
1. SHA совпадает с принятым и проверенным коммитом в `main`.
|
||||||
|
2. `Required Checks` для этого SHA успешны, включая feature jobs.
|
||||||
|
3. Пройдены [production checklist](../production-checklist.md) и актуальный
|
||||||
|
[deploy and staging smoke](../deploy-and-staging-smoke.md); известен порядок
|
||||||
|
rollback и проверено наличие backup.
|
||||||
|
4. Нет незапланированных изменений секретов, миграций или инфраструктуры.
|
||||||
|
|
||||||
|
После deploy проверить health endpoints и authenticated product smoke, затем
|
||||||
|
зафиксировать результат в staging/production regression notes. Секреты OpenBao
|
||||||
|
загружаются только внутри уже разрешённого job `Deploy`; не выводить их в логи и
|
||||||
|
не передавать в PR или dispatch story.
|
||||||
|
|
||||||
|
## Ограничения
|
||||||
|
|
||||||
|
Workflow `Community Release` для тегов остаётся отдельным процессом публикации
|
||||||
|
release-образов и не является заменой этому ручному production deploy. Изменение
|
||||||
|
`ci.yml` не даёт постоянного разрешения на выкатку и не меняет приложение.
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
WORKFLOW = ROOT / ".gitea" / "workflows" / "ci.yml"
|
||||||
|
|
||||||
|
|
||||||
|
def workflow_text() -> str:
|
||||||
|
return WORKFLOW.read_text(encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def job_block(name: str) -> str:
|
||||||
|
lines = workflow_text().splitlines()
|
||||||
|
start = None
|
||||||
|
for index, line in enumerate(lines):
|
||||||
|
if line == f" {name}:":
|
||||||
|
start = index
|
||||||
|
break
|
||||||
|
if start is None:
|
||||||
|
raise AssertionError(f"job {name!r} not found")
|
||||||
|
end = len(lines)
|
||||||
|
for index in range(start + 1, len(lines)):
|
||||||
|
if re.match(r"^ [A-Za-z0-9_-]+:\s*$", lines[index]):
|
||||||
|
end = index
|
||||||
|
break
|
||||||
|
return "\n".join(lines[start:end])
|
||||||
|
|
||||||
|
|
||||||
|
def deploy_guard() -> str:
|
||||||
|
match = re.search(r"(?m)^ if:\s*(.+)$", job_block("deploy"))
|
||||||
|
if match is None:
|
||||||
|
raise AssertionError("deploy job has no guard")
|
||||||
|
return match.group(1).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def guard_conditions() -> dict[str, str]:
|
||||||
|
expression = deploy_guard()
|
||||||
|
if expression.startswith("${{") and expression.endswith("}}"):
|
||||||
|
expression = expression[3:-2].strip()
|
||||||
|
conditions: dict[str, str] = {}
|
||||||
|
for part in expression.split("&&"):
|
||||||
|
match = re.fullmatch(
|
||||||
|
r"([A-Za-z0-9_.]+)\s*==\s*['\"]([^'\"]+)['\"]", part.strip()
|
||||||
|
)
|
||||||
|
if match is None:
|
||||||
|
raise AssertionError(f"unsupported deploy guard condition: {part!r}")
|
||||||
|
conditions[match.group(1)] = match.group(2)
|
||||||
|
return conditions
|
||||||
|
|
||||||
|
|
||||||
|
def deploys(context: dict[str, str | None]) -> bool:
|
||||||
|
return all(
|
||||||
|
context.get(condition) == expected
|
||||||
|
for condition, expected in guard_conditions().items()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def dispatch_input(name: str) -> str:
|
||||||
|
match = re.search(
|
||||||
|
rf"(?m)^ {re.escape(name)}:\n((?: .*\n)+)", workflow_text()
|
||||||
|
)
|
||||||
|
if match is None:
|
||||||
|
raise AssertionError(f"workflow_dispatch input {name!r} not found")
|
||||||
|
return match.group(0)
|
||||||
|
|
||||||
|
|
||||||
|
class DeployPolicyTests(unittest.TestCase):
|
||||||
|
def test_guard_allows_only_manual_production_feature_on_main(self):
|
||||||
|
self.assertEqual(
|
||||||
|
guard_conditions(),
|
||||||
|
{
|
||||||
|
"gitea.event_name": "workflow_dispatch",
|
||||||
|
"gitea.ref": "refs/heads/main",
|
||||||
|
"inputs.validation_level": "feature",
|
||||||
|
"inputs.deploy_target": "production",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_manual_production_feature_on_main_deploys(self):
|
||||||
|
self.assertTrue(
|
||||||
|
deploys(
|
||||||
|
{
|
||||||
|
"gitea.event_name": "workflow_dispatch",
|
||||||
|
"gitea.ref": "refs/heads/main",
|
||||||
|
"inputs.validation_level": "feature",
|
||||||
|
"inputs.deploy_target": "production",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_push_to_main_does_not_deploy(self):
|
||||||
|
self.assertFalse(
|
||||||
|
deploys(
|
||||||
|
{
|
||||||
|
"gitea.event_name": "push",
|
||||||
|
"gitea.ref": "refs/heads/main",
|
||||||
|
"inputs.validation_level": "feature",
|
||||||
|
"inputs.deploy_target": "production",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_pull_request_with_feature_label_does_not_deploy(self):
|
||||||
|
self.assertFalse(
|
||||||
|
deploys(
|
||||||
|
{
|
||||||
|
"gitea.event_name": "pull_request",
|
||||||
|
"gitea.ref": "refs/pull/42/head",
|
||||||
|
"inputs.validation_level": "feature",
|
||||||
|
"inputs.deploy_target": "production",
|
||||||
|
"gitea.event.pull_request.labels.*.name": "feature-ready",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_missing_or_none_deploy_target_does_not_deploy(self):
|
||||||
|
base = {
|
||||||
|
"gitea.event_name": "workflow_dispatch",
|
||||||
|
"gitea.ref": "refs/heads/main",
|
||||||
|
"inputs.validation_level": "feature",
|
||||||
|
}
|
||||||
|
self.assertFalse(deploys(base))
|
||||||
|
self.assertFalse(deploys({**base, "inputs.deploy_target": "none"}))
|
||||||
|
|
||||||
|
def test_story_dispatch_does_not_deploy(self):
|
||||||
|
self.assertFalse(
|
||||||
|
deploys(
|
||||||
|
{
|
||||||
|
"gitea.event_name": "workflow_dispatch",
|
||||||
|
"gitea.ref": "refs/heads/main",
|
||||||
|
"inputs.validation_level": "story",
|
||||||
|
"inputs.deploy_target": "production",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_dispatch_on_other_ref_does_not_deploy(self):
|
||||||
|
self.assertFalse(
|
||||||
|
deploys(
|
||||||
|
{
|
||||||
|
"gitea.event_name": "workflow_dispatch",
|
||||||
|
"gitea.ref": "refs/heads/release",
|
||||||
|
"inputs.validation_level": "feature",
|
||||||
|
"inputs.deploy_target": "production",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_deploy_target_is_explicit_choice_defaulting_to_none(self):
|
||||||
|
block = dispatch_input("deploy_target")
|
||||||
|
self.assertIn("type: choice", block)
|
||||||
|
self.assertIn("options: [none, production]", block)
|
||||||
|
self.assertIn("default: none", block)
|
||||||
|
self.assertIn("required: true", block)
|
||||||
|
|
||||||
|
def test_push_main_source_ci_stays_enabled(self):
|
||||||
|
self.assertRegex(
|
||||||
|
workflow_text(),
|
||||||
|
r"(?m)^ push:\n branches:\n - main$",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_deploy_requires_successful_required_checks(self):
|
||||||
|
deploy = job_block("deploy")
|
||||||
|
self.assertRegex(deploy, r"(?ms)^ needs:\n - required-checks$")
|
||||||
|
|
||||||
|
def test_required_checks_gate_feature_jobs(self):
|
||||||
|
block = job_block("required-checks")
|
||||||
|
for job in ("rust-feature", "frontend-e2e", "deployment"):
|
||||||
|
self.assertIn(f" - {job}", block)
|
||||||
|
for variable in ("RUST_FEATURE_RESULT", "E2E_RESULT", "IMAGE_RESULT"):
|
||||||
|
self.assertIn(variable, block)
|
||||||
|
|
||||||
|
def test_only_deploy_loads_production_secrets(self):
|
||||||
|
text = workflow_text()
|
||||||
|
self.assertEqual(text.count("scripts/load-openbao-env.sh"), 1)
|
||||||
|
self.assertIn("scripts/load-openbao-env.sh", job_block("deploy"))
|
||||||
|
self.assertNotIn("openbao", job_block("deployment").lower())
|
||||||
|
|
||||||
|
def test_deploy_keeps_build_scan_backup_health_and_smoke_steps(self):
|
||||||
|
deploy = job_block("deploy")
|
||||||
|
for step in (
|
||||||
|
"Load deployment secrets from OpenBao",
|
||||||
|
"Build and push images",
|
||||||
|
"Save deploy image scan evidence",
|
||||||
|
"Sync deployment files to server",
|
||||||
|
"Write environment file",
|
||||||
|
"Validate required environment variables",
|
||||||
|
"Deploy with Docker Compose",
|
||||||
|
"Verify health endpoints",
|
||||||
|
"Run authenticated product smoke",
|
||||||
|
):
|
||||||
|
self.assertIn(f"name: {step}", deploy)
|
||||||
|
self.assertIn("scripts/scan-images.sh", deploy)
|
||||||
|
self.assertIn("deploy-community.sh", deploy)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user