#!/usr/bin/env bash # Bugsink for Peppa (PEP-58), idempotent: secrets in .env, database in Peppa's Postgres, # container peppa-bugsink on 127.0.0.1:3180, Traefik route bugsink.telecom.quest, API token. # Usage: scripts/bugsink-up.sh [path/to/.env] (default: /.env) set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" ENV_FILE="${1:-$ROOT/.env}" TRAEFIK_DYNAMIC="${TRAEFIK_DYNAMIC:-/Users/timur/Dev/_Zorro/_INFRA/traefik/dynamic}" [ -f "$ENV_FILE" ] || { echo "no $ENV_FILE"; exit 1; } chmod 600 "$ENV_FILE" get() { grep -E "^$1=" "$ENV_FILE" | tail -1 | cut -d= -f2- || true; } put() { [ -n "$(get "$1")" ] || { printf '%s=%s\n' "$1" "$2" >>"$ENV_FILE"; echo "added $1 to .env"; }; } rnd() { openssl rand -hex "$1"; } put BUGSINK_SECRET_KEY "$(rnd 32)" put BUGSINK_DB_PASSWORD "$(rnd 16)" put BUGSINK_ADMIN_EMAIL "admin@telecom.quest" put BUGSINK_ADMIN_PASSWORD "$(rnd 12)" put BUGSINK_PUBLIC_URL "https://bugsink.telecom.quest" put BUGSINK_URL "http://127.0.0.1:3180" # docker exec target for alert webhooks; where the container reaches Peppa's web. put BUGSINK_CONTAINER "peppa-bugsink" put BUGSINK_WEBHOOK_BASE "http://host.docker.internal:3100" PG="docker exec -i peppa-postgres psql -U peppa -v ON_ERROR_STOP=1 -tA" if [ -z "$($PG -c "select 1 from pg_roles where rolname='bugsink'")" ]; then $PG -c "create role bugsink login password '$(get BUGSINK_DB_PASSWORD)'" >/dev/null echo "created role bugsink" fi if [ -z "$($PG -c "select 1 from pg_database where datname='bugsink'")" ]; then $PG -c "create database bugsink owner bugsink" >/dev/null echo "created database bugsink" fi PEPPA_ENV_FILE="$ENV_FILE" "$ROOT/scripts/infra-up.sh" postgres bugsink for i in $(seq 1 60); do curl -sf http://127.0.0.1:3180/health/ready >/dev/null && break sleep 2 done curl -sf http://127.0.0.1:3180/health/ready >/dev/null || { echo "bugsink not ready"; docker logs --tail 30 peppa-bugsink; exit 1; } # One team for all Peppa projects (the API has no team endpoints); its id goes to .env. if [ -z "$(get BUGSINK_TEAM_ID)" ]; then TEAM=$(docker exec peppa-bugsink bugsink-manage shell -c " from teams.models import Team t = Team.objects.filter(name='Peppa').first() or Team.objects.create(name='Peppa') print(t.id)" | tail -1) put BUGSINK_TEAM_ID "$TEAM" fi if [ -z "$(get BUGSINK_TOKEN)" ]; then put BUGSINK_TOKEN "$(docker exec peppa-bugsink bugsink-manage create_auth_token | tail -1)" fi if [ -d "$TRAEFIK_DYNAMIC" ]; then cp "$ROOT/infra/traefik/bugsink.yml" "$TRAEFIK_DYNAMIC/bugsink.yml" echo "traefik route installed: $TRAEFIK_DYNAMIC/bugsink.yml" fi echo "bugsink ready: $(get BUGSINK_URL) (public $(get BUGSINK_PUBLIC_URL))"