@@ -15,6 +15,7 @@ import (
1515 "sort"
1616 "strconv"
1717 "strings"
18+ "sync"
1819 "time"
1920
2021 composecli "github.com/compose-spec/compose-go/v2/cli"
@@ -375,8 +376,12 @@ func ParseFiles(files []File, defaults map[string]string) (_ *Config, _ *hclpars
375376
376377 var pm hclparser.ParseMeta
377378 if len (hclFiles ) > 0 {
379+ lookup := func (string ) (string , bool ) { return "" , false }
380+ if envLookupAllowed () {
381+ lookup = os .LookupEnv
382+ }
378383 res , err := hclparser .Parse (hclparser .MergeFiles (hclFiles ), hclparser.Opt {
379- LookupVar : os . LookupEnv ,
384+ LookupVar : lookup ,
380385 Vars : defaults ,
381386 ValidateLabel : validateTargetName ,
382387 }, & c )
@@ -597,7 +602,7 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
597602 if len (keys ) != 3 {
598603 return nil , errors .Errorf ("invalid key %s, args requires name" , parts [0 ])
599604 }
600- if len (parts ) < 2 {
605+ if len (parts ) < 2 && envLookupAllowed () {
601606 v , ok := os .LookupEnv (keys [2 ])
602607 if ! ok {
603608 continue
@@ -1728,3 +1733,13 @@ func parseArrValue[T any, PT arrValue[T]](s []string) ([]*T, error) {
17281733 }
17291734 return outputs , nil
17301735}
1736+
1737+ var envLookupAllowed = sync .OnceValue (func () bool {
1738+ if v , ok := os .LookupEnv ("BUILDX_BAKE_DISABLE_VARS_ENV_LOOKUP" ); ok {
1739+ disable , err := strconv .ParseBool (v )
1740+ if err == nil && disable {
1741+ return false
1742+ }
1743+ }
1744+ return true
1745+ })
0 commit comments