99 lines
3.1 KiB
PowerShell
99 lines
3.1 KiB
PowerShell
# PetWash API Docker 部署脚本
|
|
|
|
Write-Host "======================================" -ForegroundColor Cyan
|
|
Write-Host "PetWash API Docker 部署" -ForegroundColor Cyan
|
|
Write-Host "======================================" -ForegroundColor Cyan
|
|
|
|
# 检查 Docker
|
|
Write-Host ""
|
|
Write-Host "[1/6] 检查 Docker..." -ForegroundColor Yellow
|
|
try {
|
|
docker --version | Out-Null
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " Docker 已安装" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " 错误: Docker 未安装" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
} catch {
|
|
Write-Host " 错误: Docker 未安装,请先安装 Docker Desktop" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 检查 Docker Compose
|
|
Write-Host ""
|
|
Write-Host "[2/6] 检查 Docker Compose..." -ForegroundColor Yellow
|
|
try {
|
|
docker-compose --version | Out-Null
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " Docker Compose 已安装" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " 错误: Docker Compose 未安装" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
} catch {
|
|
Write-Host " 错误: Docker Compose 未安装" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 停止旧容器
|
|
Write-Host ""
|
|
Write-Host "[3/6] 停止旧容器..." -ForegroundColor Yellow
|
|
docker-compose down
|
|
Write-Host " 完成" -ForegroundColor Green
|
|
|
|
# 构建镜像
|
|
Write-Host ""
|
|
Write-Host "[4/6] 构建 Docker 镜像..." -ForegroundColor Yellow
|
|
docker-compose build
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " 镜像构建成功" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " 错误: 镜像构建失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 启动容器
|
|
Write-Host ""
|
|
Write-Host "[5/6] 启动容器..." -ForegroundColor Yellow
|
|
docker-compose up -d
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " 容器启动成功" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " 错误: 容器启动失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 等待服务启动
|
|
Write-Host ""
|
|
Write-Host "[6/6] 等待服务启动..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 10
|
|
|
|
# 检查容器状态
|
|
Write-Host ""
|
|
Write-Host "容器状态:" -ForegroundColor Cyan
|
|
docker-compose ps
|
|
|
|
# 查看日志
|
|
Write-Host ""
|
|
Write-Host "======================================" -ForegroundColor Cyan
|
|
Write-Host "最近的日志:" -ForegroundColor Cyan
|
|
Write-Host "======================================" -ForegroundColor Cyan
|
|
docker-compose logs --tail=30 petwash-api
|
|
|
|
# 完成
|
|
Write-Host ""
|
|
Write-Host "======================================" -ForegroundColor Green
|
|
Write-Host "部署完成!" -ForegroundColor Green
|
|
Write-Host "======================================" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "API 地址: http://localhost:5000" -ForegroundColor White
|
|
Write-Host "Swagger 文档: http://localhost:5000/swagger" -ForegroundColor White
|
|
Write-Host ""
|
|
Write-Host "常用命令:" -ForegroundColor Yellow
|
|
Write-Host " 查看实时日志: docker-compose logs -f petwash-api" -ForegroundColor Gray
|
|
Write-Host " 停止服务: docker-compose down" -ForegroundColor Gray
|
|
Write-Host " 重启服务: docker-compose restart" -ForegroundColor Gray
|
|
Write-Host " 查看状态: docker-compose ps" -ForegroundColor Gray
|
|
Write-Host ""
|