https://github.com/benc-uk/python-demoapp
Simple Python Flask web application designed for running in containers for demos
https://github.com/benc-uk/python-demoapp
docker flask kubernetes python
Last synced: about 2 months ago
JSON representation
Simple Python Flask web application designed for running in containers for demos
- Host: GitHub
- URL: https://github.com/benc-uk/python-demoapp
- Owner: benc-uk
- License: mit
- Archived: true
- Created: 2019-11-29T09:55:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-26T12:21:24.000Z (over 1 year ago)
- Last Synced: 2024-11-13T17:45:51.832Z (7 months ago)
- Topics: docker, flask, kubernetes, python
- Language: JavaScript
- Homepage:
- Size: 16.1 MB
- Stars: 140
- Watchers: 5
- Forks: 1,101
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - benc-uk/python-demoapp - Simple Python Flask web application designed for running in containers for demos (JavaScript)
README
# Python Flask - Demo Web Application
This is a simple Python Flask web application. The app provides system information and a realtime monitoring screen with dials showing CPU, memory, IO and process information.
The app has been designed with cloud native demos & containers in mind, in order to provide a real working application for deployment, something more than "hello-world" but with the minimum of pre-reqs. It is not intended as a complete example of a fully functioning architecture or complex software design.
Typical uses would be deployment to Kubernetes, demos of Docker, CI/CD (build pipelines are provided), deployment to cloud (Azure) monitoring, auto-scaling
## Screenshot

# Status
   
Live instances:
[](https://python-demoapp.azurewebsites.net/)
[](https://python-demoapp.kube.benco.io/)## Building & Running Locally
### Pre-reqs
- Be using Linux, WSL or MacOS, with bash, make etc
- [Python 3.8+](https://www.python.org/downloads/) - for running locally, linting, running tests etc
- [Docker](https://docs.docker.com/get-docker/) - for running as a container, or image build and push
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux) - for deployment to AzureClone the project to any directory where you do development work
```
git clone https://github.com/benc-uk/python-demoapp.git
```### Makefile
A standard GNU Make file is provided to help with running and building locally.
```text
help ๐ฌ This help message
lint ๐ Lint & format, will not fix but sets exit code on error
lint-fix ๐ Lint & format, will try to fix errors and modify code
image ๐จ Build container image from Dockerfile
push ๐ค Push container image to registry
run ๐ Run the server locally using Python & Flask
deploy ๐ Deploy to Azure Web App
undeploy ๐ Remove from Azure
test ๐ฏ Unit tests for Flask app
test-report ๐ฏ Unit tests for Flask app (with report output)
test-api ๐ฆ Run integration API tests, server must be running
clean ๐งน Clean up project
```Make file variables and default values, pass these in when calling `make`, e.g. `make image IMAGE_REPO=blah/foo`
| Makefile Variable | Default |
| ----------------- | ---------------------- |
| IMAGE_REG | ghcr.io |
| IMAGE_REPO | benc-uk/python-demoapp |
| IMAGE_TAG | latest |
| AZURE_RES_GROUP | temp-demoapps |
| AZURE_REGION | uksouth |
| AZURE_SITE_NAME | pythonapp-{git-sha} |The app runs under Flask and listens on port 5000 by default, this can be changed with the `PORT` environmental variable.
# Containers
Public container image is [available on GitHub Container Registry](https://github.com/users/benc-uk/packages/container/package/python-demoapp)
Run in a container with:
```bash
docker run --rm -it -p 5000:5000 ghcr.io/benc-uk/python-demoapp:latest
```Should you want to build your own container, use `make image` and the above variables to customise the name & tag.
## Kubernetes
The app can easily be deployed to Kubernetes using Helm, see [deploy/kubernetes/readme.md](deploy/kubernetes/readme.md) for details
# GitHub Actions CI/CD
A working set of CI and CD release GitHub Actions workflows are provided `.github/workflows/`, automated builds are run in GitHub hosted runners
### [GitHub Actions](https://github.com/benc-uk/python-demoapp/actions)
[](https://github.com/benc-uk/python-demoapp/actions?query=workflow%3A%22CI+Build+App%22)
[](https://github.com/benc-uk/python-demoapp/actions?query=workflow%3A%22CD+Release+-+AKS%22)
[](https://github.com/benc-uk/python-demoapp/actions?query=workflow%3A%22CD+Release+-+Webapp%22)
[](https://github.com/benc-uk/python-demoapp/commits/master)
## Running in Azure App Service (Linux)
If you want to deploy to an Azure Web App as a container (aka Linux Web App), a Bicep template is provided in the [deploy](deploy/) directory
For a super quick deployment, use `make deploy` which will deploy to a resource group, temp-demoapps and use the git ref to create a unique site name
```bash
make deploy
```## Running in Azure App Service (Windows)
Just don't, it's awful