updated deploy scripts and locations

This commit is contained in:
buenosairesam
2025-12-31 08:21:07 -03:00
parent 9e9e0a5a25
commit fc63e9010c
33 changed files with 160283 additions and 758 deletions

33
cfg/amar/ctrl/logs.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
# View amar room logs
#
# Usage:
# ./logs.sh # All logs (tail)
# ./logs.sh -f # Follow mode
# ./logs.sh backend # Specific container
# ./logs.sh soleprint # Soleprint logs
set -e
cd "$(dirname "$0")/.."
FOLLOW=""
TARGET=""
for arg in "$@"; do
case $arg in
-f|--follow) FOLLOW="-f" ;;
*) TARGET="$arg" ;;
esac
done
if [ -z "$TARGET" ]; then
echo "=== Amar ==="
docker compose logs --tail=20 $FOLLOW
echo ""
echo "=== Soleprint ==="
(cd soleprint && docker compose logs --tail=20 $FOLLOW)
elif [ "$TARGET" = "soleprint" ]; then
(cd soleprint && docker compose logs $FOLLOW)
else
docker logs $FOLLOW "amar_$TARGET" 2>/dev/null || docker logs $FOLLOW "$TARGET"
fi

40
cfg/amar/ctrl/start.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
# Start amar room (managed app + soleprint)
#
# Usage:
# ./start.sh # Start all (foreground)
# ./start.sh -d # Start all (detached)
# ./start.sh amar # Start only amar
# ./start.sh soleprint # Start only soleprint
# ./start.sh --build # Rebuild images
set -e
cd "$(dirname "$0")/.."
BUILD=""
DETACH=""
TARGET="all"
for arg in "$@"; do
case $arg in
-d|--detached) DETACH="-d" ;;
--build) BUILD="--build" ;;
amar) TARGET="amar" ;;
soleprint) TARGET="soleprint" ;;
esac
done
if [ "$TARGET" = "all" ] || [ "$TARGET" = "amar" ]; then
echo "Starting amar..."
docker compose up $DETACH $BUILD
fi
if [ "$TARGET" = "all" ] || [ "$TARGET" = "soleprint" ]; then
echo "Starting soleprint..."
(cd soleprint && docker compose up $DETACH $BUILD)
fi
if [ -n "$DETACH" ]; then
echo ""
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "(amar|soleprint|NAMES)"
fi

7
cfg/amar/ctrl/status.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
# Show amar room status
cd "$(dirname "$0")/.."
echo "=== Containers ==="
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "(amar|soleprint|NAMES)" || echo "No containers running"

25
cfg/amar/ctrl/stop.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Stop amar room (managed app + soleprint)
#
# Usage:
# ./stop.sh # Stop all
# ./stop.sh amar # Stop only amar
# ./stop.sh soleprint # Stop only soleprint
set -e
cd "$(dirname "$0")/.."
TARGET="all"
[ -n "$1" ] && TARGET="$1"
if [ "$TARGET" = "all" ] || [ "$TARGET" = "soleprint" ]; then
echo "Stopping soleprint..."
(cd soleprint && docker compose down)
fi
if [ "$TARGET" = "all" ] || [ "$TARGET" = "amar" ]; then
echo "Stopping amar..."
docker compose down
fi
echo "Done."

117
cfg/amar/ctrl/xtras/reload-db.sh Executable file
View File

