This project is a showcase of how we can implement a CI/CD workflow on a fastApi based project ran in a Docker container from the base FastAPI Image
Clone the project
git clone https://github.com/ismael-su/python-ci
cd python-ci
python3 -m venv venv
pip install -r requirements.txt
Build locally and run
docker build -t myimage .
docker run -d --name rs -p 0.0.0.0:8080:2376/tcp myimage
Pull image from github package and run locally
Note that the login is required for this step
docker login -u {github_username} -p {[token](https://github.com/settings/tokens)} ghcr.io
docker pull ghcr.io/ismael-su/python-ci:latest
docker run -d --name rs -p 0.0.0.0:8080:2376/tcp ghcr.io/ismael-su/python-ci:latest
Before each commit i run some githooks you will find under .github directory
pre-commit
pip freeze > requirements.txt
git add requirements.txt
autopep8 --in-place --aggressive --aggressive ./app/*.py
flake8 . --count --show-source --s
pytest
This script invokes autopep8 that automatically formats Python code to conform to the PEP 8 style guide Flake8 which is a great toolkit for checking your code base against coding style (PEP8), programming errors (like “library imported but unused” and “Undefined name”). Pytest is a python framework for running unit test. the test file for this project is under app/test_index file
Under .github/workflows/ci-cd.yml there are github actions that run on each push and pull request. They test the project against 3 different version of python (3.7, 3.8, 3.9), runs autopep8, flake8 , run the tests. If everything passes, it then pushes the image to github public container registry then prints the docker iamge url as output