From 0e6f5a155edb9abad48cd8fc12e7585b571ffa37 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 21 Dec 2022 09:47:13 +0900 Subject: [PATCH] Propagate SOURCE_DATE_EPOCH from the client env Signed-off-by: Akihiro Suda --- bake/bake.go | 10 ++++++++++ build/build.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/bake/bake.go b/bake/bake.go index 06efe9a3..3494b1e1 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -140,6 +140,16 @@ 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 _, ok := f.Args["SOURCE_DATE_EPOCH"]; !ok { + f.Args["SOURCE_DATE_EPOCH"] = &v + } + } + } + return m, n, nil } diff --git a/build/build.go b/build/build.go index 1fc679b7..58b75141 100644 --- a/build/build.go +++ b/build/build.go @@ -579,6 +579,13 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op } } + // Propagate SOURCE_DATE_EPOCH from the client env + if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" { + if _, ok := so.FrontendAttrs["build-arg:SOURCE_DATE_EPOCH"]; !ok { + so.FrontendAttrs["build-arg:SOURCE_DATE_EPOCH"] = v + } + } + if len(opt.Attests) > 0 { if !bopts.LLBCaps.Contains(apicaps.CapID("exporter.image.attestations")) { return nil, nil, errors.Errorf("attestations are not supported by the current buildkitd")