Skip to content

Commit

Permalink
feat: 解决编辑镜像之后会删除镜像的问题 (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 authored Apr 13, 2023
1 parent cd79cac commit 9603389
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions backend/app/service/runtime_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 9603389

Please sign in to comment.