#!/bin/bash set -e echo "🚀 Deploying Blonk to Fly.io..." # Set PATH to include fly export PATH="/root/.fly/bin:$PATH" # Check if authenticated if ! fly auth whoami > /dev/null 2>&1; then echo "❌ Not authenticated with Fly.io" echo "Please run: fly auth login" exit 1 fi echo "📋 Current Fly.io status:" fly auth whoami # Create app if it doesn't exist if ! fly apps list | grep -q "^blonk"; then echo "📦 Creating new Fly app..." fly apps create blonk --org personal echo "✅ App 'blonk' created!" else echo "✅ App 'blonk' already exists" fi # Create PostgreSQL database if it doesn't exist if ! fly postgres list | grep -q "blonk-db"; then echo "🗄️ Creating PostgreSQL database..." fly postgres create --name blonk-db --region dfw --vm-size shared-cpu-1x --volume-size 1 echo "✅ Database 'blonk-db' created!" # Wait a moment for database to be ready echo "⏳ Waiting for database to be ready..." sleep 10 else echo "✅ Database 'blonk-db' already exists" fi # Set up secrets echo "🔑 Setting up secrets..." if [ -f "./setup-fly-secrets.sh" ]; then echo "Running automated secrets setup..." ./setup-fly-secrets.sh else echo "Manual secrets setup required:" echo "fly secrets set SECRET_KEY_BASE=\$(mix phx.gen.secret)" echo "fly secrets set RELEASE_COOKIE=\$(mix phx.gen.secret)" echo "fly secrets set DATABASE_URL=\$(fly postgres connect-string blonk-db)" echo "fly secrets set PHX_HOST=blonk.fly.dev" echo "fly secrets set MIX_ENV=prod" echo "fly secrets set PORT=8080" echo "" echo "ATProto credentials (set manually):" echo "fly secrets set ATPROTO_IDENTIFIER=your_bluesky_handle" echo "fly secrets set ATPROTO_PASSWORD=your_bluesky_app_password" exit 1 fi # Show current secrets (without values) echo "📋 Current secrets:" fly secrets list # Build and deploy echo "🔨 Building and deploying..." fly deploy echo "" echo "✅ Deployment complete!" echo "🌐 Visit your app at: https://blonk.fly.dev" echo "📊 Monitor with: fly logs" echo "🗄️ Check database: fly postgres connect blonk-db" echo "" echo "🔧 Useful commands:" echo " fly status - Check app status" echo " fly logs - View application logs" echo " fly ssh console - SSH into the app" echo " fly scale count 1 - Scale to 1 instance" echo " fly secrets list - View secrets"