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 4, 2020
1 parent 0e4ebdd commit 8980118
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
5 changes: 2 additions & 3 deletions docs/content/en/schemas/v2beta10.json
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,11 @@
},
"network": {
"type": "string",
"description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `container:<name|id>`: reuse another container's network stack. `none`: no networking in the container.",
"x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are <code>host</code>: use the host's networking stack. <code>bridge</code>: use the bridged network configuration. <code>container:&lt;name|id&gt;</code>: reuse another container's network stack. <code>none</code>: no networking in the container.",
"description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `none`: no networking in the container.",
"x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are <code>host</code>: use the host's networking stack. <code>bridge</code>: use the bridged network configuration. <code>none</code>: no networking in the container.",
"enum": [
"host",
"bridge",
"container:<name|id>",
"none"
]
},
Expand Down
5 changes: 3 additions & 2 deletions docs/content/en/schemas/v2beta11.json
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,12 @@
},
"network": {
"type": "string",
"description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `none`: no networking in the container.",
"x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are <code>host</code>: use the host's networking stack. <code>bridge</code>: use the bridged network configuration. <code>none</code>: no networking in the container.",
"description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `container:<name|id>`: reuse another container's network stack. `none`: no networking in the container.",
"x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are <code>host</code>: use the host's networking stack. <code>bridge</code>: use the bridged network configuration. <code>container:&lt;name|id&gt;</code>: reuse another container's network stack. <code>none</code>: no networking in the container.",
"enum": [
"host",
"bridge",
"container:<name|id>",
"none"
]
},
Expand Down
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 8980118

Please sign in to comment.