Skip to content

Commit

Permalink
Adapting REGEXP to docker requirements
Browse files Browse the repository at this point in the history
According to the `docker` CLI, when running a container with a wrong name, the following output is shown:
```
> docker run -it --name '$$' alpine
docker: Error response from daemon: Invalid container name ($$), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed.
```
Concatenating `container:` to the expected regular expression `[a-zA-Z0-9][a-zA-Z0-9_.-]` helps us rejecting wrong values.
  • Loading branch information
zedfmario committed Dec 3, 2020
1 parent d505084 commit b2be10f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func validateDockerNetworkMode(artifacts []*latest.Artifact) (errs []error) {
if mode == "none" || mode == "bridge" || mode == "host" {
continue
}
containerRegExp := regexp.MustCompile("container:.+")
containerRegExp := regexp.MustCompile("^container:[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
if containerRegExp.MatchString(mode) {
continue
}
Expand Down
45 changes: 43 additions & 2 deletions pkg/skaffold/schema/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,54 @@ func TestValidateNetworkMode(t *testing.T) {
shouldErr: true,
},
{
description: "container's network stack",
description: "wrong container's network stack '-not-valid'",
artifacts: []*latest.Artifact{
{
ImageName: "image/container",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
NetworkMode: "Container:unique-identifier",
NetworkMode: "Container:-not-valid",
},
},
},
},
shouldErr: true,
},
{
description: "wrong container's network stack 'fussball'",
artifacts: []*latest.Artifact{
{
ImageName: "image/container",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
NetworkMode: "Container:fußball",
},
},
},
},
shouldErr: true,
},
{
description: "container's network stack 'unique'",
artifacts: []*latest.Artifact{
{
ImageName: "image/container",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
NetworkMode: "Container:unique",
},
},
},
},
},
{
description: "container's network stack 'unique-id.123'",
artifacts: []*latest.Artifact{
{
ImageName: "image/container",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
NetworkMode: "Container:unique-id.123",
},
},
},
Expand Down

0 comments on commit b2be10f

Please sign in to comment.