allow to set image without a tag

This commit is contained in:
Nestor
2019-05-10 17:27:49 +02:00
parent 540e4023da
commit e4159d9411
2 changed files with 22 additions and 3 deletions

View File

@@ -160,7 +160,7 @@ func parse(arg string) (image.Image, error) {
// matches if there is an image name to overwrite
// <image>=<new-image><:|@><new-tag>
if s := strings.Split(arg, separator); len(s) == 2 {
p, err := parseOverwrite(s[1])
p, err := parseOverwrite(s[1], true)
return image.Image{
Name: s[0],
NewName: p.name,
@@ -171,7 +171,7 @@ func parse(arg string) (image.Image, error) {
// matches only for <tag|digest> overwrites
// <image><:|@><new-tag>
p, err := parseOverwrite(arg)
p, err := parseOverwrite(arg, false)
return image.Image{
Name: p.name,
NewTag: p.tag,
@@ -181,7 +181,7 @@ func parse(arg string) (image.Image, error) {
// parseOverwrite parses the overwrite parameters
// from the given arg into a struct
func parseOverwrite(arg string) (overwrite, error) {
func parseOverwrite(arg string, overwriteImage bool) (overwrite, error) {
// match <image>@<digest>
if d := strings.Split(arg, "@"); len(d) > 1 {
return overwrite{
@@ -197,5 +197,12 @@ func parseOverwrite(arg string) (overwrite, error) {
tag: t[2],
}, nil
}
// match <image>
if len(arg) > 0 && overwriteImage {
return overwrite{
name: arg,
}, nil
}
return overwrite{}, errImageInvalidArgs
}

View File

@@ -84,6 +84,18 @@ func TestSetImage(t *testing.T) {
" name: image1",
}},
},
{
description: "<image>=<image>",
given: given{
args: []string{"ngnix=localhost:5000/my-project/ngnix"},
},
expected: expected{
fileOutput: []string{
"images:",
"- name: ngnix",
" newName: localhost:5000/my-project/ngnix",
}},
},
{
given: given{
args: []string{"ngnix=localhost:5000/my-project/ngnix:dev-01"},