A third party ATProto appview
at main 173 lines 4.8 kB view raw
1#!/bin/bash 2 3# Enable Constellation integration for AppView 4# Adds/updates environment variables and optionally starts the bridge service 5 6set -e 7 8SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 9PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" 10ENV_FILE="$PROJECT_ROOT/.env" 11 12echo "🌌 Constellation Integration Setup" 13echo "==================================" 14echo 15 16# Check if .env exists 17if [ ! -f "$ENV_FILE" ]; then 18 echo "📝 Creating .env file..." 19 touch "$ENV_FILE" 20fi 21 22# Function to update or add env variable 23update_env() { 24 local key=$1 25 local value=$2 26 27 if grep -q "^${key}=" "$ENV_FILE"; then 28 # Update existing 29 sed -i.bak "s|^${key}=.*|${key}=${value}|" "$ENV_FILE" 30 echo "✅ Updated ${key}=${value}" 31 else 32 # Add new 33 echo "${key}=${value}" >> "$ENV_FILE" 34 echo "✅ Added ${key}=${value}" 35 fi 36} 37 38# Prompt for configuration 39echo "Choose Constellation endpoint:" 40echo "1) Public instance (constellation.microcosm.blue) - Recommended for getting started" 41echo "2) Self-hosted instance" 42echo 43read -p "Enter choice [1]: " choice 44choice=${choice:-1} 45 46if [ "$choice" = "2" ]; then 47 read -p "Enter self-hosted Constellation URL [http://constellation:8080]: " CONSTELLATION_URL 48 CONSTELLATION_URL=${CONSTELLATION_URL:-http://constellation:8080} 49 SELF_HOSTED=true 50else 51 CONSTELLATION_URL="https://constellation.microcosm.blue" 52 SELF_HOSTED=false 53 echo 54 echo "ℹ️ Using public instance - please be respectful:" 55 echo " - Free to use for development and production" 56 echo " - Best-effort uptime (no SLA)" 57 echo " - Rate limiting applies" 58 echo 59fi 60 61# Cache TTL 62echo 63read -p "Cache TTL in seconds [60]: " CACHE_TTL 64CACHE_TTL=${CACHE_TTL:-60} 65 66# Update .env file 67echo 68echo "📝 Updating .env file..." 69update_env "CONSTELLATION_ENABLED" "true" 70update_env "CONSTELLATION_URL" "$CONSTELLATION_URL" 71update_env "CONSTELLATION_CACHE_TTL" "$CACHE_TTL" 72 73# Clean up backup 74rm -f "$ENV_FILE.bak" 75 76echo 77echo "✅ Configuration saved to .env" 78echo 79 80# Ask about running the bridge service 81if [ "$SELF_HOSTED" = false ]; then 82 echo "ℹ️ The lightweight integration layer is now configured." 83 echo " Your AppView will query Constellation API directly." 84 echo 85 read -p "Do you want to also run the full bridge service with health monitoring? [y/N]: " run_bridge 86 87 if [[ "$run_bridge" =~ ^[Yy]$ ]]; then 88 RUN_BRIDGE=true 89 else 90 RUN_BRIDGE=false 91 fi 92else 93 echo "ℹ️ For self-hosted instances, we recommend running the bridge service." 94 echo 95 read -p "Run the bridge service? [Y/n]: " run_bridge 96 97 if [[ "$run_bridge" =~ ^[Nn]$ ]]; then 98 RUN_BRIDGE=false 99 else 100 RUN_BRIDGE=true 101 fi 102fi 103 104# Start services 105echo 106echo "🚀 Starting services..." 107echo 108 109cd "$PROJECT_ROOT" 110 111if [ "$RUN_BRIDGE" = true ]; then 112 echo "Starting AppView with Constellation bridge..." 113 docker-compose --profile constellation up -d --build 114 115 echo 116 echo "⏳ Waiting for services to be healthy..." 117 sleep 5 118 119 # Check bridge health 120 if command -v curl &> /dev/null; then 121 echo 122 echo "🏥 Checking bridge health..." 123 if curl -sf http://localhost:3003/health > /dev/null 2>&1; then 124 echo "✅ Constellation bridge is healthy!" 125 echo 126 curl -s http://localhost:3003/health | python3 -m json.tool 2>/dev/null || curl -s http://localhost:3003/health 127 else 128 echo "⚠️ Bridge health check failed, but service may still be starting..." 129 echo " Check logs with: docker-compose logs constellation-bridge" 130 fi 131 fi 132else 133 echo "Restarting AppView with Constellation integration..." 134 docker-compose restart app 135 136 echo 137 echo "⏳ Waiting for AppView to restart..." 138 sleep 3 139fi 140 141echo 142echo "✅ Constellation integration enabled!" 143echo 144echo "📋 Next steps:" 145echo 146 147if [ "$RUN_BRIDGE" = true ]; then 148 echo "1. Check bridge status:" 149 echo " curl http://localhost:3003/health" 150 echo 151 echo "2. View bridge logs:" 152 echo " docker-compose logs -f constellation-bridge" 153 echo 154else 155 echo "1. Check AppView logs for Constellation initialization:" 156 echo " docker-compose logs app | grep CONSTELLATION" 157 echo 158fi 159 160echo "3. Test with a post URI:" 161echo " curl 'https://constellation.microcosm.blue/links/count?target=at://...&collection=app.bsky.feed.like&path=.subject.uri'" 162echo 163 164echo "4. Monitor stats in your feeds - counts should now be network-wide!" 165echo 166 167if [ "$SELF_HOSTED" = true ]; then 168 echo "📝 Note: Make sure your self-hosted Constellation instance is running:" 169 echo " docker-compose --profile constellation-selfhosted up -d" 170 echo 171fi 172 173echo "📚 For more information, see: microcosm-bridge/README.md"