#!/usr/bin/env bash # Bugsink for Peppa (PEP-58), idempotent: secrets in .env, SQLite database in the volume # peppa-bugsink-data (PEP-63; moving an old Postgres install: scripts/bugsink-migrate-to-sqlite.sh), # 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_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" # An install still on Postgres must be moved, not started on an empty SQLite database. if docker inspect peppa-postgres >/dev/null 2>&1 && ! docker volume inspect peppa-bugsink-data >/dev/null 2>&1; then echo "Bugsink's data is in peppa-postgres: run scripts/bugsink-migrate-to-sqlite.sh first (PEP-63)" exit 1 fi PEPPA_ENV_FILE="$ENV_FILE" "$ROOT/scripts/infra-up.sh" 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))"