@@ -318,9 +318,13 @@ func (f *floyDeployService) DeployNewVersion(params *model.DeployNewVersionParam
318318 // 5.6 处理版本历史记录(DeployNewVersion逻辑)
319319 // 获取当前活跃版本并标记为deprecated
320320 if currentVersion , err := f .getCurrentActiveVersion (instanceID , params .Service ); err == nil {
321+ // 如果找到当前活跃版本,将其标记为deprecated
321322 if err := f .updateVersionStatus (instanceID , params .Service , currentVersion , "deprecated" ); err != nil {
322323 fmt .Printf ("更新实例 %s 当前版本状态失败: %v\n " , instanceID , err )
323324 }
325+ } else {
326+ // 如果没有找到当前活跃版本,这是正常的(可能是首次部署)
327+ fmt .Printf ("实例 %s 没有当前活跃版本,这是正常的(可能是首次部署)\n " , instanceID )
324328 }
325329
326330 // 创建新版本的版本历史记录
@@ -1421,10 +1425,28 @@ func (f *floyDeployService) modifyStartScript(tempDir string, port int) error {
14211425
14221426 // 检查是否已经是新版本的脚本(从配置文件读取端口)
14231427 if strings .Contains (contentStr , "从配置文件读取端口" ) {
1424- // 如果已经是新版本脚本,只需要更新端口号
1425- oldPattern := `SERVICE_PORT="8080"`
1426- newPattern := fmt .Sprintf (`SERVICE_PORT="%d"` , port )
1427- newContent := strings .Replace (contentStr , oldPattern , newPattern , - 1 )
1428+ // 直接替换整个端口读取逻辑,使用更简单可靠的方法
1429+ oldPortLogic := `# 从配置文件读取端口
1430+ if [ -f "config.yaml" ]; then
1431+ SERVICE_PORT=$(grep -E "^\s*port:\s*" config.yaml | sed 's/.*port:\s*\([0-9]*\).*/\1/')
1432+ if [ -z "$SERVICE_PORT" ]; then
1433+ SERVICE_PORT="8080"
1434+ fi
1435+ else
1436+ SERVICE_PORT="8080"
1437+ fi`
1438+
1439+ newPortLogic := fmt .Sprintf (`# 从配置文件读取端口
1440+ if [ -f "config.yaml" ]; then
1441+ SERVICE_PORT=$(grep -A2 "service:" config.yaml | grep -E "^\s*port:\s*" | sed 's/.*port:\s*\([0-9]*\).*/\1/')
1442+ if [ -z "$SERVICE_PORT" ]; then
1443+ SERVICE_PORT="%d"
1444+ fi
1445+ else
1446+ SERVICE_PORT="%d"
1447+ fi` , port , port )
1448+
1449+ newContent := strings .Replace (contentStr , oldPortLogic , newPortLogic , 1 )
14281450
14291451 err = os .WriteFile (startScriptPath , []byte (newContent ), 0755 )
14301452 if err != nil {
0 commit comments