Strip the image name down more for container names

When computing a default container name from the name of a source image,
drop tags and any leading components from the image name before
attempting to use it as part of a container name.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #33
Approved by: rhatdan
This commit is contained in:
Nalin Dahyabhai 2017-03-23 16:18:40 -04:00 committed by Atomic Bot
parent e96ba381a2
commit 4c982a3799
1 changed files with 15 additions and 1 deletions

16
new.go
View File

@ -2,6 +2,7 @@ package buildah
import (
"fmt"
"strings"
"github.com/Sirupsen/logrus"
is "github.com/containers/image/storage"
@ -28,7 +29,20 @@ func newBuilder(store storage.Store, options BuilderOptions) (*Builder, error) {
name = options.Container
} else {
if image != "" {
name = image + "-" + name
prefix := image
s := strings.Split(prefix, "/")
if len(s) > 0 {
prefix = s[len(s)-1]
}
s = strings.Split(prefix, ":")
if len(s) > 0 {
prefix = s[0]
}
s = strings.Split(prefix, "@")
if len(s) > 0 {
prefix = s[0]
}
name = prefix + "-" + name
}
}
if name != "" {