feat: add complete Docker setup for testing

- Update docker-compose.yml with frontend service and healthchecks

- Add frontend Dockerfile with dev and production stages

- Add nginx.conf for production frontend serving

- Add docker-compose.prod.yml for production deployment

- Add .env.example with all configuration options

- Add init scripts (init.sh, init.ps1) for easy setup
This commit is contained in:
2026-02-06 16:33:22 +01:00
parent 174919da4e
commit ce46314afb
7 changed files with 543 additions and 8 deletions

132
scripts/init.ps1 Normal file
View File

@@ -0,0 +1,132 @@
# =============================================================================
# Aegis Initialization Script (PowerShell)
# =============================================================================
# This script initializes the Aegis platform after starting Docker containers.
#
# Usage:
# .\scripts\init.ps1
# =============================================================================
$ErrorActionPreference = "Stop"
Write-Host "╔═══════════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ Aegis - Platform Initialization ║" -ForegroundColor Cyan
Write-Host "╚═══════════════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
function Write-Status {
param([string]$Message)
Write-Host "[✓] $Message" -ForegroundColor Green
}
function Write-Warning {
param([string]$Message)
Write-Host "[!] $Message" -ForegroundColor Yellow
}
function Write-Error {
param([string]$Message)
Write-Host "[✗] $Message" -ForegroundColor Red
}
# Check if Docker is running
try {
docker info | Out-Null
} catch {
Write-Error "Docker is not running. Please start Docker first."
exit 1
}
# Check if containers are running
$backendRunning = docker-compose ps | Select-String "aegis-backend"
if (-not $backendRunning) {
Write-Warning "Containers not running. Starting them now..."
docker-compose up -d
Write-Host ""
Write-Host "Waiting for services to be healthy..."
Start-Sleep -Seconds 10
}
# Wait for backend to be ready
Write-Host "Waiting for backend to be ready..."
$maxRetries = 30
$retryCount = 0
$ready = $false
while (-not $ready -and $retryCount -lt $maxRetries) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 2
if ($response.StatusCode -eq 200) {
$ready = $true
}
} catch {
$retryCount++
Write-Host " Waiting... ($retryCount/$maxRetries)"
Start-Sleep -Seconds 2
}
}
if (-not $ready) {
Write-Error "Backend failed to start after $maxRetries attempts"
exit 1
}
Write-Status "Backend is healthy"
# Run database migrations
Write-Host ""
Write-Host "Running database migrations..."
docker-compose exec -T backend alembic upgrade head
Write-Status "Migrations completed"
# Seed admin user
Write-Host ""
Write-Host "Seeding admin user..."
try {
docker-compose exec -T backend python -m app.seed 2>$null
Write-Status "Admin user ready"
} catch {
Write-Warning "Admin user may already exist"
}
# Ask about MITRE sync
Write-Host ""
$runSync = Read-Host "Do you want to run initial MITRE ATT&CK sync? (y/N)"
if ($runSync -eq "y" -or $runSync -eq "Y") {
Write-Host "Triggering MITRE sync (this may take a minute)..."
try {
# Get admin token
$loginBody = "username=admin&password=admin123"
$loginResponse = Invoke-RestMethod -Uri "http://localhost:8000/api/v1/auth/login" `
-Method Post -Body $loginBody -ContentType "application/x-www-form-urlencoded"
$token = $loginResponse.access_token
if ($token) {
$headers = @{ "Authorization" = "Bearer $token" }
Invoke-RestMethod -Uri "http://localhost:8000/api/v1/system/sync-mitre" `
-Method Post -Headers $headers | Out-Null
Write-Status "MITRE sync triggered"
}
} catch {
Write-Warning "Could not authenticate. Run sync manually from the System page."
}
}
# Print summary
Write-Host ""
Write-Host "╔═══════════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ Aegis is ready! ║" -ForegroundColor Cyan
Write-Host "╠═══════════════════════════════════════════════════════════════════════╣" -ForegroundColor Cyan
Write-Host "║ ║" -ForegroundColor Cyan
Write-Host "║ Frontend: http://localhost:5173 ║" -ForegroundColor White
Write-Host "║ Backend API: http://localhost:8000 ║" -ForegroundColor White
Write-Host "║ Swagger UI: http://localhost:8000/docs ║" -ForegroundColor White
Write-Host "║ MinIO Console: http://localhost:9001 ║" -ForegroundColor White
Write-Host "║ ║" -ForegroundColor Cyan
Write-Host "║ Default login: admin / admin123 ║" -ForegroundColor Yellow
Write-Host "║ ║" -ForegroundColor Cyan
Write-Host "║ ⚠️ Change the default password in production! ║" -ForegroundColor Yellow
Write-Host "║ ║" -ForegroundColor Cyan
Write-Host "╚═══════════════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""

