chore: 调整脚本与 Docker 配置

This commit is contained in:
2025-12-05 16:35:07 +08:00
parent 7fda0aaeab
commit 0d9244bfc2
2 changed files with 53 additions and 5 deletions

View File

@@ -0,0 +1,47 @@
<#
用法:在 PowerShell 中执行本脚本,自动构建并重启 AdminApi 容器。
如果要放到桌面双击运行,可将本文件复制到桌面后右键“使用 PowerShell 运行”。
前置:已安装并运行 Docker Desktop。
#>
# 遇到异常时停住窗口,方便查看错误
trap {
Write-Host "发生错误:" $_ -ForegroundColor Red
Read-Host "按回车关闭窗口"
exit 1
}
$ErrorActionPreference = 'Stop'
# 1. 基本变量(脚本位于 repo_root/scripts下移一层再上跳到仓库根
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = Split-Path -Parent $scriptDir
$imageName = 'takeout.api.admin:dev'
$containerName = 'takeout.api.admin'
$dockerfilePath = Join-Path $repoRoot 'src/Api/TakeoutSaaS.AdminApi/Dockerfile'
Write-Host "工作目录:$repoRoot"
# 2. 停止并删除旧容器
if ((docker ps -a --format '{{.Names}}') -contains $containerName) {
Write-Host "发现旧容器,正在移除:$containerName"
docker stop $containerName | Out-Null
docker rm $containerName | Out-Null
}
# 3. 删除旧镜像
if ((docker images --format '{{.Repository}}:{{.Tag}}') -contains $imageName) {
Write-Host "发现旧镜像,正在移除:$imageName"
docker rmi $imageName | Out-Null
}
# 4. 构建最新镜像(使用仓库根作为上下文)
Write-Host "开始构建镜像:$imageName"
docker build -f $dockerfilePath -t $imageName $repoRoot
# 5. 运行新容器并映射端口
Write-Host "运行新容器:$containerName (端口映射 7801:7801环境 Development)"
docker run -d --name $containerName -e ASPNETCORE_ENVIRONMENT=Development -p 7801:7801 $imageName
Write-Host "完成。镜像:$imageName,容器:$containerName。Swagger 访问http://localhost:7801/swagger"
Read-Host "按回车关闭窗口"

View File

@@ -12,12 +12,13 @@
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": false,
"launchUrl": "http://localhost:7801/swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"publishAllPorts": false,
"useSSL": false,
"dockerRunOptions": "-p 7801:7801 --name TakeoutAdminApi"
}
}
}
}