Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add host support for docker build #5698

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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