diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..b593b9a --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,16 @@ +pipeline: + backend: + image: python + environment: + - DATABSE_URL=postgres://postgres:password@database:5432/postgres + commands: + - pip install virtualenv + - make env + - make lint + - make test + +services: + database: + image: postgres + environment: + - POSTGRES_PASSWORD=password diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7c94792 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +define run_migrations ## run migrations + @ . ./venv/bin/activate && python manage.py makemigrations + @ . ./venv/bin/activate && python manage.py migrate +endef + +define unimplemented + @echo "ERROR: Unimplemented!" && echo -1. +endef + +default: ## Run app + $(call run_migrations) + . ./venv/bin/activate && python manage.py runserver + +coverage: ## Generate test coverage report + $(call unimplemented) + +doc: ## Generates documentation + $(call unimplemented) + +docker: ## Build Docker image from source + $(call unimplemented) + +env: ## Install all dependencies + @-virtualenv venv + . ./venv/bin/activate && pip install -r requirements.txt + +freeze: ## Freeze python dependencies + @. ./venv/bin/activate && pip freeze > requirements.txt + +help: ## Prints help for targets with comments + @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +lint: ## Run linter + @./venv/bin/black ./payments/* + @./venv/bin/black ./billing/* + +migrate: ## Run migrations + $(call run_migrations) + +test: ## Run tests + @. ./venv/bin/activate && python manage.py test diff --git a/payments/settings.py b/payments/settings.py index 9a90656..be88953 100644 --- a/payments/settings.py +++ b/payments/settings.py @@ -9,9 +9,13 @@ https://docs.djangoproject.com/en/4.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.0/ref/settings/ """ +import environ +import os from pathlib import Path +env = environ.Env() + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -27,7 +31,6 @@ DEBUG = True ALLOWED_HOSTS = [] - # Application definition INSTALLED_APPS = [ @@ -74,14 +77,9 @@ WSGI_APPLICATION = "payments.wsgi.application" # https://docs.djangoproject.com/en/4.0/ref/settings/#databases DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": "postgres", - "HOST": "localhost", - "PORT": "5432", - "PASSWORD": "password", - "USER": "postgres", - } + "default": env.db_url( + "DATABSE_URL", default="postgres://postgres:password@localhost:5432/postgres" + ) } diff --git a/requirements.txt b/requirements.txt index 8d9426b..7e846bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,23 @@ asgiref==3.5.0 astroid==2.9.3 +black==22.1.0 +click==8.0.4 Django==4.0.3 +django-environ==0.8.1 greenlet==1.1.2 isort==5.10.1 jedi==0.18.1 lazy-object-proxy==1.7.1 mccabe==0.6.1 msgpack==1.0.3 +mypy-extensions==0.4.3 parso==0.8.3 -pika==1.2.0 +pathspec==0.9.0 platformdirs==2.5.1 psycopg2==2.9.3 pylint==2.12.2 pynvim==0.4.3 sqlparse==0.4.2 toml==0.10.2 +tomli==2.0.1 wrapt==1.13.3