|
1 |
| -## Flask + Docker + GitHub Actions |
| 1 | +# 🚀 Flask App CI/CD with Docker & GitHub Actions |
| 2 | + |
| 3 | +A simple Flask application that is **automatically built, tested, and pushed to Docker Hub** using **GitHub Actions**. This project demonstrates a lightweight CI/CD pipeline for containerized apps. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 📂 Project Structure |
| 8 | + |
| 9 | +```bash |
| 10 | +. |
| 11 | +├── app.py # Main Flask application |
| 12 | +├── test_app.py # Unit tests for the app |
| 13 | +├── Dockerfile # Docker image build instructions |
| 14 | +├── requirements.txt # Python dependencies |
| 15 | +├── .gitignore |
| 16 | +├── README.md |
| 17 | +└── .github/ |
| 18 | + └── workflows/ |
| 19 | + └── cicd.yml # GitHub Actions workflow |
| 20 | +``` |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## ⚙️ Tech Stack |
| 25 | + |
| 26 | +* **Flask** – Lightweight Python web framework |
| 27 | +* **Docker** – Containerizes the app |
| 28 | +* **GitHub Actions** – Automates build, test, and Docker push |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## 🔁 CI/CD Pipeline Overview |
| 33 | + |
| 34 | +Every push to the `main` branch triggers the following steps: |
| 35 | + |
| 36 | +1. ✅ **Checkout code** |
| 37 | +2. 📦 **Install dependencies** |
| 38 | +3. 🧪 **Run unit tests** |
| 39 | +4. 🐳 **Build Docker image** |
| 40 | +5. 🚀 **Push image to Docker Hub** |
| 41 | + |
| 42 | +> The pipeline is defined in `.github/workflows/cicd.yml`. |
| 43 | +
|
| 44 | +--- |
| 45 | + |
| 46 | +## 🧪 Running Locally |
| 47 | + |
| 48 | +### 1. Clone the repo |
| 49 | + |
| 50 | +```bash |
| 51 | +git clone https://github.com/amitkumar0128/flask_docker_cicd.git |
| 52 | +cd flask_docker_cicd |
| 53 | +``` |
| 54 | + |
| 55 | +### 2. Install dependencies |
| 56 | + |
| 57 | +```bash |
| 58 | +pip install -r requirements.txt |
| 59 | +``` |
| 60 | + |
| 61 | +### 3. Run the app |
| 62 | + |
| 63 | +```bash |
| 64 | +python app.py |
| 65 | +``` |
| 66 | + |
| 67 | +> App will be available at `http://localhost:5000` |
| 68 | +
|
| 69 | +--- |
| 70 | + |
| 71 | +## 🐳 Build & Run with Docker |
| 72 | + |
| 73 | +### Build image: |
| 74 | + |
| 75 | +```bash |
| 76 | +docker build -t flask-docker-ci . |
| 77 | +``` |
| 78 | + |
| 79 | +### Run container: |
| 80 | + |
| 81 | +```bash |
| 82 | +docker run -p 5000:5000 flask-docker-ci |
| 83 | +``` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## 🧪 Run Tests |
| 88 | + |
| 89 | +```bash |
| 90 | +python test_app.py |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## 🐙 GitHub Actions Workflow |
| 96 | + |
| 97 | +Update your Docker Hub credentials in GitHub: |
| 98 | + |
| 99 | +1. Go to your repo → **Settings** → **Secrets and variables** → **Actions** |
| 100 | +2. Add these secrets: |
| 101 | + |
| 102 | + * `DOCKER_USERNAME` |
| 103 | + * `DOCKER_PASSWORD` |
| 104 | + |
| 105 | +> These will be used to authenticate and push the image to Docker Hub securely. |
| 106 | +
|
| 107 | +--- |
| 108 | + |
| 109 | +## 📦 Docker Hub Image |
| 110 | + |
| 111 | +> 🐳 [docker.io/akj49/flask-app](https://hub.docker.com/repository/docker/akj49/flask-app/general) |
| 112 | +
|
| 113 | +--- |
| 114 | + |
| 115 | +## 📄 License |
| 116 | + |
| 117 | +MIT License |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## 🙋♂️ Author |
| 122 | + |
| 123 | +**Amit Kumar** |
| 124 | +🔗 [GitHub](https://github.com/amitkumar0128) |
0 commit comments