Skip to content

Commit

Permalink
Merge pull request #63 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v0.2.0 - #minor
  • Loading branch information
schtibe authored Dec 19, 2024
2 parents 086e659 + 1ff3ced commit 040b9e7
Show file tree
Hide file tree
Showing 111 changed files with 8,121 additions and 508 deletions.
2 changes: 2 additions & 0 deletions .bandit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bandit]
exclude = tests
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[report]
exclude_lines =
if TYPE_CHECKING:
17 changes: 17 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@ DB_PW=postgres
DB_PORT=15432
DB_HOST=localhost
DB_NAME_TEST=postgres_test
BOD_USER=postgres
BOD_NAME=bod_master
BOD_PW=postgres
BOD_PORT=15433
BOD_HOST=localhost
DJANGO_SETTINGS_MODULE=config.settings_dev
SECRET_KEY=django-insecure-6-72r#zx=sv6v@-4k@uf1gv32me@%yr*oqa*fu8&5l&a!ws)5#
COGNITO_POOL_ID=local_PoolPrty
COGNITO_PORT=9229
COGNITO_ENDPOINT_URL=http://localhost:9229
COGNITO_MANAGED_FLAG_NAME=dev:custom:managed_by_service

# used for local development
AWS_REGION=eu-central-2
AWS_DEFAULT_REGION=eu-central-2
AWS_ACCESS_KEY_ID=123
AWS_SECRET_ACCESS_KEY=123

DEBUG=True
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

