mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 17:05:46 +08:00
bake: move SOURCE_DATE_EPOCH parsing to overrides
Previously, when directly modifying the args map when reading targets, we could end up in a scenario where bake tests that compare arg maps would fail if SOURCE_DATE_EPOCH was set in the environment. This patch prevents this failure by setting the SOURCE_DATE_EPOCH at the command level (which isn't injected into tests as well), ensuring that we test correctly even when SOURCE_DATE_EPOCH is set in the environment. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
parent
5d4223e4f8
commit
780531425b
13
bake/bake.go
13
bake/bake.go
@ -140,19 +140,6 @@ func ReadTargets(ctx context.Context, files []File, targets, overrides []string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Propagate SOURCE_DATE_EPOCH from the client env.
|
|
||||||
// The logic is purposely duplicated from `build/build`.go for keeping this visible in `bake --print`.
|
|
||||||
if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" {
|
|
||||||
for _, f := range m {
|
|
||||||
if f.Args == nil {
|
|
||||||
f.Args = make(map[string]*string)
|
|
||||||
}
|
|
||||||
if _, ok := f.Args["SOURCE_DATE_EPOCH"]; !ok {
|
|
||||||
f.Args["SOURCE_DATE_EPOCH"] = &v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, n, nil
|
return m, n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +149,19 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" {
|
||||||
|
// TODO: extract env var parsing to a method easily usable by library consumers
|
||||||
|
for _, t := range tgts {
|
||||||
|
if _, ok := t.Args["SOURCE_DATE_EPOCH"]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if t.Args == nil {
|
||||||
|
t.Args = map[string]*string{}
|
||||||
|
}
|
||||||
|
t.Args["SOURCE_DATE_EPOCH"] = &v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this function can update target context string from the input so call before printOnly check
|
// this function can update target context string from the input so call before printOnly check
|
||||||
bo, err := bake.TargetsToBuildOpt(tgts, inp)
|
bo, err := bake.TargetsToBuildOpt(tgts, inp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user