Skip to content

Commit

Permalink
更新副本时,增加updateDelay参数控制
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 17, 2024
1 parent f964cf8 commit 99701ef
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,26 @@ func (receiver service) Delete(serviceName string) error {

// SetImagesAndReplicas 更新镜像版本和副本数量
func (receiver service) SetImagesAndReplicas(serviceName string, dockerImages string, dockerReplicas int) error {
var exitCode = exec.RunShell(fmt.Sprintf("docker service update --image %s --replicas %v --update-delay 10s --with-registry-auth %s", dockerImages, dockerReplicas, serviceName), receiver.progress, nil, "", false)
var exitCode = exec.RunShell(fmt.Sprintf("docker service update --image %s --replicas %v --with-registry-auth %s", dockerImages, dockerReplicas, serviceName), receiver.progress, nil, "", false)
if exitCode != 0 {
return fmt.Errorf(collections.NewListFromChan(receiver.progress).ToString("\n"))
}
return nil
}

// SetImages 更新镜像版本
func (receiver service) SetImages(serviceName string, dockerImages string) error {
var exitCode = exec.RunShell(fmt.Sprintf("docker service update --image %s --update-delay 10s --with-registry-auth %s", dockerImages, serviceName), receiver.progress, nil, "", true)
func (receiver service) SetImages(serviceName string, dockerImages string, updateDelay int) error {
var sb bytes.Buffer
sb.WriteString(fmt.Sprintf("docker service update --image %s --with-registry-auth", dockerImages))

// 滚动更新时的时间间隔
if updateDelay > 0 {
sb.WriteString(fmt.Sprintf(" --update-delay=%ds", updateDelay))
}

sb.WriteString(fmt.Sprintf(" %s", serviceName))

var exitCode = exec.RunShell(sb.String(), receiver.progress, nil, "", true)
if exitCode != 0 {
return fmt.Errorf(collections.NewListFromChan(receiver.progress).ToString("\n"))
}
Expand Down

0 comments on commit 99701ef

Please sign in to comment.