Skip to content

Commit

Permalink
Add template repository
Browse files Browse the repository at this point in the history
  • Loading branch information
antibagr committed Nov 16, 2023
0 parents commit ee0ac90
Show file tree
Hide file tree
Showing 20 changed files with 1,330 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/.mypy_cache/
**/.pytest_cache/
**/__pycache__/
*.md
*.xml
.*
Dockerfile*
Makefile
docker-compose*
env/
htmlcov/
tests/
Empty file added .env
Empty file.
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
max-line-length = 100
extend-ignore = E203, E704, W503
unused-arguments-ignore-abstract-functions = True
unused-arguments-ignore-overload-functions = True

ignore =
# An unused argument starting with an underscore
U101,
Empty file added .gitattributes
Empty file.
47 changes: 47 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI Workflow

on: push

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry
# Reference: https://github.com/actions/setup-python/tree/main
- uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'poetry'
- run: make install
- run: make lint

- name: Run unit tests and coverage
run: |
make tests-units
- name: Coverage Badge
uses: tj-actions/coverage-badge-py@v2

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: coverage.svg

- name: Commit files
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add coverage.svg
git commit -m "Updated coverage.svg"
- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.github_token }}
branch: ${{ github.ref }}
155 changes: 155 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
.idea/

db.json
workspace/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.code-workspace
tests/data/*
temp/*

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
contrib/vault/file/
/contrib/vault/keys/*.json
.local.env

# archives
*.zip
*.gz
*.tar
*.bz2
*.tgz
.DS_Store
Empty file added LICENCE
Empty file.
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SOURCES = app tests

.DEFAULT_GOAL := help

DOCKER_COMPOSE_FILE = contrib/docker-compose.yml
DOCKER_COMPOSE_PROJECT_NAME = app

help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

install: ## Install project dependencies
poetry install --no-interaction --no-ansi
.PHONY: install

format: ## Format the source code
poetry run black $(SOURCES)
poetry run isort $(SOURCES)
.PHONY: format

lint: ## Lint the source code
poetry run black --check $(SOURCES)
poetry run isort --check $(SOURCES)

poetry run flake8 $(SOURCES)
poetry run mypy $(SOURCES)
poetry run bandit -c pyproject.toml -r app

.PHONY: lint

run: ## Run the development Django server
echo "Not implemented"
.PHONY: run

compose-up: ## Run the development Django server with docker-compose
COMPOSE_PROJECT_NAME=${DOCKER_COMPOSE_PROJECT_NAME} docker-compose -f ${DOCKER_COMPOSE_FILE} up --build --remove-orphans --force-recreate
.PHONY: compose-up

compose-down: ## Stop the development Django server with docker-compose
docker-compose down
.PHONY: compose-down

tests-units: ## Run unit tests
poetry run coverage run -m pytest -s ./tests/units
poetry run coverage report --precision=2 -m
.PHONY: tests-units

tests-integrations: ## Run integration tests
poetry run pytest tests/integrations
.PHONY: tests-integrations

test: tests-units tests-integrations ## Run all available tests
.PHONY: test
Empty file added README.md
Empty file.
Empty file added app/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main() -> None:
print("Let the games begin!")


if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions contrib/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.9"

services:
web:
container_name: web
build:
context: ../
dockerfile: deploy/web/Dockerfile.win
32 changes: 32 additions & 0 deletions deploy/web/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# syntax=docker/dockerfile:1

# Source: https://medium.com/@albertazzir/blazing-fast-python-docker-builds-with-poetry-a78a66f5aed0
# The builder image, used to build the virtual environment
FROM python:3.12.0-slim as builder

RUN pip install poetry

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE 1 \
PYTHONUNBUFFERED 1 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

COPY pyproject.toml poetry.lock ./

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-interaction --no-ansi --no-root --only main

# The runtime image, used to just run the code provided its virtual environment
FROM python:3.12.0-slim as runtime

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

COPY app/ ./app/

ENTRYPOINT ["./entrypoint.sh"]
28 changes: 28 additions & 0 deletions deploy/web/Dockerfile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Windows does not support BuildKit yet, so we need to use the old syntax
# Reference: https://github.com/moby/buildkit/issues/616
FROM python:3.12.0-slim

ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

RUN pip install poetry

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app

COPY ./scripts/entrypoint.sh ./entrypoint.sh
RUN sed -i 's/\r$//g' ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

COPY pyproject.toml poetry.lock ./

RUN poetry install --no-interaction --no-ansi --no-root --only main && rm -rf $POETRY_CACHE_DIR

COPY app /app/app/

ENTRYPOINT ["./entrypoint.sh"]
Loading

0 comments on commit ee0ac90

Please sign in to comment.