An open API service indexing awesome lists of open source software.

https://github.com/georges034302/az-app-service-workflow

Python-Flask API container deployment to Azure App Service using GitHub Actions workflows
https://github.com/georges034302/az-app-service-workflow

appservice azure docker github-actions keyvault python pythonflask

Last synced: 2 months ago
JSON representation

Python-Flask API container deployment to Azure App Service using GitHub Actions workflows

Awesome Lists containing this project

README

          

## ๐Ÿ Employee API (Containerized Python App on Azure App Service)

This project provides a minimal FastAPI-based backend API to simulate an employee directory. The API is packaged into a Docker container, pushed to Azure Container Registry (ACR), and deployed to Azure App Service for Linux using **GitHub Actions**.

---

### ๐Ÿ“Œ Features

- โœ… Python + FastAPI-based backend API
- ๐Ÿ“ฆ Dockerized and deployed to **Azure App Service**
- ๐Ÿ” CI/CD pipeline with **GitHub Actions**
- ๐Ÿ” Secure credentials via **GitHub Secrets**
- ๐Ÿงช Mock data served from a local JSON file

---

### ๐Ÿงช API Endpoints

| Method | Endpoint | Description |
|--------|----------------------------|------------------------------------|
| GET | `/users` | List all employees |
| GET | `/users/{id}` | Get a single employee by ID |

**Full API URLs after deployment:**

- **Get all users:**
```
https://.azurewebsites.net/users
```

- **Get user by ID (example for user 2):**
```
https://.azurewebsites.net/users/2
```

Replace `` with your actual Azure App Service name.

Sample response from `/users`:
```json
[
{"id": 1, "name": "Alice", "role": "Manager", "department": "HR", "city": "Sydney"},
{"id": 2, "name": "Bob", "role": "Developer", "department": "IT", "city": "Melbourne"},
{"id": 3, "name": "Eve", "role": "Analyst", "department": "Finance", "city": "Brisbane"}
]
```

---

### โš™๏ธ Setup Instructions

#### 1. ๐Ÿ” GitHub Actions Workflows

**How these are used in the workflow:**

- **setup-iac.yml**:
*Run once to provision Azure resources and set up infrastructure-as-code (IAC) using the above secrets.*

- **deploy.yml**:
*Used for configuring and deploying the App Service container. This workflow expects all secrets to be present and resources to already exist (created by `setup-iac.yml`).*

---

#### 2. ๐Ÿ“ Project Structure

```
az-app-service-workflow/
โ”œโ”€โ”€ .github/
โ”‚ โ”œโ”€โ”€ app/
โ”‚ โ”‚ โ”œโ”€โ”€ __init__.py
โ”‚ โ”‚ โ”œโ”€โ”€ main.py
โ”‚ โ”‚ โ””โ”€โ”€ data.json
โ”‚ โ”œโ”€โ”€ scripts/
โ”‚ โ”‚ โ”œโ”€โ”€ acr_setup.sh
โ”‚ โ”‚ โ”œโ”€โ”€ az_login.sh
โ”‚ โ”‚ โ”œโ”€โ”€ az_setup.sh
โ”‚ โ”‚ โ”œโ”€โ”€ configure_app_service.sh
โ”‚ โ”‚ โ”œโ”€โ”€ deploy_app_service_container.sh
โ”‚ โ”‚ โ”œโ”€โ”€ gh_setup.sh
โ”‚ โ”‚ โ”œโ”€โ”€ output.sh
โ”‚ โ”‚ โ”œโ”€โ”€ setup.sh
โ”‚ โ”‚ โ””โ”€โ”€ tools_config.sh
โ”‚ โ””โ”€โ”€ workflows/
โ”‚ โ”œโ”€โ”€ deploy.yml
โ”‚ โ””โ”€โ”€ setup-iac.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md
```

---

#### 3. โš™๏ธ Local Setup & Deployment

I. **Authenticate and configure environment: (Run-Once)**
```bash
cd .github/scripts
bash setup.sh
```

II. **Deploy to Azure (manual run):**
```bash
cd .github/scripts
bash deploy.sh
```

---

#### 4. ๐Ÿš€ CI/CD with GitHub Actions

- Triggered on push to `main` branch.
- deploy.yaml workflow runs on push
- Uses GitHub secrets and scripts to:
- Log in to Azure
- Build and push Docker image to ACR
- Configure App Service to use image
- Deploy container-app to App Service

---

#### 5. ๐Ÿณ Local Docker Run (for testing)

```bash
docker build -t employee-api .
docker run -d -p 80:80 employee-api
```

Access API at: [http://localhost](http://localhost)

---

#### ๐Ÿ‘จโ€๐Ÿ’ป Author: Georges Bou Ghantous
*This repository demonstrates automated deployment of a Python FastAPI app to Azure App Service and Azure Container Registry (ACR) using GitHub Actions. ๐Ÿ’™*