Add NetworkMode to bake target

Allows specification of network mode in a bake target.

Fixes #848

Signed-off-by: Zachary Povey <zachary.povey@autotrader.co.uk>
This commit is contained in:
Zachary Povey
2021-11-25 11:35:10 +00:00
parent ab73275f58
commit ae53101e89
5 changed files with 27 additions and 8 deletions

View File

@@ -426,6 +426,7 @@ type Target struct {
Outputs []string `json:"output,omitempty" hcl:"output,optional"`
Pull *bool `json:"pull,omitempty" hcl:"pull,optional"`
NoCache *bool `json:"no-cache,omitempty" hcl:"no-cache,optional"`
NetworkMode *string `json:"network,omitempty" hcl:"network,optional"`
// IMPORTANT: if you add more fields here, do not forget to update newOverrides and README.
}
@@ -492,6 +493,9 @@ func (t *Target) Merge(t2 *Target) {
if t2.NoCache != nil {
t.NoCache = t2.NoCache
}
if t2.NetworkMode != nil {
t.NetworkMode = t2.NetworkMode
}
t.Inherits = append(t.Inherits, t2.Inherits...)
}
@@ -563,6 +567,8 @@ func (t *Target) AddOverrides(overrides map[string]Override) error {
}
}
}
case "network":
t.NetworkMode = &o.Value
default:
return errors.Errorf("unknown key: %s", keys[0])
}
@@ -632,6 +638,10 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
if t.Pull != nil {
pull = *t.Pull
}
networkMode := ""
if t.NetworkMode != nil {
networkMode = *t.NetworkMode
}
bi := build.Inputs{
ContextPath: contextPath,
@@ -648,12 +658,13 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
t.Context = &bi.ContextPath
bo := &build.Options{
Inputs: bi,
Tags: t.Tags,
BuildArgs: t.Args,
Labels: t.Labels,
NoCache: noCache,
Pull: pull,
Inputs: bi,
Tags: t.Tags,
BuildArgs: t.Args,
Labels: t.Labels,
NoCache: noCache,
Pull: pull,
NetworkMode: networkMode,
}
platforms, err := platformutil.Parse(t.Platforms)