mirror of https://github.com/docker/buildx.git
bake: allow setting networkmode in HCL/JSON
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
e58a1d35d1
commit
83d5c0c61b
|
@ -543,7 +543,7 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
|
||||||
o := t[kk[1]]
|
o := t[kk[1]]
|
||||||
|
|
||||||
switch keys[1] {
|
switch keys[1] {
|
||||||
case "output", "cache-to", "cache-from", "tags", "platform", "secrets", "ssh", "attest", "entitlements":
|
case "output", "cache-to", "cache-from", "tags", "platform", "secrets", "ssh", "attest", "entitlements", "network":
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
o.ArrValue = append(o.ArrValue, parts[1])
|
o.ArrValue = append(o.ArrValue, parts[1])
|
||||||
}
|
}
|
||||||
|
@ -704,7 +704,7 @@ type Target struct {
|
||||||
Outputs []string `json:"output,omitempty" hcl:"output,optional" cty:"output"`
|
Outputs []string `json:"output,omitempty" hcl:"output,optional" cty:"output"`
|
||||||
Pull *bool `json:"pull,omitempty" hcl:"pull,optional" cty:"pull"`
|
Pull *bool `json:"pull,omitempty" hcl:"pull,optional" cty:"pull"`
|
||||||
NoCache *bool `json:"no-cache,omitempty" hcl:"no-cache,optional" cty:"no-cache"`
|
NoCache *bool `json:"no-cache,omitempty" hcl:"no-cache,optional" cty:"no-cache"`
|
||||||
NetworkMode *string `json:"-" hcl:"-" cty:"-"`
|
NetworkMode *string `json:"network" hcl:"network" cty:"network"`
|
||||||
NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional" cty:"no-cache-filter"`
|
NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional" cty:"no-cache-filter"`
|
||||||
ShmSize *string `json:"shm-size,omitempty" hcl:"shm-size,optional"`
|
ShmSize *string `json:"shm-size,omitempty" hcl:"shm-size,optional"`
|
||||||
Ulimits []string `json:"ulimits,omitempty" hcl:"ulimits,optional"`
|
Ulimits []string `json:"ulimits,omitempty" hcl:"ulimits,optional"`
|
||||||
|
@ -914,6 +914,8 @@ func (t *Target) AddOverrides(overrides map[string]Override) error {
|
||||||
t.ShmSize = &value
|
t.ShmSize = &value
|
||||||
case "ulimits":
|
case "ulimits":
|
||||||
t.Ulimits = o.ArrValue
|
t.Ulimits = o.ArrValue
|
||||||
|
case "network":
|
||||||
|
t.NetworkMode = &value
|
||||||
case "pull":
|
case "pull":
|
||||||
pull, err := strconv.ParseBool(value)
|
pull, err := strconv.ParseBool(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1757,7 +1757,7 @@ func TestHCLEntitlements(t *testing.T) {
|
||||||
require.Equal(t, entitlements.EntitlementNetworkHost, bo["app"].Allow[1])
|
require.Equal(t, entitlements.EntitlementNetworkHost, bo["app"].Allow[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEntitlementsForNetHost(t *testing.T) {
|
func TestEntitlementsForNetHostCompose(t *testing.T) {
|
||||||
fp := File{
|
fp := File{
|
||||||
Name: "docker-bake.hcl",
|
Name: "docker-bake.hcl",
|
||||||
Data: []byte(
|
Data: []byte(
|
||||||
|
@ -1790,7 +1790,69 @@ func TestEntitlementsForNetHost(t *testing.T) {
|
||||||
require.Contains(t, m, "app")
|
require.Contains(t, m, "app")
|
||||||
require.Len(t, m["app"].Entitlements, 1)
|
require.Len(t, m["app"].Entitlements, 1)
|
||||||
require.Equal(t, "network.host", m["app"].Entitlements[0])
|
require.Equal(t, "network.host", m["app"].Entitlements[0])
|
||||||
|
require.Equal(t, "host", *m["app"].NetworkMode)
|
||||||
|
|
||||||
require.Len(t, bo["app"].Allow, 1)
|
require.Len(t, bo["app"].Allow, 1)
|
||||||
require.Equal(t, entitlements.EntitlementNetworkHost, bo["app"].Allow[0])
|
require.Equal(t, entitlements.EntitlementNetworkHost, bo["app"].Allow[0])
|
||||||
|
require.Equal(t, "host", bo["app"].NetworkMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEntitlementsForNetHost(t *testing.T) {
|
||||||
|
fp := File{
|
||||||
|
Name: "docker-bake.hcl",
|
||||||
|
Data: []byte(
|
||||||
|
`target "app" {
|
||||||
|
dockerfile = "app.Dockerfile"
|
||||||
|
network = "host"
|
||||||
|
}`),
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.TODO()
|
||||||
|
m, g, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
bo, err := TargetsToBuildOpt(m, &Input{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, 1, len(g))
|
||||||
|
require.Equal(t, []string{"app"}, g["default"].Targets)
|
||||||
|
|
||||||
|
require.Equal(t, 1, len(m))
|
||||||
|
require.Contains(t, m, "app")
|
||||||
|
require.Len(t, m["app"].Entitlements, 1)
|
||||||
|
require.Equal(t, "network.host", m["app"].Entitlements[0])
|
||||||
|
require.Equal(t, "host", *m["app"].NetworkMode)
|
||||||
|
|
||||||
|
require.Len(t, bo["app"].Allow, 1)
|
||||||
|
require.Equal(t, entitlements.EntitlementNetworkHost, bo["app"].Allow[0])
|
||||||
|
require.Equal(t, "host", bo["app"].NetworkMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNetNone(t *testing.T) {
|
||||||
|
fp := File{
|
||||||
|
Name: "docker-bake.hcl",
|
||||||
|
Data: []byte(
|
||||||
|
`target "app" {
|
||||||
|
dockerfile = "app.Dockerfile"
|
||||||
|
network = "none"
|
||||||
|
}`),
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.TODO()
|
||||||
|
m, g, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
bo, err := TargetsToBuildOpt(m, &Input{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, 1, len(g))
|
||||||
|
require.Equal(t, []string{"app"}, g["default"].Targets)
|
||||||
|
|
||||||
|
require.Equal(t, 1, len(m))
|
||||||
|
require.Contains(t, m, "app")
|
||||||
|
require.Len(t, m["app"].Entitlements, 0)
|
||||||
|
require.Equal(t, "none", *m["app"].NetworkMode)
|
||||||
|
|
||||||
|
require.Len(t, bo["app"].Allow, 0)
|
||||||
|
require.Equal(t, "none", bo["app"].NetworkMode)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue