bake: SOURCE_DATE_EPOCH: fix `panic: assignment to entry in nil map`

Fix issue 1562

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2023-01-29 08:42:47 +09:00
parent a718d07f64
commit 1f56f51740
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A
1 changed files with 3 additions and 0 deletions

View File

@ -144,6 +144,9 @@ func ReadTargets(ctx context.Context, files []File, targets, overrides []string,
// 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
}