- [ ] Model changes documented in the [business entity model](https://ltwiki.adr.admin.ch:8443/display/PB/Business+Entity+Model)
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
.env
# Byte-compiled / optimized / DLL files
__pycache__

# Distribution / packaging
.env
var/

# IDE config files
.vscode

# Local database
.volumes

# Coverage
coverage.xml
htmlcov/
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,6 @@ min-public-methods=2

# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception,
StandardError
overgeneral-exceptions=builtins.BaseException,
builtins.Exception,
builtins.StandardError
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Container that contains basic configurations used by all other containers
# It should only contain variables that don't change or change very infrequently
# so that the cache is not needlessly invalidated
FROM python:3.12-slim-bullseye as base
FROM python:3.12-slim-bullseye AS base
ENV HTTP_PORT=8080
ENV USER=geoadmin
ENV GROUP=geoadmin
Expand All @@ -18,7 +18,7 @@ RUN apt-get -qq update > /dev/null \

###########################################################
# Builder container
FROM base as builder
FROM base AS builder
RUN apt-get -qq update > /dev/null \
&& apt-get -qq -y install \
# dev dependencies
Expand All @@ -37,7 +37,7 @@ COPY --chown=${USER}:${GROUP} app/ ${INSTALL_DIR}/app/

###########################################################
# Container to perform tests/management/dev tasks
FROM base as debug
FROM base AS debug
LABEL target=debug
ENV DEBUG=1

Expand Down Expand Up @@ -81,6 +81,9 @@ ENV PYTHONHOME=""
ARG VERSION=unknown
RUN echo "APP_VERSION = '$VERSION'" > ${INSTALL_DIR}/app/config/version.py

# Collect static files.
RUN ${INSTALL_DIR}/app/manage.py collectstatic --noinput

ARG GIT_HASH=unknown
ARG GIT_BRANCH=unknown
ARG GIT_DIRTY=""
Expand All @@ -101,7 +104,7 @@ ENTRYPOINT ["python"]

###########################################################
# Container to use in production
FROM base as production
FROM base AS production
LABEL target=production
ENV DEBUG=0

Expand All @@ -121,6 +124,9 @@ ENV PYTHONHOME=""
ARG VERSION=unknown
RUN echo "APP_VERSION = '$VERSION'" > ${INSTALL_DIR}/app/config/version.py

# Collect static files.
RUN ${INSTALL_DIR}/app/manage.py collectstatic --noinput

ARG GIT_HASH=unknown
ARG GIT_BRANCH=unknown
ARG GIT_DIRTY=""
Expand Down
35 changes: 31 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ AUTHOR = $(USER)
# Django specific
APP_SRC_DIR := app
DJANGO_MANAGER := $(CURRENT_DIR)/$(APP_SRC_DIR)/manage.py
DJANGO_MANAGER_DEBUG := -m debugpy --listen localhost:5678 --wait-for-client $(CURRENT_DIR)/$(APP_SRC_DIR)/manage.py

# Commands
PIPENV_RUN := pipenv run
PYTHON := $(PIPENV_RUN) python3
TEST := $(PIPENV_RUN) pytest
YAPF := $(PIPENV_RUN) yapf
ISORT := $(PIPENV_RUN) isort
PYLINT := $(PIPENV_RUN) pylint
MYPY := $(PIPENV_RUN) mypy
PSQL := PGPASSWORD=postgres psql -h localhost -p 15433 -U postgres
PGRESTORE := PGPASSWORD=postgres pg_restore -h localhost -p 15433 -U postgres
BANDIT := $(PIPENV_RUN) bandit

# Find all python files that are not inside a hidden directory (directory starting with .)
PYTHON_FILES := $(shell find $(APP_SRC_DIR) -type f -name "*.py" -print)
Expand All @@ -55,8 +60,8 @@ ci:
.PHONY: setup
setup: $(SETTINGS_TIMESTAMP) ## Create virtualenv with all packages for development
pipenv install --dev
pipenv shell
cp .env.default .env
pipenv shell

.PHONY: format
format: ## Call yapf to make sure your code is easier to read and respects some conventions.
Expand Down Expand Up @@ -87,6 +92,9 @@ ci-check-format: format ## Check the format (CI)
serve: ## Serve the application locally
$(PYTHON) $(DJANGO_MANAGER) runserver

.PHONY: serve-debug
serve-debug: ## Serve the application locally for debugging
$(PYTHON) $(DJANGO_MANAGER_DEBUG) runserver

.PHONY: dockerlogin
dockerlogin: ## Login to the AWS Docker Registry (ECR)
Expand Down Expand Up @@ -140,11 +148,30 @@ type-check: ## Run the type-checker mypy
start-local-db: ## Run the local db as docker container
docker compose up -d

.PHONY: test-ci
test-ci: ## Run tests in the CI
$(TEST) --cov --cov-branch --cov-report=xml:coverage.xml

.PHONY: test
test: ## Run tests locally
# Collect static first to avoid warning in the test
# $(PYTHON) $(DJANGO_MANAGER) collectstatic --noinput
$(PYTHON) $(DJANGO_MANAGER) test --verbosity=2 --parallel 20 $(CI_TEST_OPT) $(TEST_DIR) $(APP_SRC_DIR)
$(TEST) --cov --cov-branch --cov-report=html

.PHONY: setup-bod
setup-bod: ## Set up the bod locally
$(PSQL) -c 'CREATE ROLE "pgkogis";'
$(PSQL) -c 'CREATE ROLE "www-data";'
$(PSQL) -c 'CREATE ROLE "bod_admin";'
$(PSQL) -c 'CREATE ROLE "rdsadmin";'

.PHONY: import-bod
import-bod: ## Import the bod locally
$(PSQL) -c 'DROP DATABASE IF EXISTS bod_master;'
$(PSQL) -c 'CREATE DATABASE bod_master;'
$(PGRESTORE) -d bod_master $(file) --v

.PHONY: security-check
security-check: ## Run bandit security checker locally
$(BANDIT) --recursive --ini .bandit app

.PHONY: help
help: ## Display this help
Expand Down
11 changes: 10 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ verify_ssl = true
name = "pypi"

[packages]
django = "~=5.0.7"
django = "~=5.0.10"
django-ninja = "~=1.1"
psycopg2-binary = "~=2.9.5"
django-environ = "~=0.11"
gunicorn = "~=23.0"
pyyaml = "~=6.0.2"
gevent = "~=24.2"
logging-utilities = "~=4.4.1"
boto3 = "~=1.35.78"
nanoid = "~=2.0.0"
whitenoise = "~=6.8.2"

[dev-packages]
yapf = "*"
Expand All @@ -29,6 +32,12 @@ pytest-django = "*"
mypy = "*"
types-gevent = "*"
django-stubs = "~=5.0.4"
debugpy = "*"
boto3-stubs = {extras = ["cognito-idp"], version = "~=1.35"}
bandit = "*"
pytest-xdist = "*"
types-nanoid = "*"
pytest-cov = "*"

[requires]
python_version = "3.12"
Loading

0 comments on commit 040b9e7

Please sign in to comment.