#!/bin/bash -e set -o pipefail function kapply() { for f in "$@"; do kubectl apply -f \ <(envsubst "$(env | xargs printf '$%s ')" < "manifests/$f") done }; export -f kapply function kcreatesec() { kubectl create secret generic --save-config --dry-run=client -oyaml "$@" | kubectl apply -f- }; export -f kcreatesec function kcreatecm() { kubectl create configmap --dry-run=client -oyaml "$@" | kubectl apply -f- }; export -f kcreatecm function kgseckey() { local sec="$1"; shift local key="$1"; shift if ! kubectl get secret "$sec" -ojson | jq -re ".data.\"$key\" // empty" | base64 -d; then return 1 fi }; export -f kgseckey function kgcmkey() { local cm="$1"; shift local key="$1"; shift if ! kubectl get configmap "$cm" -ojson | jq -re ".data.\"$key\" // empty"; then return 1 fi }; export -f kgcmkey kapply common/db.yaml export REDIS_HOST=valkey export REDIS_DB=0 export REDIS_PORT=6379 export POSTGRES_HOST; POSTGRES_HOST="$(kgseckey postgres-app host)" export POSTGRES_PORT; POSTGRES_PORT="$(kgseckey postgres-app port)" export POSTGRES_DB; POSTGRES_DB="$(kgseckey postgres-app dbname)" export POSTGRES_USER; POSTGRES_USER="$(kgseckey postgres-app user)" export POSTGRES_PASSWORD; POSTGRES_PASSWORD="$(kgseckey postgres-app password)" # shellcheck disable=SC1090 . <(kubectl run -i --rm --image "$IMAGEAPP" secrets -- bash <