From 9603389586d3a4d4093d2d8daa1740ef3628407c Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:42:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=A3=E5=86=B3=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E4=B9=8B=E5=90=8E=E4=BC=9A=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E7=9A=84=E9=97=AE=E9=A2=98=20(#613)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/runtime_utils.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/app/service/runtime_utils.go b/backend/app/service/runtime_utils.go index 36069e57a..8979adcfd 100644 --- a/backend/app/service/runtime_utils.go +++ b/backend/app/service/runtime_utils.go @@ -13,24 +13,27 @@ import ( "strings" ) -func buildRuntime(runtime *model.Runtime, service *docker.ComposeService, imageID string) { +func buildRuntime(runtime *model.Runtime, service *docker.ComposeService, oldImageID string) { err := service.ComposeBuild() if err != nil { runtime.Status = constant.RuntimeError runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + err.Error() } else { runtime.Status = constant.RuntimeNormal - if imageID != "" { + if oldImageID != "" { client, err := docker.NewClient() - global.LOG.Infof("delete imageID [%s] ", imageID) if err == nil { - if err := client.DeleteImage(imageID); err != nil { - global.LOG.Errorf("delete imageID [%s] error %v", imageID, err) - } else { - global.LOG.Infof("delete old image success") + newImageID, err := client.GetImageIDByName(runtime.Image) + if err == nil && newImageID != oldImageID { + global.LOG.Infof("delete imageID [%s] ", oldImageID) + if err := client.DeleteImage(oldImageID); err != nil { + global.LOG.Errorf("delete imageID [%s] error %v", oldImageID, err) + } else { + global.LOG.Infof("delete old image success") + } } } else { - global.LOG.Errorf("delete imageID [%s] error %v", imageID, err) + global.LOG.Errorf("delete imageID [%s] error %v", oldImageID, err) } } }