# REDCap Docker一键部署脚本 param([switch]$SkipCheck, [switch]$Force) Write-Host "============================================" -ForegroundColor Cyan Write-Host " REDCap Docker环境一键部署脚本" -ForegroundColor Cyan Write-Host "============================================" -ForegroundColor Cyan Write-Host "" $ScriptDir = Split-Path -Parent $PSCommandPath $ProjectDir = Split-Path -Parent $ScriptDir Set-Location $ProjectDir Write-Host "工作目录: $ProjectDir" -ForegroundColor Green Write-Host "" # 步骤 1: 环境检查 if (-not $SkipCheck) { Write-Host "步骤 1/7: 环境检查..." -ForegroundColor Yellow Write-Host " 检查Docker..." -NoNewline $null = docker --version 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host " X" -ForegroundColor Red Write-Host "Docker未安装或未运行!" -ForegroundColor Red exit 1 } Write-Host " OK" -ForegroundColor Green Write-Host " 检查Docker Compose..." -NoNewline $null = docker-compose --version 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host " X" -ForegroundColor Red Write-Host "Docker Compose未安装!" -ForegroundColor Red exit 1 } Write-Host " OK" -ForegroundColor Green Write-Host " 检查REDCap源码..." -NoNewline if (-not (Test-Path "..\redcap15.8.0\redcap\index.php")) { Write-Host " X" -ForegroundColor Red Write-Host "REDCap源码未找到!" -ForegroundColor Red exit 1 } Write-Host " OK" -ForegroundColor Green Write-Host "环境检查通过!" -ForegroundColor Green Write-Host "" } # 步骤 2: 创建.env文件 Write-Host "步骤 2/7: 配置环境变量..." -ForegroundColor Yellow $envExists = Test-Path ".env" if (-not $envExists) { Write-Host " 从模板创建.env文件..." -ForegroundColor Gray $templateExists = Test-Path "env.template" if (-not $templateExists) { Write-Host " 未找到env.template!" -ForegroundColor Red exit 1 } Copy-Item "env.template" ".env" Write-Host " .env文件已创建" -ForegroundColor Green } if ($envExists) { Write-Host " .env文件已存在" -ForegroundColor Green } Write-Host "" # 步骤 3: 检查端口 Write-Host "步骤 3/7: 检查端口占用..." -ForegroundColor Yellow $ports = @(8080, 3306, 8081) $portsInUse = @() foreach ($port in $ports) { $check = netstat -ano | Select-String ":$port " | Select-Object -First 1 if ($check) { Write-Host " 端口 $port 已被占用" -ForegroundColor Yellow $portsInUse += $port continue } Write-Host " 端口 $port 可用" -ForegroundColor Green } if ($portsInUse.Count -gt 0) { Write-Host "" Write-Host "警告: 部分端口被占用!" -ForegroundColor Yellow if (-not $Force) { $continue = Read-Host "是否继续? (Y/N)" if ($continue -ne "Y") { Write-Host "部署已取消" -ForegroundColor Yellow exit 0 } } } Write-Host "" # 步骤 4: 清理旧容器 if ($Force) { Write-Host "步骤 4/7: 清理旧容器..." -ForegroundColor Yellow docker-compose down 2>&1 | Out-Null Write-Host " 旧容器已清理" -ForegroundColor Green Write-Host "" } if (-not $Force) { Write-Host "步骤 4/7: 跳过清理 (使用 -Force 强制清理)" -ForegroundColor Gray Write-Host "" } # 步骤 5: 构建镜像 Write-Host "步骤 5/7: 构建Docker镜像..." -ForegroundColor Yellow Write-Host " 这可能需要几分钟..." -ForegroundColor Gray Write-Host "" docker-compose build if ($LASTEXITCODE -ne 0) { Write-Host "Docker镜像构建失败!" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "Docker镜像构建成功!" -ForegroundColor Green Write-Host "" # 步骤 6: 启动容器 Write-Host "步骤 6/7: 启动容器..." -ForegroundColor Yellow docker-compose up -d if ($LASTEXITCODE -ne 0) { Write-Host "容器启动失败!" -ForegroundColor Red exit 1 } Write-Host "容器启动成功!" -ForegroundColor Green Write-Host "" # 步骤 7: 等待服务就绪 Write-Host "步骤 7/7: 等待服务就绪..." -ForegroundColor Yellow Write-Host " 等待MySQL启动 (30秒)..." -ForegroundColor Gray Start-Sleep -Seconds 30 Write-Host "" Write-Host "容器状态:" -ForegroundColor Cyan docker-compose ps # 部署完成 Write-Host "" Write-Host "============================================" -ForegroundColor Green Write-Host " REDCap Docker环境部署完成!" -ForegroundColor Green Write-Host "============================================" -ForegroundColor Green Write-Host "" Write-Host "服务访问地址:" -ForegroundColor Cyan Write-Host " REDCap: http://localhost:8080" -ForegroundColor White Write-Host " phpMyAdmin: http://localhost:8081" -ForegroundColor White Write-Host "" Write-Host "下一步操作:" -ForegroundColor Cyan Write-Host " 1. 访问 http://localhost:8080/install.php" -ForegroundColor White Write-Host " 2. 数据库配置:" -ForegroundColor White Write-Host " Host: redcap-db" -ForegroundColor Gray Write-Host " Database: redcap" -ForegroundColor Gray Write-Host " User: redcap_user" -ForegroundColor Gray Write-Host " Password: redcap_pass_dev_456" -ForegroundColor Gray Write-Host ""