Skip to content
/ python_ci_template Public template

Python scaffolding project. Template with CI for testing, linting, releasing in a container

License

Notifications You must be signed in to change notification settings

romitagl/python_ci_template

Repository files navigation

Description

This project can be used as base template to easily start writing your app with the support of a basic CI pipeline that includes testing, linting and code coverage.

Pipeline can be run in you development environment or directly in GitHub.

Workflows status

CI

Features

Is currently supported:

  • Formatting using black
  • Isort sorts your imports.
  • Linting checks using flake8
  • Testing using pytest
  • Executing the target app in a container using Docker
  • GitHub Actions integration for CI/CD executions
  • Project can be used as GitHub Template

Update Python dependencies

Edit/Update the Pipfile to the desired Python/Package version, then:

make run_docker_bash
cd /app
make upgrade_pipenv

How To Run

Dependencies

Quick spin

Run make run_docker_image in the command line. This command will build the CI image running all tests and finally build the release target image and run it.

Makefile contains all the targets to run the code in a containerized environment (Docker) and natively.

Local Development/Testing

The run_docker_bash make target can be used for development/testing without having to install the Python dependencies in the host machine. Everything can be run in a python:3.12 Docker image.

The following commands show how to run the image and format the python code:

make run_docker_bash
cd /app
make dev_dependencies
make activate_pipenv
make format
make ci

Structure

  • src contains the source code of the target app. Use app.py as main() file.
  • tests include the pytest files used to test the app
  • Makefile implements all the Features currently supported
  • Dockerfile Docker image used for releasing the target app

Notes

Run Docker as a non-root user

Create the docker group and add your user to the docker group:

sudo groupadd docker
sudo usermod -aG docker $USER

Deploying your application to the cloud

First, build your image, e.g.: docker build -t myapp .. If your cloud uses a different CPU architecture than your development machine (e.g., you are on a Mac M1 and your cloud provider is amd64), you'll want to build the image for that platform, e.g.: docker build --platform=linux/amd64 -t myapp ..