How ceibalabs/ceiba-infra works
Purpose and entry points
This repository defines Ceiba’s live AWS production infrastructure and the Docker workload deployed to its single EC2 host. Primary operator entry point is Terraform under terraform/; host runtime entry point is deploy/docker-compose.yml. Terraform plans run on PRs but applies remain human-operated with local state.
1. AWS network and isolation
The VPC design uses a public subnet for the internet-facing host and private subnets for RDS. No NAT Gateway is provisioned: RDS has no outbound requirement, reducing fixed cost. Security groups expose EC2 only on HTTP/HTTPS; database ingress is limited to the EC2 security group.
Paths: terraform/vpc.tf, terraform/ec2.tf, terraform/rds.tf.
2. Single-host application runtime
An ARM/Graviton t4g.small EC2 instance is the production execution boundary. Docker Compose runs Ceiba control plane, Ceiba runtime, self-hosted Redis, and Caddy on that host. Caddy terminates TLS via Let’s Encrypt and routes app/API hostnames to containers.
Paths: terraform/ec2.tf, deploy/docker-compose.yml, deploy/Caddyfile.
3. Persistent data and backup boundary
PostgreSQL runs as single-AZ RDS db.t4g.micro, isolated in private networking. RDS provides automated backups; off-instance exports/static assets use versioned S3. CloudTrail records management events for audit and cost investigation.
Paths: terraform/rds.tf, terraform/s3-and-audit.tf, docs/ADR-0006-single-az-rds.md.
4. Image delivery and deployment control plane
Application repositories build ARM images off-host, push them to two ECR repositories, then deploy to the one EC2 instance through SSM. GitHub Actions assumes AWS roles through branch-pinned OIDC trust rather than stored AWS credentials. This repository’s CI only plans Terraform; it does not apply.
Paths: terraform/ecr.tf, terraform/github-oidc.tf, .github/workflows/terraform-plan.yml.
5. Identity, secrets, and least privilege
Human operators use IAM Identity Center; EC2, Lambda, and CI use scoped IAM roles. EC2 can pull designated ECR images, retrieve named secrets/parameters, and access constrained S3 data; deploy identities use SSM against one instance. Secret values are intentionally external to Terraform and Compose templates.
Paths: terraform/iam.tf, terraform/github-oidc.tf, deploy/.env.example.
6. Cost controls and automated shutdown
An $80/month budget sends threshold and forecast alerts through SNS/email. Separately, a CloudWatch billing alarm publishes to SNS, which invokes Lambda to stop the non-critical EC2 instance; RDS is deliberately excluded. The shutdown chain is configured but has not been end-to-end tested.
Paths: terraform/budgets.tf, terraform/cloudwatch-billing-alarm.tf, terraform/lambda-auto-shutdown/handler.py.
7. Operational constraints and evolution
The system intentionally accepts local Terraform state, one operator, one EC2 instance, and single-AZ RDS in exchange for a roughly $30–40/month baseline. Key scaling/reliability upgrades are ALB/horizontal compute, ElastiCache, Multi-AZ RDS, remote Terraform state, and external synthetic monitoring.
Paths: docs/ADR-0003-local-state.md, docs/ADR-0004-ecr-over-host-build.md, docs/cost-breakdown.md.
Main entry points: ec2.tf Graviton EC2 · terraform Terraform infrastructure · docker-compose.yml Docker Compose · rds.tf PostgreSQL RDS
Components 19
Delivery & Access
- Terraform infrastructure · Human-applied infrastructure with local state.
terraform - Terraform plan CI · Runs plans on pull requests only.
.github/workflows/terraform-plan.yml - GitHub OIDC roles · Branch-pinned trust avoids stored AWS credentials.
terraform/github-oidc.tf - SSM deployment · Deploy identities target the single instance.
terraform/iam.tf
AWS Production
- VPC & subnets · Public EC2 subnet and private RDS subnets; no NAT gateway.
terraform/vpc.tf - Graviton EC2 · Single production execution boundary.
terraform/ec2.tf - Security groups · HTTP/HTTPS reach EC2; database access is EC2-only.
terraform/ec2.tf - ECR repositories · Two repositories receive off-host ARM images.
terraform/ecr.tf - Scoped IAM roles · Roles constrain EC2, Lambda, CI, and operator access.
terraform/iam.tf
Single EC2 Host
- Docker Compose · Runs the production container stack.
deploy/docker-compose.yml - Caddy · Obtains Let's Encrypt TLS and routes app/API hostnames.
deploy/Caddyfile - Ceiba services
deploy/docker-compose.yml - Redis
deploy/docker-compose.yml
Data & Audit
- PostgreSQL RDS · Private database with automated backups.
terraform/rds.tf - Versioned S3 · Off-instance persistent data boundary.
terraform/s3-and-audit.tf - CloudTrail · Records management events for audit and cost investigation.
terraform/s3-and-audit.tf
Cost Controls
- Budget & SNS alerts · $80 monthly threshold and forecast alerts.
terraform/budgets.tf - Billing alarm
terraform/cloudwatch-billing-alarm.tf - Auto-shutdown Lambda · Stops EC2; RDS is excluded.
terraform/lambda-auto-shutdown/handler.py
Connections 26
- Terraform plan CI → Terraform infrastructure: plans
- GitHub OIDC roles → Terraform plan CI: authenticates
- Terraform infrastructure → VPC & subnets: provisions
- Terraform infrastructure → Graviton EC2: provisions
- Terraform infrastructure → ECR repositories: provisions
- Terraform infrastructure → PostgreSQL RDS: provisions
- Terraform infrastructure → Scoped IAM roles: defines
- VPC & subnets → Graviton EC2: public subnet
- VPC & subnets → PostgreSQL RDS: private subnets
- Security groups → Graviton EC2: HTTP/HTTPS ingress
- Security groups → PostgreSQL RDS: EC2-only database ingress
- SSM deployment → Graviton EC2: deploys via SSM
- ECR repositories → Graviton EC2: ARM image pulls
- Scoped IAM roles → Graviton EC2: pull, secrets, S3 permissions
- Graviton EC2 → Docker Compose: hosts
- Docker Compose → Caddy: runs
- Docker Compose → Ceiba services: runs
- Docker Compose → Redis: runs
- Caddy → Ceiba services: routes TLS traffic
- Ceiba services → PostgreSQL RDS: application data
- Ceiba services → Redis: cache/runtime state
- Graviton EC2 → Versioned S3: exports and assets
- CloudTrail → Versioned S3: audit storage
- Billing alarm → Budget & SNS alerts: publishes alert
- Budget & SNS alerts → Auto-shutdown Lambda: invokes
- Auto-shutdown Lambda → Graviton EC2: stops on billing alarm