mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
Merge pull request #116 from tonistiigi/build-arg-default
build: load default build args from env
This commit is contained in:
commit
92f1234aaa
@ -101,6 +101,8 @@ func toMap(in composetypes.MappingWithEquals) map[string]string {
|
|||||||
for k, v := range in {
|
for k, v := range in {
|
||||||
if v != nil {
|
if v != nil {
|
||||||
m[k] = *v
|
m[k] = *v
|
||||||
|
} else {
|
||||||
|
m[k] = os.Getenv(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
|
@ -84,8 +84,8 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
|
|||||||
InStream: os.Stdin,
|
InStream: os.Stdin,
|
||||||
},
|
},
|
||||||
Tags: in.tags,
|
Tags: in.tags,
|
||||||
Labels: listToMap(in.labels),
|
Labels: listToMap(in.labels, false),
|
||||||
BuildArgs: listToMap(in.buildArgs),
|
BuildArgs: listToMap(in.buildArgs, true),
|
||||||
Pull: in.pull,
|
Pull: in.pull,
|
||||||
NoCache: in.noCache,
|
NoCache: in.noCache,
|
||||||
Target: in.target,
|
Target: in.target,
|
||||||
@ -282,12 +282,16 @@ func commonFlags(options *commonOptions, flags *pflag.FlagSet) {
|
|||||||
flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image")
|
flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image")
|
||||||
}
|
}
|
||||||
|
|
||||||
func listToMap(values []string) map[string]string {
|
func listToMap(values []string, defaultEnv bool) map[string]string {
|
||||||
result := make(map[string]string, len(values))
|
result := make(map[string]string, len(values))
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
kv := strings.SplitN(value, "=", 2)
|
kv := strings.SplitN(value, "=", 2)
|
||||||
if len(kv) == 1 {
|
if len(kv) == 1 {
|
||||||
result[kv[0]] = ""
|
if defaultEnv {
|
||||||
|
result[kv[0]] = os.Getenv(kv[0])
|
||||||
|
} else {
|
||||||
|
result[kv[0]] = ""
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result[kv[0]] = kv[1]
|
result[kv[0]] = kv[1]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user