File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ## 背景
2+
3+ * 当前脚本支持 ` -Pull ` 拉取镜像与 ` up -d ` 启动,但没有一个参数同时完成二者。
4+
5+ * 用户需要“一条命令拉取并启动”的便捷入口。
6+
7+ ## 方案选项
8+
9+ * 方案 A(兼容最广):新增 ` -Update ` ,顺序执行 ` pull ` → ` up -d ` (按 ` -ServiceName ` 的 profile)。
10+
11+ * 方案 B(Compose v2 优化):新增 ` -PullAlways ` ,执行 ` up -d --pull always ` ,让 ` up ` 阶段自动拉取最新镜像。
12+
13+ * 无 ` -ServiceName ` 时,默认作用于所有服务;提供 ` -DryRun ` 预览命令。
14+
15+ ## 实现步骤
16+
17+ 1 . 参数扩展:在 ` param() ` 增加 ` [switch]$Update ` 、` [switch]$PullAlways ` ,并更新 Doc 注释示例与 ` .PARAMETER ` 。
18+ 2 . 逻辑分支:
19+
20+ * ` $Update ` 为真:
21+
22+ * 调用 ` Invoke-DockerCompose -Action 'pull' -Profiles @($ServiceName) `
23+
24+ * 继续调用 ` Invoke-DockerCompose -Action 'up -d' -Profiles @($ServiceName) `
25+
26+ * ` $PullAlways ` 为真(Compose v2):
27+
28+ * 调用 ` Invoke-DockerCompose -Action 'up -d' -Profiles @($ServiceName) -ExtraArgs @('--pull','always') `
29+
30+ * 若检测为 legacy compose(` docker-compose ` ),自动降级为方案 A 的两步执行。
31+ 3 . 细节约束:保持现有 ` ProjectName ` 、环境变量注入与 ` Wait-ServiceHealthy ` 行为一致。
32+ 4 . 文档更新:完善 ` .SYNOPSIS ` 、` .PARAMETER ` 、` .EXAMPLE ` ,新增:
33+
34+ * ` .\start-container.ps1 -ServiceName new-api -Update `
35+
36+ * ` .\start-container.ps1 -ServiceName new-api -PullAlways `
37+
38+ ## 验证
39+
40+ * 使用 ` -DryRun ` 验证生成命令,在 v2 环境确认出现 ` --pull always ` 。
41+
42+ * 针对 ` redis ` 、` new-api ` 做冒烟:` -Update ` 和 ` -PullAlways ` 分别测试,有/无 ` -ServiceName ` 两种路径。
43+
44+ * 保证 legacy 环境自动回退,两步执行仍可用。
45+
46+ ## 风险与回滚
47+
48+ * ` --pull always ` 仅 v2 支持,已设置自动回退避免失败。
49+
50+ * 若镜像更新导致不兼容,可用 ` -Down ` 再 ` -Update ` 进行干净重启。
51+
52+ ## 代码位置参考
53+
54+ * 拉取逻辑:` start-container.ps1:294-301 `
55+
56+ * 启动逻辑:` start-container.ps1:302-306 `
57+
58+ * Compose 封装:` start-container.ps1:165-189 `
59+
60+ * ` new-api ` 服务定义(profile 映射):` config/dockerfiles/compose/docker-compose.yml:214-229 `
61+
Original file line number Diff line number Diff line change 11$moduleParent = Split-Path - Parent $PSScriptRoot
22$psutilsRoot = Join-Path $moduleParent ' psutils'
3- $modulesPath = Join-Path $psutilsRoot ' modules'
43
5- Import-Module (Join-Path $modulesPath ' test.psm1' )
6- Import-Module (Join-Path $modulesPath ' cache.psm1' )
7- Import-Module (Join-Path $modulesPath ' wrapper.psm1' )
4+ Import-Module (Join-Path $psutilsRoot ' psutils.psd1' )
85
9- $paths = ($env: PSModulePath -split ' ;' ) | Where-Object { $_ }
6+ $sep = [System.IO.Path ]::PathSeparator
7+ $paths = ($env: PSModulePath -split [string ]$sep ) | Where-Object { $_ }
108if ($psutilsRoot -notin $paths ) {
11- $env: PSModulePath = ($paths + $psutilsRoot ) -join ' ; '
9+ $env: PSModulePath = ($paths + $psutilsRoot ) -join $sep
1210}
1311
14-
Original file line number Diff line number Diff line change 2929[CmdletBinding ()]
3030param (
3131 [Parameter (HelpMessage = " 是否将配置加载到 PowerShell 配置文件中" )]
32- [switch ]$LoadProfile
32+ [switch ]$LoadProfile ,
33+ [string ]$AliasDespPrefix = ' [mudssky]'
3334)
3435
3536# 加载自定义模块
You can’t perform that action at this time.
0 commit comments