mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
Merge pull request #2106 from jedevc/fix-bake-matrix-with-target-access
bake: fix global target access when using a matrix
This commit is contained in:
commit
08a70ecdcc
@ -949,8 +949,10 @@ func (t *Target) GetEvalContexts(ectx *hcl.EvalContext, block *hcl.Block, loadDe
|
||||
for _, e := range ectxs {
|
||||
e2 := ectx.NewChild()
|
||||
e2.Variables = make(map[string]cty.Value)
|
||||
for k, v := range e.Variables {
|
||||
e2.Variables[k] = v
|
||||
if e != ectx {
|
||||
for k, v := range e.Variables {
|
||||
e2.Variables[k] = v
|
||||
}
|
||||
}
|
||||
e2.Variables[k] = v
|
||||
ectxs2 = append(ectxs2, e2)
|
||||
|
@ -1113,6 +1113,27 @@ func TestHCLMatrixBadTypes(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHCLMatrixWithGlobalTarget(t *testing.T) {
|
||||
dt := []byte(`
|
||||
target "x" {
|
||||
tags = ["a", "b"]
|
||||
}
|
||||
|
||||
target "default" {
|
||||
tags = target.x.tags
|
||||
matrix = {
|
||||
dummy = [""]
|
||||
}
|
||||
}
|
||||
`)
|
||||
c, err := ParseFile(dt, "docker-bake.hcl")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(c.Targets))
|
||||
require.Equal(t, "x", c.Targets[0].Name)
|
||||
require.Equal(t, "default", c.Targets[1].Name)
|
||||
require.Equal(t, []string{"a", "b"}, c.Targets[1].Tags)
|
||||
}
|
||||
|
||||
func TestJSONAttributes(t *testing.T) {
|
||||
dt := []byte(`{"FOO": "abc", "variable": {"BAR": {"default": "def"}}, "target": { "app": { "args": {"v1": "pre-${FOO}-${BAR}"}} } }`)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user