This is a Flak RESTfulAPI. Please run the application and vivsit /swagger
for API documentations.
- http://localhost:3000
- http://localhost:3000/health
- http://localhost:3000/metrics
- http://localhost:3000/swagger
- Visit Swagger for more V1 API details.
🐳 Docker Registry is here -- davidh83110/flask-app
The /history
API will require some history data in place so that it can return to user,
so we have scripts/migrations.py here for helping to inject initial data.
The script will be executed when we run scripts/entrypoint.sh in Docker environment.
If you are not in Docker environment, please run it manually before start the application.
cd scripts
python3 migrations.py
This Page will only focus on Flask application,
if you need any information about Helm
or run in Kubernetes
,
please visit deploy/README.md.
docker-compose up --build -d
- Hardcode the password in the
docker-compose.yaml
, it can also usedocker-compose secret from file
.
cd ./deploy
sh ./startup.sh
- More information, please visit deploy/README.md.
- Python >= 3.10
- Pipenv
- Docker
- Redis Server
- Install Pipenv
python -m pip install --upgrade pip pip install pipenv --no-cache-dir
- Install Dependencies
pipenv install --system --deploy --ignore-pipfile
- Start Redis Locally
docker run -p 6379:6379 -itd redis:alpine
gunicorn --bind 0.0.0.0:3000 \
--access-logfile flask-app-gunicorn.log \
--error-logfile flask-app-gunicron-error.log \
--log-level debug \
wsgi:app
- Build Docker Image
export APP_VERSION=0.0.1 docker build --build-arg APP_VERSION=$APP_VERSION --no-cache -t flask-app .
- Run Docker Container
docker run -p 3000:3000 -it -e REDIS_HOST='172.17.0.1' flask-app
172.17.0.1
is Docker default host network, I am assuming you have a Redis running in Docker.
please visit deploy/README.md.
After the applciation is started, you can always vivist the pages on browser -- http://localhost:3000 .
pipenv install --deploy
pipenv shell
python3 main.py
or
pipenv install --deploy
pipenv run python3 main.py
pipenv install flask ...
pipenv update
pipenv shell
pytest
I use Github Actions
to implement a simple CI/CD pipeline,
which includes unittest
, SAST evulation
, docker build and push
, and helm package and upload
.
- Please visit ci-build.yaml.
- SAST tool - bandit
- We could possibly optimize the pipeline to be faster and comment some messages on the Pull Request, but I just ignore those things since it is a demo only.
The artifacts of this CI pipeline are --
- Docker Image on Docker Hub -- davidh83110/flask-app
- Helm Package on Github Pages
I use a VERSION file to control the Application version, which will be the APP_VERSION
when we build the Docker Image.
But in real environment, I think we can do it with tags triggering
, auto increament
, or integrate with Jira
/Github Project
.
The access and error logs of Gunicorn/Flask will be shown as JSON format,
it is better for most of the log streamer like Filebeat.