Skip to content

Commit 025c708

Browse files
authored
fix: restore update tar image (#2346)
Signed-off-by: Qi Zhang <[email protected]>
1 parent 2b17ee4 commit 025c708

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

builder/parser/docker_run.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ package parser
2121
import (
2222
"encoding/json"
2323
"fmt"
24+
"path"
25+
"path/filepath"
26+
"runtime"
27+
"strconv"
28+
"strings" //"github.com/docker/docker/client"
29+
2430
"github.com/containerd/containerd"
2531
"github.com/containerd/containerd/content"
2632
"github.com/containerd/containerd/images"
@@ -33,12 +39,8 @@ import (
3339
"github.com/goodrain/rainbond/pkg/component/storage"
3440
"github.com/goodrain/rainbond/util"
3541
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
42+
"github.com/sirupsen/logrus"
3643
"golang.org/x/net/context"
37-
"path"
38-
"path/filepath"
39-
"runtime"
40-
"strconv"
41-
"strings" //"github.com/docker/docker/client"
4244
)
4345

4446
// DockerRunOrImageParse docker run 命令解析或直接镜像名解析
@@ -125,11 +127,29 @@ func (d *DockerRunOrImageParse) Parse() ParseErrorList {
125127
})
126128
}
127129
d.tarImages = tarImages
128-
// 简化tar包镜像处理:跳过重新打tag和push操作
129-
// 直接使用加载的镜像名称,不进行额外的标签操作
130-
d.logger.Info(fmt.Sprintf("加载tar包镜像: %v (跳过tag和push操作)", imageNames), map[string]string{"step": "image-parse"})
131-
132-
// 注意:跳过了镜像tag和push操作,直接使用原始镜像名称
130+
for _, imageName := range imageNames {
131+
imageList := strings.Split(imageName, "/")
132+
var newImageName string
133+
if len(imageList) == 1 {
134+
newImageName = path.Join(builder.REGISTRYDOMAIN, d.namespace, imageList[0])
135+
} else if len(imageList) == 2 {
136+
newImageName = path.Join(builder.REGISTRYDOMAIN, d.namespace, imageList[1])
137+
} else if len(imageList) == 3 {
138+
newImageName = path.Join(builder.REGISTRYDOMAIN, d.namespace, imageList[2])
139+
}
140+
err := d.imageClient.ImageTag(imageName, newImageName, d.logger, 3)
141+
if err != nil {
142+
logrus.Errorf("tag tar image failure: %v", err)
143+
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("镜像修改 tag 失败"), SolveAdvice("modify_image", "请联系平台管理员")))
144+
return d.errors
145+
}
146+
err = d.imageClient.ImagePush(newImageName, builder.REGISTRYUSER, builder.REGISTRYPASS, d.logger, 3)
147+
if err != nil {
148+
logrus.Errorf("load tar image push failure: %v", err)
149+
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("镜像push 失败"), SolveAdvice("modify_image", "请联系平台管理员")))
150+
return d.errors
151+
}
152+
}
133153
return d.errors
134154
} else {
135155
//else image

0 commit comments

Comments
 (0)