Skip to content

Commit

Permalink
Adds db function back into Makefile and includes DB in local.env.example
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbarnes committed Sep 9, 2024
1 parent f8bdb9c commit 110697c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,7 +133,7 @@
"filename": "Makefile",
"hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3",
"is_verified": false,
"line_number": 104
"line_number": 102
}
],
"orp/tests/conftest.py": [
Expand Down Expand Up @@ -160,5 +164,5 @@
}
]
},
"generated_at": "2024-08-07T09:06:47Z"
"generated_at": "2024-09-09T12:08:54Z"
}
31 changes: 30 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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)"
Expand Down
5 changes: 5 additions & 0 deletions local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 110697c

Please sign in to comment.