Giter Club home page Giter Club logo

python-ci's Introduction

Python FastApi docker CI/CD Workflow

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

Run the docker 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

CI / CD Workflows and Linting/Testing

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

github actions

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

python-ci's People

Contributors

ismael-su avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.