chore: improve DX scripts, fix test suite, and harden tooling
All checks were successful
Deploy to Production / test (push) Successful in 32s
All checks were successful
Deploy to Production / test (push) Successful in 32s
Scripts: - remote.sh: remove unused open_browser() function - deploy-remote.sh: add DB backup before deploy, --skip-backup flag, step numbering - db-backup.sh: fix macOS compat (xargs -r is GNU-only), use portable approach - db-restore.sh: add safety backup before restore, SQL file validation, file size display - logs.sh: default to no-follow with --tail=100, order-independent arg parsing - docker-cleanup.sh: add Docker health check, colored output - test-sequential.sh: exclude *.integration.test.ts by default, add --integration flag - simulate-ci.sh: pass --integration flag (has real DB) Tests: - db.test.ts: fix mock path from ./DrizzleClient to @shared/db/DrizzleClient - server.settings.test.ts: rewrite mocks for gameSettingsService (old config/saveConfig removed) - server.test.ts: add missing config.lootdrop and BotClient mocks, complete DrizzleClient chain - indexes.test.ts: rename to indexes.integration.test.ts (requires live DB) Config: - package.json: test script uses sequential runner, add test:ci and db:restore aliases - deploy.yml: use --integration flag in CI (has Postgres service)
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
# =============================================================================
|
||||
# Aurora Database Backup Script
|
||||
# =============================================================================
|
||||
# Creates a timestamped PostgreSQL backup and retains the last 10 backups.
|
||||
#
|
||||
# Usage: ./db-backup.sh
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
@@ -37,9 +41,13 @@ if docker ps | grep -q aurora_db; then
|
||||
echo -e " 📂 File: $BACKUP_FILE"
|
||||
echo -e " 📏 Size: $(du -h "$BACKUP_FILE" | cut -f1)"
|
||||
|
||||
# Keep only last 10 backups
|
||||
# Keep only last 10 backups (cross-platform: works on macOS and Linux)
|
||||
cd "$BACKUP_DIR"
|
||||
ls -t backup_*.sql | tail -n +11 | xargs -r rm --
|
||||
OLD_BACKUPS=$(ls -t backup_*.sql 2>/dev/null | tail -n +11)
|
||||
if [ -n "$OLD_BACKUPS" ]; then
|
||||
echo "$OLD_BACKUPS" | xargs rm --
|
||||
echo -e " ${GREEN}✓${NC} Pruned old backups"
|
||||
fi
|
||||
else
|
||||
echo -e " ${RED}✗${NC} Backup created but empty. Something went wrong."
|
||||
rm -f "$BACKUP_FILE"
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
# =============================================================================
|
||||
# Aurora Database Restore Script
|
||||
# =============================================================================
|
||||
# Usage: ./db-restore.sh [path/to/backup.sql]
|
||||
# Restores the database from a SQL backup file.
|
||||
# Automatically creates a safety backup before overwriting.
|
||||
#
|
||||
# Usage: ./db-restore.sh <path-to-backup.sql>
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
@@ -14,6 +17,8 @@ if [ -f .env ]; then
|
||||
set +a
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
@@ -23,6 +28,7 @@ NC='\033[0m'
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "${RED}Error: Please specify the backup file to restore.${NC}"
|
||||
echo "Usage: ./db-restore.sh <path-to-sql-file>"
|
||||
echo ""
|
||||
echo "Available backups:"
|
||||
ls -lh shared/db/backups/*.sql 2>/dev/null || echo " (No backups found in shared/db/backups)"
|
||||
exit 1
|
||||
@@ -35,29 +41,42 @@ if [ ! -f "$BACKUP_FILE" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate the backup file looks like SQL
|
||||
if ! head -1 "$BACKUP_FILE" | grep -qiE '(^--|^SET|^CREATE|^INSERT|^\\\\connect|^pg_dump)'; then
|
||||
echo -e "${YELLOW}⚠️ Warning: File does not appear to be a SQL dump.${NC}"
|
||||
read -p "Continue anyway? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Operation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}⚠️ WARNING: This will OVERWRITE the current database!${NC}"
|
||||
echo -e "Target Database: ${DB_NAME:-auroradev}"
|
||||
echo -e "Backup File: $BACKUP_FILE"
|
||||
echo -e "Backup File: $BACKUP_FILE"
|
||||
echo -e "File Size: $(du -h "$BACKUP_FILE" | cut -f1)"
|
||||
echo ""
|
||||
read -p "Are you sure you want to proceed? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo -e "${YELLOW}♻️ Restoring database...${NC}"
|
||||
|
||||
if docker ps | grep -q aurora_db; then
|
||||
# Drop and recreate public schema to ensure clean slate, then restore
|
||||
# Note: dependent on how the dump was created. Standard pg_dump usually includes CREATE commands if configured,
|
||||
# but often it's data only or structure+data.
|
||||
# For safety, we'll just pipe the file to psql.
|
||||
|
||||
cat "$BACKUP_FILE" | docker exec -i aurora_db psql -U "${DB_USER:-auroradev}" -d "${DB_NAME:-auroradev}"
|
||||
|
||||
echo -e " ${GREEN}✓${NC} Restore complete!"
|
||||
else
|
||||
echo -e "${RED}Error: Database container (aurora_db) is not running!${NC}"
|
||||
exit 1
|
||||
if ! docker ps | grep -q aurora_db; then
|
||||
echo -e "${RED}Error: Database container (aurora_db) is not running!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a safety backup before restoring
|
||||
echo -e "${YELLOW}💾 Creating safety backup before restore...${NC}"
|
||||
bash "$SCRIPT_DIR/db-backup.sh" || {
|
||||
echo -e "${RED}⚠️ Safety backup failed. Aborting restore.${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo -e "${YELLOW}♻️ Restoring database...${NC}"
|
||||
cat "$BACKUP_FILE" | docker exec -i aurora_db psql -U "${DB_USER:-auroradev}" -d "${DB_NAME:-auroradev}"
|
||||
|
||||
echo -e " ${GREEN}✓${NC} Restore complete!"
|
||||
else
|
||||
echo "Operation cancelled."
|
||||
exit 0
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Aurora Remote Deployment Script
|
||||
# =============================================================================
|
||||
# Deploys the application to a remote VPS via SSH.
|
||||
# Performs a database backup, pulls latest code, builds, and restarts services.
|
||||
#
|
||||
# Usage: ./deploy-remote.sh [--skip-backup]
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Load environment variables
|
||||
@@ -8,8 +17,14 @@ if [ -f .env ]; then
|
||||
set +a
|
||||
fi
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
if [ -z "$VPS_HOST" ] || [ -z "$VPS_USER" ]; then
|
||||
echo "Error: VPS_HOST and VPS_USER must be set in .env"
|
||||
echo -e "${RED}Error: VPS_HOST and VPS_USER must be set in .env${NC}"
|
||||
echo "Please add them to your .env file:"
|
||||
echo "VPS_USER=your-username"
|
||||
echo "VPS_HOST=your-ip-address"
|
||||
@@ -18,15 +33,36 @@ fi
|
||||
|
||||
# Default remote directory to ~/Aurora if not specified
|
||||
REMOTE_DIR="${VPS_PROJECT_PATH:-~/Aurora}"
|
||||
SKIP_BACKUP=false
|
||||
|
||||
echo -e "\033[1;33m🚀 Deploying to $VPS_USER@$VPS_HOST:$REMOTE_DIR...\033[0m"
|
||||
if [[ "$1" == "--skip-backup" ]]; then
|
||||
SKIP_BACKUP=true
|
||||
fi
|
||||
|
||||
# Execute commands on remote server
|
||||
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && \
|
||||
echo '⬇️ Pulling latest changes...' && \
|
||||
git pull && \
|
||||
echo '🏗️ Building production containers...' && \
|
||||
docker compose -f docker-compose.prod.yml build && \
|
||||
echo '🚀 Starting services...' && \
|
||||
docker compose -f docker-compose.prod.yml up -d && \
|
||||
echo '✅ Deployment complete!'"
|
||||
echo -e "${YELLOW}🚀 Deploying to $VPS_USER@$VPS_HOST:$REMOTE_DIR...${NC}"
|
||||
|
||||
# Step 1: Database backup (unless skipped)
|
||||
if [ "$SKIP_BACKUP" = false ]; then
|
||||
echo -e "\n${YELLOW}💾 Step 1/4: Backing up remote database...${NC}"
|
||||
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && bash shared/scripts/db-backup.sh" || {
|
||||
echo -e "${RED}⚠️ Backup failed. Aborting deployment.${NC}"
|
||||
echo "Use --skip-backup to deploy without backing up."
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
echo -e "\n${YELLOW}⏭️ Step 1/4: Skipping database backup (--skip-backup)${NC}"
|
||||
fi
|
||||
|
||||
# Step 2: Pull latest code
|
||||
echo -e "\n${YELLOW}⬇️ Step 2/4: Pulling latest changes...${NC}"
|
||||
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && git pull"
|
||||
|
||||
# Step 3: Build production containers
|
||||
echo -e "\n${YELLOW}🏗️ Step 3/4: Building production containers...${NC}"
|
||||
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && docker compose -f docker-compose.prod.yml build"
|
||||
|
||||
# Step 4: Restart services
|
||||
echo -e "\n${YELLOW}🚀 Step 4/4: Starting services...${NC}"
|
||||
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && docker compose -f docker-compose.prod.yml up -d"
|
||||
|
||||
echo -e "\n${GREEN}✅ Deployment complete!${NC}"
|
||||
|
||||
0
shared/scripts/deploy.sh
Normal file → Executable file
0
shared/scripts/deploy.sh
Normal file → Executable file
@@ -1,14 +1,31 @@
|
||||
#!/bin/bash
|
||||
# Cleanup script for Docker resources
|
||||
# Use: ./shared/scripts/docker-cleanup.sh
|
||||
# Use: ./shared/scripts/docker-cleanup.sh --full (for aggressive cleanup)
|
||||
# =============================================================================
|
||||
# Aurora Docker Cleanup Script
|
||||
# =============================================================================
|
||||
# Cleans up Docker resources to free disk space.
|
||||
#
|
||||
# Usage: ./docker-cleanup.sh (interactive mode)
|
||||
# ./docker-cleanup.sh --full (automatic full cleanup)
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
echo "🧹 Aurora Docker Cleanup"
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo -e "${YELLOW}🧹 Aurora Docker Cleanup${NC}"
|
||||
echo "========================"
|
||||
echo ""
|
||||
|
||||
# Verify Docker is running
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
echo -e "${RED}Error: Docker is not running.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show current disk usage first
|
||||
echo "📊 Current Docker disk usage:"
|
||||
docker system df
|
||||
@@ -26,7 +43,7 @@ docker image prune -f
|
||||
# Check for --full flag for aggressive cleanup
|
||||
if [[ "$1" == "--full" ]]; then
|
||||
echo ""
|
||||
echo "🔥 Full cleanup mode - removing all unused Docker resources..."
|
||||
echo -e "${YELLOW}🔥 Full cleanup mode - removing all unused Docker resources...${NC}"
|
||||
|
||||
# Remove all unused images, not just dangling ones
|
||||
echo " → Removing unused images..."
|
||||
@@ -49,7 +66,7 @@ if [[ "$1" == "--full" ]]; then
|
||||
docker volume rm aurora_app_node_modules aurora_web_node_modules 2>/dev/null || true
|
||||
|
||||
echo ""
|
||||
echo "✅ Full cleanup complete!"
|
||||
echo -e "${GREEN}✅ Full cleanup complete!${NC}"
|
||||
else
|
||||
# Interactive mode
|
||||
echo ""
|
||||
@@ -57,7 +74,7 @@ else
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
docker builder prune -f
|
||||
echo "✓ Build cache cleared"
|
||||
echo -e "${GREEN}✓${NC} Build cache cleared"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -65,7 +82,7 @@ else
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
docker image prune -a -f
|
||||
echo "✓ Unused images removed"
|
||||
echo -e "${GREEN}✓${NC} Unused images removed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -73,7 +90,7 @@ else
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
docker volume rm aurora_app_node_modules aurora_web_node_modules 2>/dev/null || true
|
||||
echo "✓ Node modules volumes removed"
|
||||
echo -e "${GREEN}✓${NC} Node modules volumes removed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -81,11 +98,11 @@ else
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
docker system prune -a -f --volumes
|
||||
echo "✓ Full system prune complete"
|
||||
echo -e "${GREEN}✓${NC} Full system prune complete"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✅ Cleanup complete!"
|
||||
echo -e "${GREEN}✅ Cleanup complete!${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
@@ -2,37 +2,53 @@
|
||||
# =============================================================================
|
||||
# Aurora Log Viewer
|
||||
# =============================================================================
|
||||
# Usage: ./logs.sh [app|db|all] [-f]
|
||||
# Default: app container, follow mode
|
||||
# Usage: ./logs.sh [app|db|all] [-f|--follow]
|
||||
# Default: app container, no follow (shows last 100 lines)
|
||||
#
|
||||
# Examples:
|
||||
# ./logs.sh # Last 100 lines of app logs
|
||||
# ./logs.sh -f # Follow app logs in real-time
|
||||
# ./logs.sh db -f # Follow db logs in real-time
|
||||
# ./logs.sh all # Last 100 lines of all logs
|
||||
# =============================================================================
|
||||
|
||||
SERVICE=${1:-app}
|
||||
FOLLOW="-f"
|
||||
SERVICE="app"
|
||||
FOLLOW=""
|
||||
TAIL_LINES="--tail=100"
|
||||
|
||||
if [[ "$1" == "-f" ]]; then
|
||||
SERVICE="app"
|
||||
FOLLOW="-f"
|
||||
elif [[ "$2" == "-f" ]]; then
|
||||
FOLLOW="-f"
|
||||
elif [[ "$2" == "--no-follow" ]]; then
|
||||
FOLLOW=""
|
||||
fi
|
||||
# Parse arguments (order-independent)
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
-f|--follow)
|
||||
FOLLOW="-f"
|
||||
TAIL_LINES="" # When following, start from current output
|
||||
;;
|
||||
app|db|all)
|
||||
SERVICE="$arg"
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option: $arg"
|
||||
echo "Usage: ./logs.sh [app|db|all] [-f|--follow]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "📋 Fetching logs for service: $SERVICE..."
|
||||
|
||||
case $SERVICE in
|
||||
app)
|
||||
docker compose logs $FOLLOW app
|
||||
docker compose logs $FOLLOW $TAIL_LINES app
|
||||
;;
|
||||
db)
|
||||
docker compose logs $FOLLOW db
|
||||
docker compose logs $FOLLOW $TAIL_LINES db
|
||||
;;
|
||||
all)
|
||||
docker compose logs $FOLLOW
|
||||
docker compose logs $FOLLOW $TAIL_LINES
|
||||
;;
|
||||
*)
|
||||
echo "Unknown service: $SERVICE"
|
||||
echo "Usage: ./logs.sh [app|db|all] [-f]"
|
||||
echo "Usage: ./logs.sh [app|db|all] [-f|--follow]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =============================================================================
|
||||
# Aurora Remote Tunnel Script
|
||||
# =============================================================================
|
||||
# Establishes secure SSH tunnels to remote Aurora services.
|
||||
# Uses autossh for automatic reconnection if available.
|
||||
#
|
||||
# Usage: ./remote.sh
|
||||
# =============================================================================
|
||||
|
||||
# Load environment variables
|
||||
if [ -f .env ]; then
|
||||
set -a
|
||||
@@ -26,21 +35,6 @@ echo ""
|
||||
echo "Press Ctrl+C to stop all connections."
|
||||
echo ""
|
||||
|
||||
# Function to open browser (cross-platform)
|
||||
open_browser() {
|
||||
sleep 2 # Wait for tunnel to establish
|
||||
if command -v open &> /dev/null; then
|
||||
# macOS
|
||||
open "http://localhost:$DASHBOARD_PORT"
|
||||
elif command -v xdg-open &> /dev/null; then
|
||||
# Linux
|
||||
xdg-open "http://localhost:$DASHBOARD_PORT"
|
||||
elif command -v start &> /dev/null; then
|
||||
# Windows (Git Bash)
|
||||
start "http://localhost:$DASHBOARD_PORT"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if autossh is available for auto-reconnection
|
||||
if command -v autossh &> /dev/null; then
|
||||
echo "✅ Using autossh for automatic reconnection"
|
||||
|
||||
0
shared/scripts/setup-server.sh
Normal file → Executable file
0
shared/scripts/setup-server.sh
Normal file → Executable file
@@ -92,7 +92,7 @@ if [ -n "$1" ]; then
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
else
|
||||
if bash shared/scripts/test-sequential.sh; then
|
||||
if bash shared/scripts/test-sequential.sh --integration; then
|
||||
echo "✅ CI Simulation Passed!"
|
||||
EXIT_CODE=0
|
||||
else
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INCLUDE_INTEGRATION=false
|
||||
if [[ "$1" == "--integration" ]]; then
|
||||
INCLUDE_INTEGRATION=true
|
||||
fi
|
||||
|
||||
echo "🔍 Finding test files..."
|
||||
TEST_FILES=$(find . -name "*.test.ts" -not -path "*/node_modules/*")
|
||||
if [ "$INCLUDE_INTEGRATION" = true ]; then
|
||||
TEST_FILES=$(find . -name "*.test.ts" -not -path "*/node_modules/*")
|
||||
else
|
||||
TEST_FILES=$(find . -name "*.test.ts" -not -name "*.integration.test.ts" -not -path "*/node_modules/*")
|
||||
fi
|
||||
|
||||
if [ -z "$TEST_FILES" ]; then
|
||||
echo "⚠️ No test files found!"
|
||||
@@ -10,6 +19,10 @@ if [ -z "$TEST_FILES" ]; then
|
||||
fi
|
||||
|
||||
echo "🧪 Running tests sequentially..."
|
||||
if [ "$INCLUDE_INTEGRATION" = true ]; then
|
||||
echo " (including integration tests)"
|
||||
fi
|
||||
|
||||
FAILED=0
|
||||
|
||||
for FILE in $TEST_FILES; do
|
||||
|
||||
Reference in New Issue
Block a user