From 0582f9877e5d39bc2917035e85bc33676caa64fb Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sat, 16 Dec 2023 21:32:05 -0500 Subject: [PATCH] refactor(taskfiles): extract start logic out of taskfile --- Taskfile.backend.yml | 6 ++++-- backend-test.env | 5 +++++ backend/rotini/base/settings.py | 10 +++++----- backend/script/start.sh | 8 ++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 backend/script/start.sh diff --git a/Taskfile.backend.yml b/Taskfile.backend.yml index 2075f63..155342b 100644 --- a/Taskfile.backend.yml +++ b/Taskfile.backend.yml @@ -46,8 +46,10 @@ tasks: start: desc: "Starts the backend application." deps: [docker-build] - cmd: docker run -d -p 8000:8000 --name {{ .APP_CONTAINER_NAME }} {{ .CLI_ARGS }} --add-host docker.host.internal:host-gateway --env-file ../../backend.env rotini:dev - dir: backend/rotini + env: + APP_CONTAINER_NAME: "{{ .APP_CONTAINER_NAME }}" + cmd: . script/start.sh + dir: backend stop: desc: "Stops the backend application." cmd: docker rm -f {{ .APP_CONTAINER_NAME }} diff --git a/backend-test.env b/backend-test.env index 157ab3b..3eccfae 100644 --- a/backend-test.env +++ b/backend-test.env @@ -1,2 +1,7 @@ DJANGO_SECRET_KEY="notakey" JWT_SIGNING_SECRET="notasecret" +DB_HOST="rotini_db" +DB_USER="postgres" +DB_PASSWORD="postgres" +DB_PORT=5432 +DB_NAME="postgres" diff --git a/backend/rotini/base/settings.py b/backend/rotini/base/settings.py index 1793cce..027514b 100644 --- a/backend/rotini/base/settings.py +++ b/backend/rotini/base/settings.py @@ -64,11 +64,11 @@ WSGI_APPLICATION = "base.wsgi.application" DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", - "NAME": "postgres", - "USER": "postgres", - "PASSWORD": "test", - "HOST": "docker.host.internal", - "PORT": "5432", + "NAME": os.environ["DB_NAME"], + "USER": os.environ["DB_USER"], + "PASSWORD": os.environ["DB_PASSWORD"], + "HOST": os.environ["DB_HOST"], + "PORT": os.environ["DB_PORT"], } } diff --git a/backend/script/start.sh b/backend/script/start.sh new file mode 100644 index 0000000..8efa385 --- /dev/null +++ b/backend/script/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +docker run \ + --detach \ + --publish 8000:8000 \ + --name $APP_CONTAINER_NAME \ + --env-file ../backend.env \ + rotini:dev