Simple example of a Python/FastAPI/Poetry demo Api Application
- Python 3
- Poetry 1.1.11
- FastAPI
- Install Poetry
pip install poetry==1.1.11
- build the application project and its dependencies
poetry install
use the script below. This script will ensure poetry 1.1.11 is used to install the project and build an the image
python install-build.py
you can skip the tests with --skip-tests
python install-build.py --skip-tests
you can skip the installation of the project and dependency with --skip-install-poetry
python install-build.py --skip-install-poetry
you can skip build the image with --skip-poetry
python install-build.py --skip-build-images
python3 and poetry are required.
Run the Application localy with this command and check the url returned
poetry run python main.py
Ping the app on http://127.0.0.1:5001/ping
Demo on http://127.0.0.1:5001/demo
Run the unit tests with
poetry run pytest
This is configurable from the file config.py
you can build one localy with this command
docker build -t python-demo-api . docker build --no-cache --progress=plain -t python-demo-api .
You build an image with this script
python install-build.py python install-build.py --skip-install-poetry --skip-tests
Run the image with this command
docker run -p 5001:5001 python-demo-api
This application is deployed to Azure Kubernetes Service (AKS) using Azure DevOps Pipelines.
The deployment process consists of the following stages:
-
Build Stage
- Sets up Python and Poetry
- Installs dependencies
- Builds and tests the application
- Creates and pushes a Docker image to GitHub Container Registry
-
Infrastructure Stage
- Deploys or updates the AKS cluster using Terraform
- Configures network and security settings
-
Deploy Stage
- Retrieves AKS credentials
- Updates the Kubernetes manifest with the current image tag
- Creates necessary Kubernetes secrets for image pulling
- Deploys the application to AKS
- Verifies the deployment
- Azure DevOps project with a service connection to Azure
- GitHub Container Registry credentials stored as pipeline variables
- Terraform state storage in Azure Blob Storage
The application is deployed with the following Kubernetes resources:
- Deployment with the container image
- Service to expose the application
- ConfigMap for application configuration
- Secret for container registry authentication