Files
ColaFlow/scripts/dev-start.ps1
Yaojia Wang 8c0e6e8c23 feat(docker): Add Phase 4 - automated startup scripts and documentation
Implemented one-click development environment startup solution for frontend developers.

Changes:
- Created scripts/dev-start.ps1 (PowerShell startup script for Windows)
  * Docker health checks
  * Service status monitoring
  * Clean/Logs/Stop command options
  * Auto .env creation from .env.example
  * Friendly colored output and progress indicators

- Created scripts/dev-start.sh (Bash startup script for Linux/macOS)
  * Feature parity with PowerShell version
  * Cross-platform compatibility
  * Color-coded status messages

- Updated .env.example with comprehensive configuration
  * Added missing port configurations
  * Added JWT settings (Issuer, Audience)
  * Added SignalR hub URL
  * Improved documentation and organization

- Created README.md (project documentation)
  * Quick start guide for Docker setup
  * Manual development instructions
  * Project structure overview
  * Technology stack details
  * Troubleshooting guide
  * Development workflow

Testing:
- Verified PowerShell script syntax (valid)
- Verified Bash script has executable permissions
- Confirmed all files created successfully
- Docker services running and healthy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 23:50:55 +01:00

176 lines
4.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env pwsh
<#
.SYNOPSIS
ColaFlow 开发环境启动脚本
.DESCRIPTION
一键启动 ColaFlow 开发环境的所有服务PostgreSQL, Redis, Backend, Frontend
.PARAMETER Clean
清理现有容器和数据,重新构建启动
.PARAMETER Logs
显示所有服务的日志
.PARAMETER Stop
停止所有服务
.EXAMPLE
.\dev-start.ps1
启动所有服务
.EXAMPLE
.\dev-start.ps1 -Clean
清理并重新启动
.EXAMPLE
.\dev-start.ps1 -Logs
查看服务日志
#>
param(
[switch]$Clean,
[switch]$Logs,
[switch]$Stop
)
# 颜色输出函数
function Write-ColorOutput($ForegroundColor) {
$fc = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = $ForegroundColor
if ($args) {
Write-Output $args
}
$host.UI.RawUI.ForegroundColor = $fc
}
function Write-Success { Write-ColorOutput Green $args }
function Write-Info { Write-ColorOutput Cyan $args }
function Write-Warning { Write-ColorOutput Yellow $args }
function Write-Error { Write-ColorOutput Red $args }
# 横幅
Write-Info @"
ColaFlow Development Environment
Docker-based Development Stack
"@
# 检查 Docker
Write-Info "🔍 Checking Docker..."
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Error "❌ Docker not found! Please install Docker Desktop."
exit 1
}
if (-not (docker info 2>$null)) {
Write-Error "❌ Docker is not running! Please start Docker Desktop."
exit 1
}
Write-Success "✅ Docker is ready"
# 处理参数
if ($Stop) {
Write-Info "🛑 Stopping all services..."
docker-compose down
Write-Success "✅ All services stopped"
exit 0
}
if ($Logs) {
Write-Info "📋 Showing logs (Ctrl+C to exit)..."
docker-compose logs -f
exit 0
}
if ($Clean) {
Write-Warning "🧹 Cleaning up containers and volumes..."
docker-compose down -v
Write-Info "🔨 Rebuilding images..."
docker-compose build --no-cache
}
# 检查 .env 文件
if (-not (Test-Path ".env")) {
if (Test-Path ".env.example") {
Write-Info "📄 Creating .env from .env.example..."
Copy-Item ".env.example" ".env"
Write-Success "✅ .env file created"
} else {
Write-Warning "⚠️ No .env or .env.example found, using docker-compose defaults"
}
}
# 启动服务
Write-Info "🚀 Starting services..."
docker-compose up -d
# 等待健康检查
Write-Info "⏳ Waiting for services to be healthy..."
$maxWait = 60
$waited = 0
$interval = 2
while ($waited -lt $maxWait) {
$status = docker-compose ps --format json 2>$null
if ($status) {
try {
$services = $status | ConvertFrom-Json
$allHealthy = $true
foreach ($service in $services) {
if ($service.Health -eq "unhealthy") {
$allHealthy = $false
break
}
}
if ($allHealthy) {
break
}
} catch {
# Continue waiting if JSON parsing fails
}
}
Start-Sleep -Seconds $interval
$waited += $interval
Write-Host "." -NoNewline
}
Write-Host ""
# 检查服务状态
Write-Info "`n📊 Service Status:"
docker-compose ps
Write-Success "`n🎉 ColaFlow development environment is ready!"
Write-Info @"
📍 Access Points:
Frontend: http://localhost:3000
Backend: http://localhost:5000
Swagger: http://localhost:5000/scalar/v1
Database: localhost:5432 (colaflow/colaflow_dev_password)
Redis: localhost:6379
👤 Demo Accounts (see scripts/DEMO-ACCOUNTS.md):
Owner: owner@demo.com / Demo@123456
Developer: developer@demo.com / Demo@123456
📝 Useful Commands:
.\scripts\dev-start.ps1 -Stop # Stop all services
.\scripts\dev-start.ps1 -Logs # View logs
.\scripts\dev-start.ps1 -Clean # Clean rebuild
docker-compose ps # Check status
"@