Deployment¶
The forge ships as a Docker Compose stack behind nginx, deployed by AWS
CodeDeploy off an AWS CodePipeline that triggers on a merge to the stage
integration branch.
Pipeline¶
| Field | Value |
|---|---|
| CodePipeline (stage) | cms-ai-forge-stg |
| Trigger | merge / push to the stage branch |
| Deploy | CodeDeploy → the cms-ai-forge-stg EC2 target (kind: docker) |
| Endpoint | http://cms-ai-forge-stg.skyneto.com |
| Health path | /api/status (DB + broker reachability, always 200) |
A per-task PR merges to stage, CI (.github/workflows/ci.yml, job name
tests -- required by the branch-protection ruleset, AISD-38 pattern) runs
ENVIRONMENT=test python -m pytest with no AWS/RabbitMQ/MySQL access, and on
merge the pipeline builds and deploys the stage instance.
Check the stage deploy from the workspace with the deploy registry rather than hand-hunting AWS resources:
hq/.venv/bin/python -m hq.deploy check cms-ai-forge --env stage
# or the slash command:
/check-deploy cms-ai-forge stage
A healthy result reads e.g. pipeline=ok endpoint=200 docker=ok:4, and the
endpoint check curls http://cms-ai-forge-stg.skyneto.com/api/status.
What runs on the instance¶
CodeDeploy syncs the repo to /srv/cms-ai-forge and the appspec.yml hooks
bring up the Compose stack (scripts/application_start):
| Service | Role |
|---|---|
forge-api |
FastAPI control plane (uvicorn). Its command bootstraps the schema (idempotent create_all() + ddl/*.sql) before serving |
forge-worker |
Celery workers -- one queue per entity type, advancing state-machine steps |
forge-beat |
Celery beat -- the bounded retry beat, plus the content_refresh schedule when enabled |
nginx |
Reverse proxy fronting forge-api (nginx.conf) |
After the stack is up, application_start runs an idempotent provider seed
(scripts/seed_providers.py) in a one-shot forge-api container so the
real-provider path has its providers / provider_accounts rows the moment
stubs are flipped off.
appspec hooks¶
| Hook | Script | Purpose |
|---|---|---|
ApplicationStop |
scripts/application_stop |
Tear the previous stack down |
AfterInstall |
scripts/after_install |
Prepare the new release on disk |
ApplicationStart |
scripts/application_start |
docker-compose up -d + idempotent provider seed |
ValidateService |
scripts/validate_service |
Post-deploy health gate |
Schema bootstrap¶
There is no migration tool. The forge-owned tables are declared on a single
SQLAlchemy Base and applied by datastore/schema.py:bootstrap(engine)
(Base.metadata.create_all() + an ordered run of datastore/ddl/*.sql). It is
idempotent and runs automatically at forge-api start; operators can also run
scripts/bootstrap_schema.py (--dry-run to preview, --yes required in prod).
The control-plane credential¶
Every control-plane route is gated by a bearer token (AISD-317) held in Secrets
Manager at /<env>/cms-ai-forge/control-plane (field api_key). The image ships
fs_config + boto3 and the instance role already grants Secrets Manager read, so
forge-api resolves the credential itself at boot -- there is nothing for a
deploy hook to do, which is deliberate: re-minting or re-fetching a shared
credential on every deploy is how one gets rotated by accident.
Creating it is a one-time operator act, from a host with Secrets Manager write:
# create-or-fetch; prints what it did, never the value
python scripts/seed_control_plane_secret.py --env stg
# also write it into an env file (bare flag = /srv/cms-ai-forge/.env)
python scripts/seed_control_plane_secret.py --env stg --env-file
# a host whose env file disagrees with Secrets Manager reports `drift` (exit 3)
# and writes nothing; resync that host's copy explicitly:
python scripts/seed_control_plane_secret.py --env stg --env-file --repair
--rotate mints a new token and invalidates every existing caller, so it is its
own flag and never implicit. After a rotation, restart the stack and update each
consumer.
FORGE_CONTROL_PLANE_API_KEY in the instance .env is an override for the Secrets
Manager read; docker-compose passes it to forge-api only, since the worker and
beat serve no HTTP and have no use for the credential.
If neither source yields a credential, the gated routes answer 503 and
/api/status keeps working -- so a misconfigured host is visibly misconfigured
rather than open.
Environment on the deployed instance¶
ENVIRONMENT selects the secrets/DB target and defaults to prd when
unset (deploy-safe). The stage instance runs ENVIRONMENT=stg. See
Configuration for the full env-var and secret-path matrix,
and note that deployed environments generate for real by default -- stubs
are off unless FORGE_PROVIDER_STUBS=1 is set, and real jobs require an
account_id (3468 on stage) and cost money.