Files
motovaultpro/scripts/ci/generate-log-config.sh
Eric Gullickson 853a075e8b
All checks were successful
Deploy to Staging / Build Images (push) Successful in 39s
Deploy to Staging / Deploy to Staging (push) Successful in 52s
Deploy to Staging / Verify Staging (push) Successful in 9s
Deploy to Staging / Notify Staging Ready (push) Successful in 8s
Deploy to Staging / Notify Staging Failure (push) Has been skipped
chore: centralize docker-compose variables into .env
Stripe Price IDs were hardcoded and duplicated across 4 compose files.
Log levels were hardcoded per-overlay instead of using generate-log-config.sh.
This refactors all environment-specific variables into a single .env file
that CI/CD generates from Gitea repo variables + generate-log-config.sh.

- Add .env.example template with documented variables
- Replace hardcoded values with ${VAR:-default} substitution in base compose
- Simplify prod overlay from 90 to 32 lines (remove redundant env blocks)
- Add YAML anchors to blue-green overlay (eliminate blue/green duplication)
- Remove redundant OCR env block from staging overlay
- Change generate-log-config.sh to output to stdout (pipe into .env)
- Update staging/production CI/CD to generate .env with Stripe + log vars
- Remove dangerous pk_live_ default from VITE_STRIPE_PUBLISHABLE_KEY

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 19:57:36 -06:00

57 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# generate-log-config.sh - Generate log-level environment variables
# Maps a single LOG_LEVEL to per-container settings and writes to stdout
#
# Usage: ./generate-log-config.sh [LOG_LEVEL]
# LOG_LEVEL: DEBUG, INFO, WARN, or ERROR (default: INFO)
#
# Output: Log configuration variables on stdout (append to .env)
# Example: ./generate-log-config.sh INFO >> .env
#
# Exit codes:
# 0 - Configuration generated successfully
# 1 - Invalid LOG_LEVEL provided
set -euo pipefail
LOG_LEVEL="${1:-INFO}"
# Validate input
case "$LOG_LEVEL" in
DEBUG|INFO|WARN|ERROR) ;;
*)
echo "Error: Invalid LOG_LEVEL '$LOG_LEVEL'. Must be DEBUG, INFO, WARN, or ERROR." >&2
exit 1
;;
esac
# Convert to lowercase for services that need it
LOG_LEVEL_LOWER=$(echo "$LOG_LEVEL" | tr '[:upper:]' '[:lower:]')
# Map PostgreSQL log settings based on level
case "$LOG_LEVEL" in
DEBUG) POSTGRES_LOG_STATEMENT="all"; POSTGRES_LOG_MIN_DURATION="0" ;;
INFO) POSTGRES_LOG_STATEMENT="ddl"; POSTGRES_LOG_MIN_DURATION="500" ;;
WARN) POSTGRES_LOG_STATEMENT="none"; POSTGRES_LOG_MIN_DURATION="1000" ;;
ERROR) POSTGRES_LOG_STATEMENT="none"; POSTGRES_LOG_MIN_DURATION="-1" ;;
esac
# Map Redis log level
case "$LOG_LEVEL" in
DEBUG) REDIS_LOGLEVEL="debug" ;;
INFO) REDIS_LOGLEVEL="verbose" ;;
WARN) REDIS_LOGLEVEL="notice" ;;
ERROR) REDIS_LOGLEVEL="warning" ;;
esac
# Output log configuration to stdout
cat << EOF
# Log levels (generated by generate-log-config.sh $LOG_LEVEL)
BACKEND_LOG_LEVEL=$LOG_LEVEL_LOWER
TRAEFIK_LOG_LEVEL=$LOG_LEVEL
POSTGRES_LOG_STATEMENT=$POSTGRES_LOG_STATEMENT
POSTGRES_LOG_MIN_DURATION=$POSTGRES_LOG_MIN_DURATION
REDIS_LOGLEVEL=$REDIS_LOGLEVEL
EOF