From f3a5edd91d083dd5a9d7ce1e2f70ca1b577fbf35 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Thu, 29 Jan 2026 00:44:25 +0100 Subject: [PATCH] scripts: improve demo reset and production prep --- scripts/demo-reset.ps1 | 23 +++++++++++++++-------- scripts/demo-reset.sh | 24 +++++++++++++++--------- scripts/dev-start.ps1 | 2 +- scripts/dev-start.sh | 2 +- scripts/prepare-production.ps1 | 18 ++++++------------ 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/scripts/demo-reset.ps1 b/scripts/demo-reset.ps1 index 2a5ccee..32d3e09 100644 --- a/scripts/demo-reset.ps1 +++ b/scripts/demo-reset.ps1 @@ -19,16 +19,22 @@ if (-not $Force) { Set-Location "$PSScriptRoot\.." -Write-Host "`n[1/4] Stopping demo containers..." -ForegroundColor Yellow -podman-compose -f compose/demo.yml down +$envFile = "compose/.env.demo" +if (-not (Test-Path $envFile) -and (Test-Path "compose/.env.demo.example")) { + $envFile = "compose/.env.demo.example" +} +$composeArgs = @("-f", "compose/demo.yml") +if (Test-Path $envFile) { + $composeArgs = @("--env-file", $envFile) + $composeArgs +} -Write-Host "`n[2/4] Removing demo database volume..." -ForegroundColor Yellow -podman volume rm likwid_demo_data -f 2>$null +Write-Host "`n[1/3] Stopping demo containers and removing volumes..." -ForegroundColor Yellow +podman-compose @composeArgs down --remove-orphans -v -Write-Host "`n[3/4] Starting fresh demo instance..." -ForegroundColor Yellow -podman-compose -f compose/demo.yml up -d +Write-Host "`n[2/3] Starting fresh demo instance..." -ForegroundColor Yellow +podman-compose @composeArgs up -d -Write-Host "`n[4/4] Waiting for services to be ready..." -ForegroundColor Yellow +Write-Host "`n[3/3] Waiting for services to be ready..." -ForegroundColor Yellow Start-Sleep -Seconds 10 # Check if backend is responding @@ -56,4 +62,5 @@ while ($retry -lt $maxRetries) { } Write-Host "`nWarning: Backend health check timed out. Check logs with:" -ForegroundColor Yellow -Write-Host " podman-compose -f compose/demo.yml logs backend" +$composeArgsText = ($composeArgs -join ' ') +Write-Host " podman-compose $composeArgsText logs backend" diff --git a/scripts/demo-reset.sh b/scripts/demo-reset.sh index b0a7c03..a778bb4 100644 --- a/scripts/demo-reset.sh +++ b/scripts/demo-reset.sh @@ -7,6 +7,14 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR/.." +ENV_FILE="compose/.env.demo" +COMPOSE_ARGS=("-f" "compose/demo.yml") +if [ -f "$ENV_FILE" ]; then + COMPOSE_ARGS=("--env-file" "$ENV_FILE" "-f" "compose/demo.yml") +elif [ -f "compose/.env.demo.example" ]; then + COMPOSE_ARGS=("--env-file" "compose/.env.demo.example" "-f" "compose/demo.yml") +fi + echo "=== Likwid Demo Reset ===" if [ "$1" != "--force" ] && [ "$1" != "-f" ]; then @@ -17,16 +25,13 @@ if [ "$1" != "--force" ] && [ "$1" != "-f" ]; then fi fi -echo -e "\n[1/4] Stopping demo containers..." -podman-compose -f compose/demo.yml down || docker-compose -f compose/demo.yml down +echo -e "\n[1/3] Stopping demo containers and removing volumes..." +podman-compose "${COMPOSE_ARGS[@]}" down --remove-orphans -v || docker-compose "${COMPOSE_ARGS[@]}" down --remove-orphans -v -echo -e "\n[2/4] Removing demo database volume..." -podman volume rm likwid_demo_data -f 2>/dev/null || docker volume rm likwid_demo_data -f 2>/dev/null || true +echo -e "\n[2/3] Starting fresh demo instance..." +podman-compose "${COMPOSE_ARGS[@]}" up -d || docker-compose "${COMPOSE_ARGS[@]}" up -d -echo -e "\n[3/4] Starting fresh demo instance..." -podman-compose -f compose/demo.yml up -d || docker-compose -f compose/demo.yml up -d - -echo -e "\n[4/4] Waiting for services to be ready..." +echo -e "\n[3/3] Waiting for services to be ready..." sleep 5 max_retries=30 @@ -49,4 +54,5 @@ while [ $retry -lt $max_retries ]; do done echo -e "\nWarning: Backend health check timed out. Check logs with:" -echo " podman-compose -f compose/demo.yml logs backend" +echo " podman-compose ${COMPOSE_ARGS[*]} logs backend" +echo " docker-compose ${COMPOSE_ARGS[*]} logs backend" diff --git a/scripts/dev-start.ps1 b/scripts/dev-start.ps1 index 235924f..862c758 100644 --- a/scripts/dev-start.ps1 +++ b/scripts/dev-start.ps1 @@ -73,7 +73,7 @@ $backend = Start-Process -FilePath 'cmd.exe' ` # Start frontend Write-Host "Starting frontend..." $frontend = Start-Process -FilePath 'cmd.exe' ` - -ArgumentList '/c', 'npm', 'run', 'dev', '2>&1' ` + -ArgumentList '/c', "set PUBLIC_API_BASE=http://127.0.0.1:3000&& npm run dev", '2>&1' ` -WorkingDirectory (Join-Path $root 'frontend') ` -PassThru -WindowStyle Hidden ` -RedirectStandardOutput $frontendLog diff --git a/scripts/dev-start.sh b/scripts/dev-start.sh index b8a7a3f..cf24765 100644 --- a/scripts/dev-start.sh +++ b/scripts/dev-start.sh @@ -50,7 +50,7 @@ BACKEND_PID=$! # Start frontend echo "Starting frontend..." cd "$ROOT_DIR/frontend" -npm run dev > "$FRONTEND_LOG" 2>&1 & +PUBLIC_API_BASE="http://127.0.0.1:3000" npm run dev > "$FRONTEND_LOG" 2>&1 & FRONTEND_PID=$! # Save state diff --git a/scripts/prepare-production.ps1 b/scripts/prepare-production.ps1 index fca59dd..f5c0da7 100644 --- a/scripts/prepare-production.ps1 +++ b/scripts/prepare-production.ps1 @@ -7,7 +7,7 @@ Write-Host "=== Preparing Production Build ===" -ForegroundColor Cyan $projectRoot = "$PSScriptRoot\.." $backendDir = "$projectRoot\backend" -$migrationsDir = "$backendDir\migrations" +$migrationsDir = "$backendDir\migrations_demo" $demoMigration = "$migrationsDir\20260127150000_demo_seed_data.sql" # Check if demo migration exists @@ -16,17 +16,11 @@ if (Test-Path $demoMigration) { Write-Host " 1. This file should be EXCLUDED from production deployments" Write-Host " 2. It contains test users and sample data" Write-Host "" - - $action = Read-Host "Remove demo migration for production build? (y/N)" - if ($action -eq "y" -or $action -eq "Y") { - # Backup first - $backupPath = "$demoMigration.backup" - Copy-Item $demoMigration $backupPath - Remove-Item $demoMigration - Write-Host "Demo migration removed (backup at $backupPath)" -ForegroundColor Green - } else { - Write-Host "Keeping demo migration. Remember to remove for production!" -ForegroundColor Yellow - } + + Write-Host "No action required:" -ForegroundColor Green + Write-Host " - The backend only runs migrations_demo when DEMO_MODE=true" + Write-Host " - The production container build excludes demo seed data via INCLUDE_DEMO_SEED=false" + Write-Host " - Keep this file in your working tree for demo/dev" -ForegroundColor Green } else { Write-Host "Demo migration not found - already production ready" -ForegroundColor Green }