109 lines
3.4 KiB
Bash
Executable File
109 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Deploy script - Creates R2 bucket, configures CORS, and deploys worker
|
|
|
|
set -e # Exit on error
|
|
|
|
echo "=================================================="
|
|
echo "OBS R2 Uploader - Deployment Script"
|
|
echo "=================================================="
|
|
echo ""
|
|
|
|
# Get the directory where this script is located
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
# Check if wrangler is authenticated
|
|
echo "Checking Wrangler authentication..."
|
|
if ! wrangler whoami &> /dev/null; then
|
|
echo "✗ Wrangler is not authenticated"
|
|
echo "Run 'wrangler login' first"
|
|
exit 1
|
|
fi
|
|
echo "✓ Wrangler is authenticated"
|
|
echo ""
|
|
|
|
# Create R2 bucket
|
|
echo "Creating R2 bucket 'obs-videos'..."
|
|
if wrangler r2 bucket create obs-videos 2>&1 | grep -q "already exists"; then
|
|
echo "✓ Bucket 'obs-videos' already exists"
|
|
else
|
|
echo "✓ Bucket 'obs-videos' created"
|
|
fi
|
|
echo ""
|
|
|
|
# Configure CORS
|
|
echo "Configuring CORS for bucket..."
|
|
|
|
# Load R2 credentials from .env
|
|
if [ -f .env ]; then
|
|
export $(grep -v '^#' .env | xargs)
|
|
fi
|
|
|
|
# Check if credentials are available
|
|
if [ -z "$R2_ACCOUNT_ID" ] || [ -z "$R2_ACCESS_KEY_ID" ] || [ -z "$R2_SECRET_ACCESS_KEY" ]; then
|
|
echo "⚠ CORS configuration skipped - R2 credentials not found in .env"
|
|
echo " You can configure CORS manually in Cloudflare dashboard"
|
|
else
|
|
# Apply CORS configuration using AWS CLI-compatible API
|
|
# Check for AWS CLI in venv or system
|
|
if [ -f "venv/bin/aws" ]; then
|
|
AWS_CMD="venv/bin/aws"
|
|
elif command -v aws &> /dev/null; then
|
|
AWS_CMD="aws"
|
|
else
|
|
AWS_CMD=""
|
|
fi
|
|
|
|
if [ -n "$AWS_CMD" ]; then
|
|
echo "Applying CORS configuration..."
|
|
AWS_ACCESS_KEY_ID="$R2_ACCESS_KEY_ID" \
|
|
AWS_SECRET_ACCESS_KEY="$R2_SECRET_ACCESS_KEY" \
|
|
$AWS_CMD s3api put-bucket-cors \
|
|
--bucket obs-videos \
|
|
--cors-configuration file://cors-config.json \
|
|
--endpoint-url "https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ CORS configured successfully"
|
|
else
|
|
echo "⚠ CORS configuration failed - you may need to configure it manually"
|
|
echo " Go to R2 > obs-videos > Settings > CORS Policy in Cloudflare dashboard"
|
|
fi
|
|
else
|
|
echo "⚠ AWS CLI not found - skipping automatic CORS configuration"
|
|
echo " Run: venv/bin/pip install awscli"
|
|
echo " Or configure CORS manually in Cloudflare dashboard"
|
|
echo " Go to R2 > obs-videos > Settings > CORS Policy"
|
|
fi
|
|
fi
|
|
echo ""
|
|
|
|
# List buckets to verify
|
|
echo "Verifying bucket creation..."
|
|
wrangler r2 bucket list
|
|
echo ""
|
|
|
|
# Deploy worker
|
|
echo "Deploying Cloudflare Worker..."
|
|
cd worker
|
|
wrangler deploy
|
|
cd ..
|
|
echo ""
|
|
|
|
echo "=================================================="
|
|
echo "Deployment complete!"
|
|
echo "=================================================="
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Configure CORS in Cloudflare dashboard (see above)"
|
|
echo "2. Set up custom domain (videos.jeffemmett.com) in Cloudflare dashboard:"
|
|
echo " - Go to Workers & Pages > obs-video-server > Settings > Domains"
|
|
echo " - Add custom domain: videos.jeffemmett.com"
|
|
echo "3. Update .env with your R2 credentials:"
|
|
echo " - Go to R2 > obs-videos > Settings > R2 API Tokens"
|
|
echo " - Create a new API token with read/write access"
|
|
echo "4. Test upload: ./scripts/upload.sh /path/to/video.mp4"
|
|
echo ""
|