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:
+12
-7
@@ -17,6 +17,7 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/containerd/containerd/v2/pkg/epoch"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/docker/buildx/bake"
|
||||
"github.com/docker/buildx/bake/hclparser"
|
||||
@@ -241,16 +242,20 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
|
||||
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
|
||||
}
|
||||
var sourceDateEpoch *string
|
||||
for _, t := range tgts {
|
||||
if _, ok := t.Args[epoch.SourceDateEpochEnv]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
v := os.Getenv(epoch.SourceDateEpochEnv)
|
||||
sourceDateEpoch = &v
|
||||
|
||||
if *sourceDateEpoch != "" {
|
||||
if t.Args == nil {
|
||||
t.Args = map[string]*string{}
|
||||
}
|
||||
t.Args["SOURCE_DATE_EPOCH"] = &v
|
||||
t.Args[epoch.SourceDateEpochEnv] = sourceDateEpoch
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/containerd/containerd/v2/core/content"
|
||||
"github.com/containerd/containerd/v2/core/content/proxy"
|
||||
"github.com/containerd/containerd/v2/core/images"
|
||||
"github.com/containerd/containerd/v2/pkg/epoch"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/docker/buildx/localstate"
|
||||
"github.com/docker/buildx/util/cobrautil/completion"
|
||||
@@ -392,7 +393,7 @@ workers0:
|
||||
readAttr(attrs, "ulimit", &out.Config.Ulimit, nil)
|
||||
readAttr(attrs, "build-arg:BUILDKIT_CACHE_MOUNT_NS", &out.Config.CacheMountNS, nil)
|
||||
readAttr(attrs, "build-arg:BUILDKIT_DOCKERFILE_CHECK", &out.Config.DockerfileCheckConfig, nil)
|
||||
readAttr(attrs, "build-arg:SOURCE_DATE_EPOCH", &out.Config.SourceDateEpoch, nil)
|
||||
readAttr(attrs, "build-arg:"+epoch.SourceDateEpochEnv, &out.Config.SourceDateEpoch, nil)
|
||||
readAttr(attrs, "build-arg:SANDBOX_HOSTNAME", &out.Config.SandboxHostname, nil)
|
||||
|
||||
var unusedAttrs []keyValueOutput
|
||||
|
||||
Reference in New Issue
Block a user