#!/usr/bin/env bash # PostgreSQL — the cluster half of soleprint's postgres cabinet. # # A room declares the dependency once, in cfg//data/cabinets.json. On a # laptop `build.py` composes it into docker-compose.yml; here it becomes a pod, # so the same declaration works either way and nothing has to be remembered # twice. # # Plain manifests rather than a helm chart, matching the other addons: a chart # repo is a network dependency, and the offline profile exists precisely so # there is a path with none. The image is pinned in ctrl/versions.env and can be # preloaded into a local registry like every other image here. # # One replica on a PVC. This models a dependency for local work, not a # highly-available database, and pretending otherwise on a kind node would be a # more elaborate lie rather than a more useful one. set -euo pipefail cd "$(dirname "$0")/.." source ./lib/config.sh load_config K="kubectl --context ${KUBECONTEXT}" NS="${DATA_NAMESPACE:-data}" $K get namespace "$NS" >/dev/null 2>&1 || $K create namespace "$NS" # The password is generated once and then left alone, so re-running this does # not rotate the credential out from under whatever is already connected. if $K get secret -n "$NS" postgres >/dev/null 2>&1; then echo " secret exists, keeping the current password" else password=$(head -c 18 /dev/urandom | base64 | tr -d '/+=' | head -c 24) $K create secret generic postgres -n "$NS" \ --from-literal=POSTGRES_DB="${POSTGRES_DB:-soleprint}" \ --from-literal=POSTGRES_USER="${POSTGRES_USER:-soleprint}" \ --from-literal=POSTGRES_PASSWORD="$password" >/dev/null echo " generated a password (read it back with the command printed below)" fi echo " applying manifests" $K apply -n "$NS" -f - >/dev/null <