From 99701efaad7ce2c32f7fb111e22d84493d56153e Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Mon, 18 Nov 2024 01:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=89=AF=E6=9C=AC=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0updateDelay=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/service.go b/service.go index a89a06a..e683b73 100644 --- a/service.go +++ b/service.go @@ -28,7 +28,7 @@ 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")) } @@ -36,8 +36,18 @@ func (receiver service) SetImagesAndReplicas(serviceName string, dockerImages st } // 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")) }