commands: micro optimization for source date epoch

Avoids the call to `os.Getenv` when it is unnecessary because it would
be overwritten anyway.

Removes the comments about moving environment variable parsing to a
method for use by library consumers. That method exists in containerd
and this set of code doesn't actually perform any parsing since the
parsing of this time is done within buildkit and not on the client.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2026-04-03 10:02:50 -05:00
parent 6bde7f2320
commit d781c83cec
6 changed files with 127 additions and 12 deletions
+4 -4
View File
@@ -18,6 +18,7 @@ import (
"time"
"github.com/containerd/console"
"github.com/containerd/containerd/v2/pkg/epoch"
"github.com/docker/buildx/build"
"github.com/docker/buildx/builder"
"github.com/docker/buildx/store"
@@ -139,10 +140,9 @@ func (o *buildOptions) toOptions() (*BuildOptions, error) {
ExportLoad: o.exportLoad,
}
// TODO: extract env var parsing to a method easily usable by library consumers
if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" {
if _, ok := opts.BuildArgs["SOURCE_DATE_EPOCH"]; !ok {
opts.BuildArgs["SOURCE_DATE_EPOCH"] = v
if _, ok := opts.BuildArgs[epoch.SourceDateEpochEnv]; !ok {
if v := os.Getenv(epoch.SourceDateEpochEnv); v != "" {
opts.BuildArgs[epoch.SourceDateEpochEnv] = v
}
}