bake: allow dot in target names for compose

This is a hotfix for v0.8 to unblock release and
restore backward compatibility. More proper fix
coming later.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
pull/1018/head
Tonis Tiigi 3 years ago
parent 106651877d
commit 24ad37a5d2

@ -29,7 +29,9 @@ var (
gitURLPathWithFragmentSuffix = regexp.MustCompile(`\.git(?:#.+)?$`) gitURLPathWithFragmentSuffix = regexp.MustCompile(`\.git(?:#.+)?$`)
validTargetNameChars = `[a-zA-Z0-9_-]+` validTargetNameChars = `[a-zA-Z0-9_-]+`
validTargetNameCharsCompose = `[a-zA-Z0-9._-]+`
targetNamePattern = regexp.MustCompile(`^` + validTargetNameChars + `$`) targetNamePattern = regexp.MustCompile(`^` + validTargetNameChars + `$`)
targetNamePatternCompose = regexp.MustCompile(`^` + validTargetNameCharsCompose + `$`)
) )
type File struct { type File struct {
@ -968,6 +970,13 @@ func validateTargetName(name string) error {
return nil return nil
} }
func validateTargetNameCompose(name string) error {
if !targetNamePatternCompose.MatchString(name) {
return errors.Errorf("only %q are allowed", validTargetNameCharsCompose)
}
return nil
}
func sliceEqual(s1, s2 []string) bool { func sliceEqual(s1, s2 []string) bool {
if len(s1) != len(s2) { if len(s1) != len(s2) {
return false return false

@ -60,7 +60,7 @@ func ParseCompose(dt []byte) (*Config, error) {
continue continue
} }
if err = validateTargetName(s.Name); err != nil { if err = validateTargetNameCompose(s.Name); err != nil {
return nil, errors.Wrapf(err, "invalid service name %q", s.Name) return nil, errors.Wrapf(err, "invalid service name %q", s.Name)
} }

@ -330,6 +330,10 @@ func TestServiceName(t *testing.T) {
}, },
{ {
svc: "a.b", svc: "a.b",
wantErr: false,
},
{
svc: "a?b",
wantErr: true, wantErr: true,
}, },
{ {

Loading…
Cancel
Save