From f5be67b2192579265426b4042db62b8233061269 Mon Sep 17 00:00:00 2001 From: ae Date: Wed, 9 Apr 2025 02:12:43 +0300 Subject: [PATCH] build: initial dev. setup with docker compose --- .env.template | 8 ++++++ docker-compose.yml | 61 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/purge.sh | 6 +++++ scripts/run_dev.sh | 8 ++++++ 4 files changed, 83 insertions(+) create mode 100644 .env.template create mode 100755 scripts/purge.sh create mode 100755 scripts/run_dev.sh diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..07f4198 --- /dev/null +++ b/.env.template @@ -0,0 +1,8 @@ +# Database +PG_USER="" +PG_PASS="" +PG_DB="" + +# Server +JWT_SECRET="" +LOG_LEVEL="debug" diff --git a/docker-compose.yml b/docker-compose.yml index e69de29..5622bf0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -0,0 +1,61 @@ +services: + notatest-psql: + image: postgres:16-alpine + container_name: notatest-psql + restart: unless-stopped + healthcheck: + test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"] + start_period: 20s + interval: 30s + retries: 5 + timeout: 5s + volumes: + # Alternatively mount to disk -> ${PWD}/data + - notatest-data:/var/lib/postgresql/data + networks: + - notatest + environment: + POSTGRES_USER: ${PG_USER:-notatest} + POSTGRES_PASSWORD: ${PG_PASS:?db password required} + POSTGRES_DB: ${PG_DB:-notatest} + + notatest-server: + container_name: notatest-server + build: + context: ${PWD}/server + dockerfile: ${PWD}/server/Dockerfile + image: notatest-server:latest + networks: + - notatest + ports: + - 8080:8080 # TODO: remove forwarding after testing + depends_on: + notatest-psql: + condition: service_healthy + environment: + JWT_SECRET: ${JWT_SECRET:?jwt secret required} + DB_URL: postgres://${PG_USER:-notatest}:${PG_PASS:?db password required}@notatest-psql/${PG_DB:-notatest}?sslmode=disable + LOG_LEVEL: ${LOG_LEVEL:-info} + ADMIN_USERNAME: ${ADMIN_USERNAME:?init admin username required} + ADMIN_PASSWORD: ${ADMIN_PASSWORD:?init admin password required} + + # notatest-web: + # build: ${PWD}/web + # image: notatest/web + # container_name: notatest-web + # networks: + # - notatest + # ports: + # - 3030:3030 + # depends_on: + # notatest-psql: + # condition: service_healthy + # notatest-server: + +networks: + notatest: + external: false + name: notatest + +volumes: + notatest-data: diff --git a/scripts/purge.sh b/scripts/purge.sh new file mode 100755 index 0000000..ad9325a --- /dev/null +++ b/scripts/purge.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Delete all Docker artifacts (e.g. DB) from previous test runs + +docker stop notatest-server notatest-psql && docker rm -f notatest-server notatest-psql +docker volume rm -f notatest_notatest-data diff --git a/scripts/run_dev.sh b/scripts/run_dev.sh new file mode 100755 index 0000000..d09206b --- /dev/null +++ b/scripts/run_dev.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +[ "$( docker container inspect -f '{{.State.Status}}' notatest-psql )" = "running" ] || docker compose up notatest-psql -d + +# Shutdown, rebuild, & restart +docker compose stop notatest-server && docker compose rm -f notatest-server +docker compose build +docker compose up notatest-server