114
scripts/init.sh Normal file
View File

@@ -0,0 +1,114 @@
#!/bin/bash
# =============================================================================
# Aegis Initialization Script
# =============================================================================
# This script initializes the Aegis platform after starting Docker containers.
#
# Usage:
# ./scripts/init.sh
# =============================================================================
set -e
echo "╔═══════════════════════════════════════════════════════════════════════╗"
echo "║ Aegis - Platform Initialization ║"
echo "╚═══════════════════════════════════════════════════════════════════════╝"
echo ""
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to print status
print_status() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_error() {
echo -e "${RED}[✗]${NC} $1"
}
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
print_error "Docker is not running. Please start Docker first."
exit 1
fi
# Check if containers are running
if ! docker-compose ps | grep -q "aegis-backend"; then
print_warning "Containers not running. Starting them now..."
docker-compose up -d
echo ""
echo "Waiting for services to be healthy..."
sleep 10
fi
# Wait for backend to be ready
echo "Waiting for backend to be ready..."
MAX_RETRIES=30
RETRY_COUNT=0
until curl -s http://localhost:8000/health > /dev/null 2>&1; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
print_error "Backend failed to start after $MAX_RETRIES attempts"
exit 1
fi
echo " Waiting... ($RETRY_COUNT/$MAX_RETRIES)"
sleep 2
done
print_status "Backend is healthy"
# Run database migrations
echo ""
echo "Running database migrations..."
docker-compose exec -T backend alembic upgrade head
print_status "Migrations completed"
# Seed admin user
echo ""
echo "Seeding admin user..."
docker-compose exec -T backend python -m app.seed 2>/dev/null || print_warning "Admin user may already exist"
print_status "Admin user ready"
# Trigger initial MITRE sync (optional)
echo ""
read -p "Do you want to run initial MITRE ATT&CK sync? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Triggering MITRE sync (this may take a minute)..."
# Get admin token
TOKEN=$(curl -s -X POST "http://localhost:8000/api/v1/auth/login" \
-d "username=admin&password=admin123" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4)
if [ -n "$TOKEN" ]; then
curl -s -X POST "http://localhost:8000/api/v1/system/sync-mitre" \
-H "Authorization: Bearer $TOKEN" > /dev/null
print_status "MITRE sync triggered"
else
print_warning "Could not authenticate. Run sync manually from the System page."
fi
fi
# Print summary
echo ""
echo "╔═══════════════════════════════════════════════════════════════════════╗"
echo "║ Aegis is ready! ║"
echo "╠═══════════════════════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ Frontend: http://localhost:5173 ║"
echo "║ Backend API: http://localhost:8000 ║"
echo "║ Swagger UI: http://localhost:8000/docs ║"
echo "║ MinIO Console: http://localhost:9001 ║"
echo "║ ║"
echo "║ Default login: admin / admin123 ║"
echo "║ ║"
echo "║ ⚠️ Change the default password in production! ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════════════════╝"
echo ""