diff --git a/bake/bake.go b/bake/bake.go index 82d7d921..384336df 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -28,8 +28,10 @@ var ( httpPrefix = regexp.MustCompile(`^https?://`) gitURLPathWithFragmentSuffix = regexp.MustCompile(`\.git(?:#.+)?$`) - validTargetNameChars = `[a-zA-Z0-9_-]+` - targetNamePattern = regexp.MustCompile(`^` + validTargetNameChars + `$`) + validTargetNameChars = `[a-zA-Z0-9_-]+` + validTargetNameCharsCompose = `[a-zA-Z0-9._-]+` + targetNamePattern = regexp.MustCompile(`^` + validTargetNameChars + `$`) + targetNamePatternCompose = regexp.MustCompile(`^` + validTargetNameCharsCompose + `$`) ) type File struct { @@ -968,6 +970,13 @@ func validateTargetName(name string) error { 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 { if len(s1) != len(s2) { return false diff --git a/bake/compose.go b/bake/compose.go index aecd88f9..32718d04 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -60,7 +60,7 @@ func ParseCompose(dt []byte) (*Config, error) { 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) } diff --git a/bake/compose_test.go b/bake/compose_test.go index fffd97b0..e6ad24a2 100644 --- a/bake/compose_test.go +++ b/bake/compose_test.go @@ -330,6 +330,10 @@ func TestServiceName(t *testing.T) { }, { svc: "a.b", + wantErr: false, + }, + { + svc: "a?b", wantErr: true, }, {