mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-16 08:27:06 +08:00
Provide current env as variables in eval context
Signed-off-by: Patrick Van Stee <patrick@vanstee.me>
This commit is contained in:
21
bake/hcl.go
21
bake/hcl.go
@ -1,10 +1,27 @@
|
||||
package bake
|
||||
|
||||
import "github.com/hashicorp/hcl/v2/hclsimple"
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
hcl "github.com/hashicorp/hcl/v2"
|
||||
"github.com/hashicorp/hcl/v2/hclsimple"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
func ParseHCL(dt []byte, fn string) (*Config, error) {
|
||||
variables := make(map[string]cty.Value)
|
||||
for _, env := range os.Environ() {
|
||||
parts := strings.SplitN(env, "=", 2)
|
||||
variables[parts[0]] = cty.StringVal(parts[1])
|
||||
}
|
||||
|
||||
ctx := &hcl.EvalContext{
|
||||
Variables: variables,
|
||||
}
|
||||
|
||||
var c Config
|
||||
if err := hclsimple.Decode(fn, dt, nil, &c); err != nil {
|
||||
if err := hclsimple.Decode(fn, dt, ctx, &c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
|
Reference in New Issue
Block a user