From 35ca5ed377247443465beaa43f0b14d7cfd336ee Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Mon, 18 Dec 2023 00:00:36 -0500 Subject: [PATCH] refactor(taskfiles): consolidate start+stop, add namespace for docker tasks --- Taskfile.backend.yml | 21 ++++++++------------- backend/script/start.sh | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Taskfile.backend.yml b/Taskfile.backend.yml index b3398e1..df0642c 100644 --- a/Taskfile.backend.yml +++ b/Taskfile.backend.yml @@ -34,28 +34,23 @@ tasks: cmd: . script/test dotenv: - ../backend-test.env - start: + lock-deps: + desc: "Locks production and development dependencies" + deps: [bootstrap] + cmd: . script/requirements-lock + docker:start: desc: "Starts the backend application." deps: [build] cmd: . script/start.sh dotenv: - ../backend.env - stop: + docker:stop: desc: "Stops the backend application." cmd: docker rm -f {{ .APP_CONTAINER_NAME }} {{ .DB_CONTAINER_NAME }} - logs: + docker:logs: desc: "Shortcut to Docker container logs" cmd: docker logs {{ .APP_CONTAINER_NAME }} -f - start-db: - desc: "Provisions a local Postgres database." - dotenv: - - ../backend.env - cmd: . script/provision-db - lock-deps: - desc: "Locks production and development dependencies" - deps: [bootstrap] - cmd: . script/requirements-lock - build: + docker:build: desc: "Builds a docker image from /backend" cmd: . script/build.sh diff --git a/backend/script/start.sh b/backend/script/start.sh index 8efa385..54de080 100644 --- a/backend/script/start.sh +++ b/backend/script/start.sh @@ -1,5 +1,20 @@ #!/bin/bash +docker run \ + --name $DB_CONTAINER_NAME \ + -e POSTGRES_PASSWORD=$DATABASE_PASSWORD \ + -e POSTGRES_USER=$DATABASE_USER \ + -e POSTGRES_DB=$DATABASE_NAME \ + -v $DATABASE_STORAGE_PATH:/var/lib/postgresql/data \ + -p 5432:5432 \ + -d \ + postgres:15.4 + +until [ -n "$(docker exec $DB_CONTAINER_NAME pg_isready | grep accepting)" ]; do + echo "Waiting for DB to come alive..." + sleep 0.1; +done; + docker run \ --detach \ --publish 8000:8000 \