提交 11e1b458 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!9 isula-build: fix build FROM local store image failed

Merge pull request !9 from Grooooot/master
......@@ -104,7 +104,15 @@ func NewBuilder(ctx context.Context, store store.Store, req *pb.BuildRequest, ru
Iidfile: req.GetIidfile(),
}
b.parseStaticBuildOpts(req)
b.buildOpts.Tag = parseTag(req.Output)
tag := parseTag(req.Output)
if tag != "" {
candidates, _, rerr := image.ResolveName(tag, nil, b.localStore)
if rerr != nil || len(candidates) == 0 {
return nil, errors.Wrapf(rerr, "parse target tag %v err", tag)
}
b.buildOpts.Tag = candidates[0]
}
// prepare workdirs for dockerfile builder
for _, dir := range []string{buildDir, runDir} {
......@@ -511,25 +519,29 @@ func (b *Builder) OutputPipeWrapper() *exporter.PipeWrapper {
func parseTag(output string) string {
outputFields := strings.Split(output, ":")
if (outputFields[0] == "docker-daemon" || outputFields[0] == "isulad") && len(outputFields) > 1 {
return strings.Join(outputFields[1:], ":")
}
const archiveOutputWithoutTagLen = 2
if outputFields[0] == "docker-archive" && len(outputFields) > archiveOutputWithoutTagLen {
var tag string
switch {
case (outputFields[0] == "docker-daemon" || outputFields[0] == "isulad") && len(outputFields) > 1:
tag = strings.Join(outputFields[1:], ":")
case outputFields[0] == "docker-archive" && len(outputFields) > archiveOutputWithoutTagLen:
if len(outputFields[archiveOutputWithoutTagLen:]) == 1 {
outputFields = append(outputFields, "latest")
}
return strings.Join(outputFields[archiveOutputWithoutTagLen:], ":")
}
if outputFields[0] == "docker" && len(outputFields) > 1 {
tag = strings.Join(outputFields[archiveOutputWithoutTagLen:], ":")
case outputFields[0] == "docker" && len(outputFields) > 1:
repoAndTag := strings.Join(outputFields[1:], ":")
// repo format regexp, "//registry.example.com/" for example
repo := regexp.MustCompile(`^\/\/[\w\.\-\:]+\/`).FindString(repoAndTag)
if repo == "" {
return ""
}
return repoAndTag[len(repo):]
tag = repoAndTag[len(repo):]
if len(strings.Split(tag, ":")) == 1 {
tag += ":latest"
}
}
return ""
return tag
}
......@@ -1295,6 +1295,11 @@ func TestParseTag(t *testing.T) {
output: "docker://localhost:5000/isula/test:latest",
tag: "isula/test:latest",
},
{
name: "docker output",
output: "docker://localhost:5000/isula/test",
tag: "isula/test:latest",
},
{
name: "invalid docker output",
output: "docker:localhost:5000/isula/test:latest",
......
......@@ -132,7 +132,7 @@ func pullImage(opt pullOption) (types.ImageReference, error) {
func pullAndGetImageInfo(opt *PrepareImageOptions) (types.ImageReference, *storage.Image, error) {
pLog := logrus.WithField(util.LogKeyBuildID, opt.Ctx.Value(util.LogFieldKey(util.LogKeyBuildID)))
candidates, transport, err := resolveName(opt.FromImage, opt.SystemContext, opt.Store)
candidates, transport, err := ResolveName(opt.FromImage, opt.SystemContext, opt.Store)
if err != nil {
return nil, nil, errors.Wrapf(err, "error parsing reference to image %q", opt.FromImage)
}
......@@ -476,7 +476,7 @@ func ResolveImageName(s string, resolveArg func(string) string) (string, error)
// FindImage get the image from storage by image describe
func FindImage(store store.Store, image string) (types.ImageReference, *storage.Image, error) {
names, _, err := resolveName(image, nil, store)
names, _, err := ResolveName(image, nil, store)
if err != nil {
return nil, nil, errors.Wrapf(err, "error parsing name %q", image)
}
......@@ -508,7 +508,9 @@ func FindImage(store store.Store, image string) (types.ImageReference, *storage.
return ref, img, nil
}
func resolveName(name string, sc *types.SystemContext, store store.Store) ([]string, string, error) {
// ResolveName checks whether the image name is valid, if the name does not include a domain,
// returns a list of candidates it might be
func ResolveName(name string, sc *types.SystemContext, store store.Store) ([]string, string, error) {
// 1. check name valid
if name == "" {
return nil, "", nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册