mirror of
https://github.com/containers/buildah.git
synced 2025-07-31 15:24:26 +03:00
Check earlier for bad image tags name
Fixes: https://github.com/containers/buildah/issues/3134 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
11
commit.go
11
commit.go
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/containers/image/v5/signature"
|
"github.com/containers/image/v5/signature"
|
||||||
is "github.com/containers/image/v5/storage"
|
is "github.com/containers/image/v5/storage"
|
||||||
"github.com/containers/image/v5/transports"
|
"github.com/containers/image/v5/transports"
|
||||||
"github.com/containers/image/v5/transports/alltransports"
|
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
encconfig "github.com/containers/ocicrypt/config"
|
encconfig "github.com/containers/ocicrypt/config"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
@ -190,13 +189,11 @@ func (b *Builder) addManifest(ctx context.Context, manifestName string, imageSpe
|
|||||||
return "", errors.Wrapf(err, "error encountered while expanding image name %q", manifestName)
|
return "", errors.Wrapf(err, "error encountered while expanding image name %q", manifestName)
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err := alltransports.ParseImageName(imageSpec)
|
ref, err := util.VerifyTagName(imageSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ref, err = alltransports.ParseImageName(util.DefaultTransport + imageSpec); err != nil {
|
// check if the local image exists
|
||||||
// check if the local image exists
|
if ref, _, err = util.FindImage(b.store, "", systemContext, imageSpec); err != nil {
|
||||||
if ref, _, err = util.FindImage(b.store, "", systemContext, imageSpec); err != nil {
|
return "", err
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/buildah/define"
|
"github.com/containers/buildah/define"
|
||||||
|
"github.com/containers/buildah/util"
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
"github.com/containers/image/v5/docker/reference"
|
"github.com/containers/image/v5/docker/reference"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
@ -56,6 +57,14 @@ func BuildDockerfiles(ctx context.Context, store storage.Store, options define.B
|
|||||||
}
|
}
|
||||||
}(dockerfiles...)
|
}(dockerfiles...)
|
||||||
|
|
||||||
|
for _, tag := range append([]string{options.Output}, options.AdditionalTags...) {
|
||||||
|
if tag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := util.VerifyTagName(tag); err != nil {
|
||||||
|
return "", nil, errors.Wrapf(err, "tag %s", tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, dfile := range paths {
|
for _, dfile := range paths {
|
||||||
var data io.ReadCloser
|
var data io.ReadCloser
|
||||||
|
|
||||||
|
@ -406,6 +406,15 @@ symlink(subdir)"
|
|||||||
expect_output --substring "Successfully tagged localhost/test2:latest"
|
expect_output --substring "Successfully tagged localhost/test2:latest"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "bud with bad --tag " {
|
||||||
|
target=scratch-image
|
||||||
|
run_buildah 125 bud --quiet=false --tag TEST1 --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
|
||||||
|
expect_output --substring "tag TEST1: invalid reference format: repository name must be lowercase"
|
||||||
|
|
||||||
|
run_buildah 125 bud --quiet=false --tag test1 --tag TEST2 --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
|
||||||
|
expect_output --substring "tag TEST2: invalid reference format: repository name must be lowercase"
|
||||||
|
}
|
||||||
|
|
||||||
@test "bud-from-scratch-iid" {
|
@test "bud-from-scratch-iid" {
|
||||||
target=scratch-image
|
target=scratch-image
|
||||||
run_buildah bud --iidfile ${TESTDIR}/output.iid --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
|
run_buildah bud --iidfile ${TESTDIR}/output.iid --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
|
||||||
|
10
util/util.go
10
util/util.go
@ -482,3 +482,13 @@ func SortMounts(m []specs.Mount) []specs.Mount {
|
|||||||
sort.Sort(byDestination(m))
|
sort.Sort(byDestination(m))
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VerifyTagName(imageSpec string) (types.ImageReference, error) {
|
||||||
|
ref, err := alltransports.ParseImageName(imageSpec)
|
||||||
|
if err != nil {
|
||||||
|
if ref, err = alltransports.ParseImageName(DefaultTransport + imageSpec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ref, nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user