Skip to content

Commit

Permalink
add host support for docker build (#5698)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxingzhong authored Apr 20, 2021
1 parent b455ffd commit 6c747fc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/content/en/schemas/v2beta15.json
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,18 @@
},
"DockerArtifact": {
"properties": {
"addHost": {
"items": {
"type": "string"
},
"type": "array",
"description": "add host.",
"x-intellij-html-description": "add host.",
"default": "[]",
"examples": [
"[\"host1:ip1\", \"host2:ip2\"]"
]
},
"buildArgs": {
"additionalProperties": {
"type": "string"
Expand Down Expand Up @@ -1142,6 +1154,7 @@
"target",
"buildArgs",
"network",
"addHost",
"cacheFrom",
"noCache",
"squash",
Expand Down
5 changes: 5 additions & 0 deletions pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string
Target: a.Target,
ForceRemove: l.forceRemove,
NetworkMode: strings.ToLower(a.NetworkMode),
ExtraHosts: a.AddHost,
NoCache: a.NoCache,
})
if err != nil {
Expand Down Expand Up @@ -481,6 +482,10 @@ func ToCLIBuildArgs(a *latest.DockerArtifact, evaluatedArgs map[string]*string)
}
}

for _, host := range a.AddHost {
args = append(args, "--add-host", host)
}

for _, from := range a.CacheFrom {
args = append(args, "--cache-from", from)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/docker/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ func TestGetBuildArgs(t *testing.T) {
},
shouldErr: true,
},
{
description: "add host",
artifact: &latest.DockerArtifact{
AddHost: []string{"1.gcr.io:127.0.0.1", "2.gcr.io:127.0.0.1"},
},
want: []string{"--add-host", "1.gcr.io:127.0.0.1", "--add-host", "2.gcr.io:127.0.0.1"},
},
{
description: "cache from",
artifact: &latest.DockerArtifact{
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,10 @@ type DockerArtifact struct {
// `none`: no networking in the container.
NetworkMode string `yaml:"network,omitempty"`

// AddHost lists add host.
// For example: `["host1:ip1", "host2:ip2"]`.
AddHost []string `yaml:"addHost,omitempty"`

// CacheFrom lists the Docker images used as cache sources.
// For example: `["golang:1.10.1-alpine3.7", "alpine:3.7"]`.
CacheFrom []string `yaml:"cacheFrom,omitempty"`
Expand Down

0 comments on commit 6c747fc

Please sign in to comment.