Skip to content

Commit

Permalink
Setup (#1)
Browse files Browse the repository at this point in the history
* ADD: django

* ADD: pylint

* UPDATE: ignore IDE

* ADD: github workflows

* ADD: bandit

* ADD: flake8

* ADD: django

* UPDATE: rename settings

* ADD: Dockerfile

* REMOVE: themes from docker

* FIX: flake8 apps

* ADD: coverage

* FIX: line break

* FIX: settings file

* FIX: no input

* ADD: static root

* ADD: flake8 config

* FORMAT

* ADD: bandit config

* ADD: base template

* ADD: django pylint plugin

* UPDATE: exlude test settings for bandit

* WIP: ignore static in docker until used

* FIX: exclude test setting
  • Loading branch information
Segelzwerg authored Nov 2, 2024
1 parent 25a483a commit 5b29dc0
Show file tree
Hide file tree
Showing 17 changed files with 945 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
exclude =
rechnung/settings.py
rechnung/test_settings.py
**/migrations/

max-line-length = 100
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
63 changes: 63 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Django CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: False
max-parallel: 4
matrix:
python-version: [ '3.13' ]
test-type: [ 'unit', 'integration' ]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
shell: bash
run: poetry install --no-interaction
- name: Install Firefox
uses: browser-actions/setup-firefox@latest
if: ${{ matrix.test-type == 'integration' }}

- name: Run Tests
run: |
poetry run python manage.py collectstatic --settings=rechnung.test_settings --no-input
poetry run coverage run manage.py test --settings=rechnung.test_settings
if: ${{ matrix.test-type == 'unit' }}
- name: Run Tests
run: |
poetry run python manage.py collectstatic --settings=rechnung.test_settings --no-input
poetry run coverage run manage.py test -k Integration --settings=rechnung.test_settings
if: ${{ matrix.test-type == 'integration' }}

- name: Create Report
run: |
poetry run coverage json
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Segelzwerg/rechnung
67 changes: 67 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Docker Image Build & Publish

on:
push:
branches: [ main ]
tags:
- 'v*'
pull_request:
branches: [ main ]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME_GHCR: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}

permissions:
contents: read
packages: write

jobs:
docker:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.13 ]
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_GHCR }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: Whist-Team/actions/setup-poetry@v2
with:
python-version: 3.13

- name: Lint sources with flake8
run: poetry run flake8 rechnung --count --show-source --statistics
- uses: articulate/actions-markdownlint@v1
with:
ignore: static/
- name: Lint sources with pylint
run: poetry run pylint --load-plugins=pylint_django --django-settings-module=rechnung.test_settings rechnung

security:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run bandit
uses: tj-actions/bandit@v5
with:
targets: |
rechnung
options: "-r -c pyproject.toml -x rechnung/test_settings.py"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG PYTHON_VERSION=3.13
FROM python:${PYTHON_VERSION} AS poetry
RUN pip install poetry
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN poetry export -f requirements.txt --output requirements.txt
LABEL authors="Segelzwerg"

FROM python:${PYTHON_VERSION}-slim
WORKDIR /app
COPY --from=poetry /app/requirements.txt .
RUN pip install -r requirements.txt
COPY rechnung ./rechnung/
#COPY static/ ./static/
COPY templates/ ./templates/
COPY manage.py ./manage.py
CMD python manage.py migrate --settings=$DJANGO_SETTINGS_MODUE; python manage.py collectstatic --no-input --settings=$DJANGO_SETTINGS_MODUE; django-admin compilemessages; gunicorn --bind=0.0.0.0 --timeout 600 rechnung.wsgi

Check warning on line 17 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker (3.13)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Rechnung

Django App for invoices
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rechnung.test_settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Loading

0 comments on commit 5b29dc0

Please sign in to comment.