From 7fab4e40720c274abc943e188fe5d5e314d776d3 Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Fri, 7 Mar 2025 13:59:33 +0000 Subject: [PATCH] chore(database): add postgres and valkey services These are used by `strapi` and `directus` to store data. --- services/database/compose.yml | 48 +++++++++++++++++++ .../postgres/00-create-strapi-database.sh | 7 +++ .../postgres/01-create-directus-database.sh | 7 +++ 3 files changed, 62 insertions(+) create mode 100644 services/database/compose.yml create mode 100755 services/database/scripts/postgres/00-create-strapi-database.sh create mode 100755 services/database/scripts/postgres/01-create-directus-database.sh diff --git a/services/database/compose.yml b/services/database/compose.yml new file mode 100644 index 0000000..276c9bd --- /dev/null +++ b/services/database/compose.yml @@ -0,0 +1,48 @@ +--- +services: + postgres: + image: 'postgres:17.4-bookworm' + hostname: ${CMS_POSTGRES_HOST:-postgres} + init: true + restart: unless-stopped + healthcheck: + test: + - CMD-SHELL + - pg_isready + - --hostname + - localhost + - --username + - ${CMD_POSTGRES_USER:-postgres} + interval: 10s + timeout: 5s + retries: 5 + start_interval: 5s + start_period: 30s + environment: + POSTGRES_USER: ${CMS_POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${CMS_POSTGRES_PASSWORD:-postgres} + volumes: + - 'postgres_data:/var/lib/postgresql/data' + - './scripts/postgres:/docker-entrypoint-initdb.d' + + # NOTE: (jpd) this is an open-source alternative to redis + valkey: + image: 'valkey/valkey:8.0.2-bookworm' + hostname: ${CMS_VALKEY_HOST:-valkey} + init: true + restart: unless-stopped + healthcheck: + test: + - CMD-SHELL + - '[ $$(redis-cli ping) = "PONG" ]' + interval: 10s + timeout: 5s + retries: 5 + start_interval: 5s + start_period: 30s + volumes: + - 'valkey_data:/data' + +volumes: + postgres_data: {} + valkey_data: {} diff --git a/services/database/scripts/postgres/00-create-strapi-database.sh b/services/database/scripts/postgres/00-create-strapi-database.sh new file mode 100755 index 0000000..0aba19e --- /dev/null +++ b/services/database/scripts/postgres/00-create-strapi-database.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -ex + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE DATABASE strapi; + GRANT ALL PRIVILEGES ON DATABASE strapi TO ${POSTGRES_USER}; +EOSQL diff --git a/services/database/scripts/postgres/01-create-directus-database.sh b/services/database/scripts/postgres/01-create-directus-database.sh new file mode 100755 index 0000000..dd2fb1f --- /dev/null +++ b/services/database/scripts/postgres/01-create-directus-database.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE DATABASE directus; + GRANT ALL PRIVILEGES ON DATABASE strapi TO ${POSTGRES_USER}; +EOSQL