Refactor Supabase services in docker-compose.yml for better organization and testing
- Commented out all Supabase services to facilitate testing with Supabase CLI. - Updated README to include Supabase directory in project structure. - Adjusted documentation for migration paths in Supabase Docker Compose guide. - Enhanced docker-compose-reset.sh to explicitly remove Supabase volumes and wait for migrations to complete.
This commit is contained in:
87
scripts/docker-compose-reset.sh
Normal file → Executable file
87
scripts/docker-compose-reset.sh
Normal file → Executable file
@@ -2,8 +2,10 @@
|
||||
# Docker Compose Reset Script
|
||||
# This script performs a complete reset of the Docker Compose environment:
|
||||
# - Stops and removes containers, networks, and volumes
|
||||
# - Explicitly removes Supabase volumes (supabase-db, supabase-storage)
|
||||
# - Prunes unused Docker resources (containers, images, networks, volumes)
|
||||
# - Rebuilds and starts all services in detached mode
|
||||
# - Waits for Supabase migrations to complete
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
@@ -24,7 +26,23 @@ echo "1. Stopping and removing containers, networks, and volumes..."
|
||||
docker compose down -v
|
||||
echo ""
|
||||
|
||||
echo "2. Pruning unused Docker resources..."
|
||||
echo "2. Removing Supabase volumes explicitly..."
|
||||
# Find and remove Supabase volumes (they may be named with project prefix)
|
||||
# Docker Compose typically names volumes as: <project>_<volume-name>
|
||||
# Try to find volumes containing 'supabase-db' or 'supabase-storage'
|
||||
SUPABASE_VOLUMES=$(docker volume ls --format "{{.Name}}" | grep -E "(supabase-db|supabase-storage)" || true)
|
||||
|
||||
if [ -n "$SUPABASE_VOLUMES" ]; then
|
||||
echo "$SUPABASE_VOLUMES" | while read -r volume; do
|
||||
echo " - Removing Supabase volume: $volume"
|
||||
docker volume rm "$volume" 2>/dev/null || echo " (Volume may have been removed already or is in use)"
|
||||
done
|
||||
else
|
||||
echo " - No Supabase volumes found (they may have been removed already)"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "3. Pruning unused Docker resources..."
|
||||
echo " - Pruning unused containers..."
|
||||
docker container prune -f
|
||||
|
||||
@@ -38,18 +56,79 @@ echo " - Pruning unused volumes..."
|
||||
docker volume prune -f
|
||||
echo ""
|
||||
|
||||
echo "3. Rebuilding and starting all services in detached mode..."
|
||||
echo "4. Rebuilding and starting all services in detached mode..."
|
||||
docker compose up --build -d
|
||||
echo ""
|
||||
|
||||
echo "4. Checking service status..."
|
||||
echo "5. Waiting for Supabase database to be ready..."
|
||||
# Wait for database to be healthy
|
||||
MAX_WAIT=60
|
||||
WAIT_COUNT=0
|
||||
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
|
||||
if docker compose ps supabase-db | grep -q "healthy"; then
|
||||
echo " ✓ Supabase database is healthy"
|
||||
break
|
||||
fi
|
||||
echo " Waiting for database... ($WAIT_COUNT/$MAX_WAIT seconds)"
|
||||
sleep 2
|
||||
WAIT_COUNT=$((WAIT_COUNT + 2))
|
||||
done
|
||||
|
||||
if [ $WAIT_COUNT -ge $MAX_WAIT ]; then
|
||||
echo " ⚠ Warning: Database may not be fully ready"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "6. Waiting for Supabase migrations to complete..."
|
||||
# Wait for migration container to complete (it has restart: "no", so it should exit when done)
|
||||
MAX_WAIT=120
|
||||
WAIT_COUNT=0
|
||||
MIGRATE_CONTAINER="usda-vision-supabase-migrate"
|
||||
|
||||
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
|
||||
# Check if container exists and its status
|
||||
if docker ps -a --format "{{.Names}}\t{{.Status}}" | grep -q "^${MIGRATE_CONTAINER}"; then
|
||||
CONTAINER_STATUS=$(docker ps -a --format "{{.Names}}\t{{.Status}}" | grep "^${MIGRATE_CONTAINER}" | awk '{print $2}')
|
||||
|
||||
if echo "$CONTAINER_STATUS" | grep -q "Exited"; then
|
||||
EXIT_CODE=$(docker inspect "$MIGRATE_CONTAINER" --format='{{.State.ExitCode}}' 2>/dev/null || echo "1")
|
||||
if [ "$EXIT_CODE" = "0" ]; then
|
||||
echo " ✓ Supabase migrations completed successfully"
|
||||
break
|
||||
else
|
||||
echo " ⚠ Warning: Migrations may have failed (exit code: $EXIT_CODE)"
|
||||
echo " Check logs with: docker compose logs supabase-migrate"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo " Waiting for migrations... ($WAIT_COUNT/$MAX_WAIT seconds)"
|
||||
sleep 2
|
||||
WAIT_COUNT=$((WAIT_COUNT + 2))
|
||||
done
|
||||
|
||||
if [ $WAIT_COUNT -ge $MAX_WAIT ]; then
|
||||
echo " ⚠ Warning: Migration timeout - check logs with: docker compose logs supabase-migrate"
|
||||
echo " Note: Migrations may still be running or the container may not have started yet"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "7. Checking service status..."
|
||||
docker compose ps
|
||||
echo ""
|
||||
|
||||
echo "=== Docker Compose Reset Complete ==="
|
||||
echo ""
|
||||
echo "All services have been reset and are running in detached mode."
|
||||
echo "Use 'docker compose logs -f' to view logs or 'docker compose ps' to check status."
|
||||
echo ""
|
||||
echo "Useful commands:"
|
||||
echo " - View all logs: docker compose logs -f"
|
||||
echo " - View Supabase logs: docker compose logs -f supabase-db supabase-rest supabase-auth"
|
||||
echo " - View migration logs: docker compose logs supabase-migrate"
|
||||
echo " - Check service status: docker compose ps"
|
||||
echo " - Access Supabase Studio: http://localhost:54323"
|
||||
echo ""
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user