{"id":35324329,"url":"https://github.com/harcastic/two-tier-flask-app","last_synced_at":"2026-04-07T23:31:42.665Z","repository":{"id":326060632,"uuid":"1103648938","full_name":"harcastic/two-tier-flask-app","owner":"harcastic","description":"Fully automated CI/CD pipeline for a two-tier Flask + MySQL app using Jenkins, Docker, and AWS EC2. Code pushes trigger automated builds, tests, and deployments via Docker Compose, delivering a production-style, containerized web application.","archived":false,"fork":false,"pushed_at":"2025-11-25T14:45:55.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-28T15:47:47.944Z","etag":null,"topics":["ci-cd","cloud","docker","docker-compose","ec2-instance","flask-application","jenkins","mysql-database"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harcastic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-25T06:36:03.000Z","updated_at":"2025-11-25T14:45:59.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/harcastic/two-tier-flask-app","commit_stats":null,"previous_names":["harcastic/two-tier-flask-app"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/harcastic/two-tier-flask-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harcastic%2Ftwo-tier-flask-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harcastic%2Ftwo-tier-flask-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harcastic%2Ftwo-tier-flask-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harcastic%2Ftwo-tier-flask-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harcastic","download_url":"https://codeload.github.com/harcastic/two-tier-flask-app/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harcastic%2Ftwo-tier-flask-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31533823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","cloud","docker","docker-compose","ec2-instance","flask-application","jenkins","mysql-database"],"created_at":"2025-12-31T01:03:26.031Z","updated_at":"2026-04-07T23:31:42.660Z","avatar_url":"https://github.com/harcastic.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Two-Tier Flask Application with CI/CD using Jenkins, Docker \u0026 AWS EC2\n\nThis project demonstrates a production-style CI/CD pipeline for a two-tier web application built using Flask (App Layer) and MySQL (Database Layer). The entire deployment is automated using Jenkins, Docker, Docker Compose, and GitHub Webhooks, running on AWS EC2.\n\n## 🏗️ Architecture Overview\n\n```\nGitHub → Jenkins → Docker Build → EC2 SSH → Docker Compose → Flask App + MySQL\n```\n\n### Two-Tier Setup\n\n- **Tier 1 – Flask App (Python backend)**\n- **Tier 2 – MySQL Database (Persistent storage)**\n\nBoth run in separate containers managed by docker-compose.\n\n### CI/CD Flow\n\n1. Developer pushes code to GitHub\n2. GitHub Webhook triggers Jenkins\n3. Jenkins pulls repository\n4. Jenkins builds Docker images\n5. Jenkins runs unit tests\n6. Jenkins SSHs into EC2\n7. Docker Compose deploys updated containers\n8. Updated Flask app goes LIVE instantly\n\n## ⚙️ Tech Stack\n\n| Component | Technology |\n|-----------|-----------|\n| App | Python Flask |\n| Database | MySQL 8.0 |\n| CI/CD | Jenkins |\n| SCM | GitHub |\n| Containerization | Docker \u0026 Docker Compose |\n| Cloud | AWS EC2 (Ubuntu) |\n| Trigger | GitHub Webhook |\n\n## 📂 Project Structure\n\n```\n.\n├── app/\n│   ├── app.py                 # Flask application\n│   ├── requirements.txt        # Python dependencies\n│   └── Dockerfile             # Docker image for Flask app\n│    \n├── tests/\n│   └── test_basic.py          # Unit tests\n├── docker-compose.yml         # Multi-container orchestration\n├── Jenkinsfile                # CI/CD pipeline configuration\n└── README.md                  # This file\n```\n\n### Key Files\n\n**Dockerfile**\n- Builds the Flask application container\n- Manages Python dependencies and application setup\n\n**docker-compose.yml**\n- Runs two containers:\n  - `web`: Flask application (exposed on port 80)\n  - `db`: MySQL database with persistent volumes \u0026 environment variables\n\n**Jenkinsfile**\n- Automates the complete CI/CD pipeline:\n  - Clone code from GitHub\n  - Build Docker images\n  - Run unit tests\n  - Deploy containers to EC2\n\n## 🚀 Deployment Instructions\n\n### 1️⃣ Set Up EC2 (App Server)\n\nInstall Docker and Docker Compose:\n\n```bash\nsudo apt update\nsudo apt install docker.io docker-compose -y\nsudo usermod -aG docker ubuntu\n```\n\nClone the repository (first time only):\n\n```bash\ngit clone https://github.com/harcastic/two-tier-flask-app.git\ncd two-tier-flask-app\n```\n\n### 2️⃣ Set Up Jenkins EC2 Server\n\nInstall Java and Jenkins:\n\n```bash\nsudo apt update\nsudo apt install fontconfig openjdk-17-jre -y\nwget -O jenkins.war https://get.jenkins.io/war-stable/latest/jenkins.war\n```\n\nInstall Jenkins Plugins:\n- Git plugin\n- SSH Pipeline Steps\n- Docker plugins\n- Credentials Binding\n\nAdd Credentials in Jenkins:\n- GitHub Personal Access Token\n- EC2 SSH Private Key (for `app-ec2-ssh`)\n\n### 3️⃣ Configure Jenkins Pipeline\n\nCreate a new Pipeline job and use the following configuration:\n\n```groovy\npipeline {\n    agent any\n\n    stages {\n        stage('Clone Code') {\n            steps {\n                git branch: 'main',\n                    url: 'https://github.com/harcastic/two-tier-flask-app.git'\n            }\n        }\n\n        stage('Build Docker Images') {\n            steps {\n                sh 'docker-compose build'\n            }\n        }\n\n        stage('Run Unit Tests') {\n            steps {\n                sh 'docker-compose run web pytest || true'\n            }\n        }\n\n        stage('Deploy to EC2') {\n            steps {\n                sshagent(['app-ec2-ssh']) {\n                    sh 'ssh -o StrictHostKeyChecking=no ubuntu@\u003cAPP_EC2_IP\u003e \"cd two-tier-flask-app \u0026\u0026 git pull \u0026\u0026 docker-compose down \u0026\u0026 docker-compose up -d\"'\n                }\n            }\n        }\n    }\n}\n```\n\n**Replace `\u003cAPP_EC2_IP\u003e` with your actual EC2 instance public IP**\n\n### 4️⃣ Set Up GitHub Webhook\n\nConfigure GitHub to trigger Jenkins automatically:\n\n1. Go to your repository → **Settings** → **Webhooks** → **Add Webhook**\n2. Set **Payload URL**: `http://\u003cJENKINS_PUBLIC_IP\u003e:8080/github-webhook/`\n3. Set **Content Type**: `application/json`\n4. Select events: ✔ **Push events**\n5. Click **Add webhook**\n\n**Replace `\u003cJENKINS_PUBLIC_IP\u003e` with your Jenkins EC2 instance public IP**\n\n## 🧪 Verification\n\n### Check Running Containers\n\n```bash\ndocker ps\n```\n\nExpected output should show:\n- `web` - Flask application container\n- `db` - MySQL database container\n\n### Access Flask Application\n\nOpen your browser and navigate to:\n\n```\nhttp://\u003cAPP_EC2_PUBLIC_IP\u003e\n```\n\nYou should see the Flask application running with the message \"New Updates are released!!\"\n\n### Check Container Logs\n\n```bash\n# View all logs\ndocker-compose logs\n\n# View specific service logs\ndocker-compose logs web\ndocker-compose logs db\n```\n\n### Test Health Endpoint\n\n```bash\ncurl http://\u003cAPP_EC2_PUBLIC_IP\u003e/health\n```\n\nShould return: `OK`\n\n## ✅ Features\n\n- ✔ End-to-end CI/CD automation\n- ✔ Two-tier containerized application\n- ✔ Production-style deployment workflow\n- ✔ GitHub → Jenkins Webhook integration\n- ✔ Docker Compose-based multi-container architecture\n- ✔ Real cloud deployment on AWS EC2\n- ✔ Automated unit testing in pipeline\n- ✔ Zero-downtime deployments\n\n## 📘 Future Improvements\n\n- [ ] Add comprehensive unit testing coverage\n- [ ] Implement Blue-Green deployment strategy\n- [ ] Add monitoring with Prometheus/Grafana\n- [ ] Migrate to Kubernetes for orchestration\n- [ ] Implement automated rollback on test failures\n- [ ] Add database migration scripts\n- [ ] Implement secrets management using AWS Secrets Manager\n- [ ] Add container image scanning for security vulnerabilities\n- [ ] Setup CloudWatch for centralized logging\n- [ ] Implement auto-scaling policies\n\n## 🔧 Environment Variables\n\nConfigure the following in your `docker-compose.yml` or environment:\n\n```yaml\nMYSQL_ROOT_PASSWORD: root123\nMYSQL_DATABASE: flaskdb\n```\n\n## 📝 Notes\n\n- The Flask app runs on port 5000 internally and is exposed on port 80\n- MySQL data is persisted using Docker volumes (`db_data`)\n- Jenkins must have SSH access to the App EC2 instance\n- GitHub Webhook requires Jenkins to be accessible from the internet\n- All deployments are containerized for consistency across environments\n\n## 🙌 Acknowledgements\n\nThis project demonstrates real-world DevOps practices and helped in learning:\n\n- Jenkins Pipeline automation\n- Docker build and containerization\n- GitHub Webhooks for event-driven CI/CD\n- Multi-tier application deployment strategies\n- Infrastructure as Code with Docker Compose\n- Cloud deployment on AWS EC2\n- End-to-end automation workflows\n\n## 📚 Additional Resources\n\n- [Flask Documentation](https://flask.palletsprojects.com/)\n- [Docker Documentation](https://docs.docker.com/)\n- [Jenkins Pipeline Documentation](https://www.jenkins.io/doc/book/pipeline/)\n- [GitHub Webhooks Documentation](https://docs.github.com/en/developers/webhooks-and-events/webhooks)\n- [AWS EC2 Documentation](https://docs.aws.amazon.com/ec2/)\n\n## 📄 License\n\nThis project is open source and available under the MIT License.\n\n---\n\n**Last Updated**: November 2025\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharcastic%2Ftwo-tier-flask-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharcastic%2Ftwo-tier-flask-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharcastic%2Ftwo-tier-flask-app/lists"}