From 110697cb163a3a53a22a12aee76c70891bc58780 Mon Sep 17 00:00:00 2001 From: Greg Barnes Date: Mon, 9 Sep 2024 13:09:29 +0100 Subject: [PATCH] Adds db function back into Makefile and includes DB in local.env.example --- .secrets.baseline | 8 ++++++-- Makefile | 31 ++++++++++++++++++++++++++++++- local.env.example | 5 +++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 3c67884..aa8d1f1 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -90,6 +90,10 @@ { "path": "detect_secrets.filters.allowlist.is_line_allowlisted" }, + { + "path": "detect_secrets.filters.common.is_baseline_file", + "filename": ".secrets.baseline" + }, { "path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", "min_level": 2 @@ -129,7 +133,7 @@ "filename": "Makefile", "hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3", "is_verified": false, - "line_number": 104 + "line_number": 102 } ], "orp/tests/conftest.py": [ @@ -160,5 +164,5 @@ } ] }, - "generated_at": "2024-08-07T09:06:47Z" + "generated_at": "2024-09-09T12:08:54Z" } diff --git a/Makefile b/Makefile index ff7c4b0..7e7009b 100644 --- a/Makefile +++ b/Makefile @@ -7,14 +7,42 @@ COLOUR_GREEN=\033[32;01m COLOUR_YELLOW=\033[33;01m COLOUR_RED=\033[31;01m -.PHONY: help build first-use up down start stop clean logs test bdd shell shell-local lint black isort +.PHONY: help database drop-database build collectstatic admin first-use up down start stop clean logs test bdd shell shell-local lint black isort help: # List commands and their descriptions @grep -E '^[a-zA-Z0-9_-]+: # .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ": # "; printf "\n\033[93;01m%-30s %-30s\033[0m\n\n", "Command", "Description"}; {split($$1,a,":"); printf "\033[96m%-30s\033[0m \033[92m%s\033[0m\n", a[1], $$2}' +database: # Create a postgres database for the project + @echo "$(COLOUR_GREEN)Initialising database...$(COLOUR_NONE)" + docker compose up --force-recreate --remove-orphans -d db + docker compose exec db createdb -h localhost -U postgres -T template0 orp + docker compose stop db + @echo "$(COLOUR_GREEN)Done$(COLOUR_NONE)" + +drop-database: # Delete project's postgres database + @echo "$(COLOUR_RED)Drop database orp$(COLOUR_NONE)" + @read -p "Are you sure? " -n 1 -r; \ + if [[ $$REPLY =~ ^[Yy] ]]; \ + then \ + echo ""; \ + echo "$(COLOUR_RED)Dropping database orp$(COLOUR_NONE)"; \ + docker compose up --force-recreate --remove-orphans -d db; \ + docker compose exec db dropdb -h localhost -U postgres orp; \ + docker compose stop db; \ + echo "$(COLOUR_GREEN)Done$(COLOUR_NONE)"; \ + else \ + echo "\n$(COLOUR_GREEN)Cancelled$(COLOUR_NONE)"; \ + fi + build: # Build docker containers for local execution docker build --no-cache -f local_deployment/Dockerfile -t local_deployment . docker compose build +collectstatic: # Run Django collectstatic + docker compose run --rm web poetry run python orp/manage.py collectstatic --noinput + +admin: # Create a superuser + docker compose exec web poetry run python orp/manage.py createsuperuser --username admin --email admin@localhost + first-use: # Initialise for local execution @echo "$(COLOUR_GREEN)Preparing for first use$(COLOUR_NONE)" @echo "$(COLOUR_GREEN)Ensuring all containers are stopped...$(COLOUR_NONE)" @@ -24,6 +52,7 @@ first-use: # Initialise for local execution @echo "$(COLOUR_GREEN)Starting...$(COLOUR_NONE)" $(MAKE) up @echo "$(COLOUR_GREEN)Initialising web service...$(COLOUR_NONE)" + $(MAKE) admin $(MAKE) stop @echo "$(COLOUR_GREEN)$(APPLICATION_NAME) is ready for use$(COLOUR_NONE)"; @echo "$(COLOUR_GREEN)Start services with 'make start'$(COLOUR_NONE)" diff --git a/local.env.example b/local.env.example index 9a6192d..a598efd 100644 --- a/local.env.example +++ b/local.env.example @@ -8,3 +8,8 @@ DEBUG=True DJANGO_ADMIN=False DJANGO_SETTINGS_MODULE=config.settings.local DJANGO_SECRET_KEY=orp-secret + +# Database Settings +DATABASE_URL=postgres://postgres:postgres@db:5432/orp # pragma: allowlist secret +DB_MAX_CONNS=1 +POSTGRES_HOST_AUTH_METHOD=trust