@@ -0,0 +1,117 @@
#!/bin/bash
# Smart database reload - only swaps if DB_DUMP changed
#
# Tracks which dump is currently loaded and only reloads if different.
# Edit DB_DUMP in .env and run this script - it handles the rest.
#
# Usage:
# ./reload-db.sh # Reload if DB_DUMP changed
# ./reload-db.sh --force # Force reload even if same
set -e
cd "$(dirname "$0")/../.."
FORCE=false
if [ "$1" = "--force" ]; then
FORCE=true
fi
# Get config from .env
DEPLOYMENT_NAME=$(grep "^DEPLOYMENT_NAME=" .env 2>/dev/null | cut -d'=' -f2 || echo "amar")
POSTGRES_DB=$(grep "^POSTGRES_DB=" .env 2>/dev/null | cut -d'=' -f2 || echo "amarback")
POSTGRES_USER=$(grep "^POSTGRES_USER=" .env 2>/dev/null | cut -d'=' -f2 || echo "postgres")
DB_DUMP=$(grep "^DB_DUMP=" .env 2>/dev/null | cut -d'=' -f2)
if [ -z "$DB_DUMP" ]; then
echo "Error: DB_DUMP not set in .env"
echo ""
echo "Add to .env:"
echo " DB_DUMP=dev.sql"
echo ""
echo "Available dumps:"
ls -1 dumps/*.sql 2>/dev/null | sed 's/dumps\// /' || echo " No dumps found in dumps/"
exit 1
fi
DUMP_FILE="dumps/${DB_DUMP}"
if [ ! -f "$DUMP_FILE" ]; then
echo "Error: Dump file not found: $DUMP_FILE"
echo ""
echo "Available dumps:"
ls -1 dumps/*.sql 2>/dev/null | sed 's/dumps\// /' || echo " No dumps found in dumps/"
exit 1
fi
DB_CONTAINER="${DEPLOYMENT_NAME}_db"
BACKEND_CONTAINER="${DEPLOYMENT_NAME}_backend"
STATE_FILE=".db_state"
# Check if db container is running
if ! docker ps --format "{{.Names}}" | grep -q "^${DB_CONTAINER}$"; then
echo "Error: Database container not running: $DB_CONTAINER"
echo "Start services first with: ./ctrl/start.sh -d"
exit 1
fi
# Check current state
if [ -f "$STATE_FILE" ] && [ "$FORCE" = false ]; then
CURRENT_DUMP=$(cat "$STATE_FILE")
if [ "$CURRENT_DUMP" = "$DB_DUMP" ]; then
echo "Database already loaded with: $DB_DUMP"
echo "Use --force to reload anyway"
exit 0
fi
echo "Database dump changed: $CURRENT_DUMP$DB_DUMP"
else
if [ "$FORCE" = true ]; then
echo "Force reloading database with: $DB_DUMP"
else
echo "Loading database with: $DB_DUMP"
fi
fi
echo ""
read -p "Continue with database reload? (y/N) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cancelled."
exit 0
fi
echo ""
echo "[1/5] Stopping backend and celery services..."
docker compose stop backend celery celery-beat 2>/dev/null || true
echo ""
echo "[2/5] Dropping and recreating database..."
docker exec "$DB_CONTAINER" psql -U "$POSTGRES_USER" -d postgres -c "DROP DATABASE IF EXISTS $POSTGRES_DB WITH (FORCE);"
docker exec "$DB_CONTAINER" psql -U "$POSTGRES_USER" -d postgres -c "CREATE DATABASE $POSTGRES_DB;"
docker exec "$DB_CONTAINER" psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION IF NOT EXISTS postgis_topology;"
echo ""
echo "[3/5] Loading dump: $DB_DUMP..."
docker exec -i "$DB_CONTAINER" psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" < "$DUMP_FILE"
echo ""
echo "[4/5] Restarting services and running migrations..."
docker compose start backend celery celery-beat
echo "Waiting for backend to start..."
sleep 3
echo "Running migrations..."
docker exec "$BACKEND_CONTAINER" python manage.py migrate --noinput
echo ""
echo "[5/5] Updating state..."
echo "$DB_DUMP" > "$STATE_FILE"
echo ""
echo "=========================================="
echo " Database Reloaded Successfully"
echo "=========================================="
echo ""
echo "Current dump: $DB_DUMP"
echo "Database: $POSTGRES_DB"
echo ""