Files
AIclinicalresearch/redcap-docker-dev/scripts/setup-redcap.ps1
HaHafeng 38d9bf99d6 feat(redcap): REDCap 15.8.0 Docker本地开发环境部署完成
核心成果:
- REDCap 15.8.0成功部署在Docker环境
- 登录功能正常,管理员账户: Admin/Admin123!
- MySQL 8.0 + PHP 8.1 + Apache 2.4环境验证通过

问题解决:
1. 修复ERR_CONTENT_DECODING_FAILED错误
   - 强制禁用Apache deflate模块
   - PHP配置关闭zlib.output_compression
   - 自动注释REDCap源码中的压缩设置

2. 修复Base URL配置错误
   - 更新redcap_config表中的redcap_base_url
   - 统一DocumentRoot与访问路径

3. 修复登录失败问题(CRLF污染)
   - 删除database.php末尾的PHP结束标签
   - 创建.gitattributes规范换行符
   - 验证REDCap官方源码无此问题

技术改进:
- 添加密码重置工具脚本
- 完善docker-entrypoint.sh启动脚本
- 创建详细的部署问题解决记录
- 建立PHP配置文件最佳实践

部署文档:
- REDCap本地Docker开发环境部署方案
- REDCap生产环境部署决策报告(ECS vs SAE)
- 部署问题解决记录(含根因分析)

下一步:
- Day 2: 开发REDCap API Adapter
- 实现与IIT Manager Agent的数据对接
2026-01-02 10:02:46 +08:00

162 lines
5.1 KiB
PowerShell

# 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 ""