Production-ready deployment of a Dockerized Flask + PostgreSQL app on AWS EC2, using Terraform for infrastructure provisioning and Docker Compose for container orchestration.
Deployment Status: Offline — destroy via
terraform destroyto avoid charges. All IaC configs in/terraform.
AWS (EC2 - Amazon Linux 2023)
┌──────────────────────────────────────┐
│ ┌───────────────┐ ┌─────────────┐ │
│ │ Flask App │ │ PostgreSQL │ │
│ │ Port: 5000 │ │ Volume: yes │ │
│ └───────────────┘ └─────────────┘ │
│ Docker Compose (multi-container) │
└──────────────────────────────────────┘
| Component | Technology |
|---|---|
| Infrastructure | AWS EC2 + Security Groups |
| IaC | Terraform |
| Orchestration | Docker Compose v2 |
| Backend | Flask (Python) |
| Database | PostgreSQL (persistent volume) |
| CI/CD | GitHub Actions |
Push to main
↓
✅ App CI (parallel) ✅ Terraform CI (parallel)
→ pip install → terraform fmt
→ docker build → terraform validate
↓ ↓
└──────────── both pass ────────┘
↓
⏸️ Manual approval gate
↓
🚀 terraform apply → provisions EC2
AWS credentials stored as GitHub Secrets — never hardcoded.
cd terraform
terraform init
terraform apply -auto-approveThe user_data script automatically installs Docker, clones the repo, and starts all containers (~5 min). Access at http://<EC2_PUBLIC_IP>:5000.
pip install -r requirements.txt
flask runRequires PostgreSQL running locally. Configure .env based on .env.example.
| Route | Method | Description |
|---|---|---|
/ |
GET | All quotes |
/random |
GET | Random quote from external API |
/insert |
POST | Add new quote |
/update |
PUT | Update existing quote |
/delete/{id}/ |
DELETE | Delete quote by ID |
terraform destroy -auto-approve- CI/CD with GitHub Actions — parallel Flask + Terraform validation with manual approval gate before AWS provisioning
- user_data automation — fully automated EC2 bootstrap: Docker install, repo clone, and Compose stack start on first boot
- Docker Compose v2 — resolved compatibility issues between Amazon Linux 2023 and modern Compose plugin syntax
- Persistent volumes — configured PostgreSQL data volume to survive container restarts
Fork of jaykantrprj/sample-flask-quotes-webapp. Cloud infrastructure and CI/CD pipeline added by MisaelTox.