From 149bf968f54afa65af6305c21cabe6c3cdda616c Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 23 Jun 2025 11:19:06 -0400 Subject: [PATCH] Accept SOURCE_DATE_EPOCH as a build-arg When SOURCE_DATE_EPOCH is passed in as a build-arg, treat it as we would if it was passed in via the environment or its own CLI flag. Signed-off-by: Nalin Dahyabhai --- imagebuildah/build.go | 10 ++++++++++ tests/bud.bats | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/imagebuildah/build.go b/imagebuildah/build.go index 7424cddc9..eb3c5e240 100644 --- a/imagebuildah/build.go +++ b/imagebuildah/build.go @@ -17,6 +17,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/containerd/platforms" "github.com/containers/buildah" @@ -219,6 +220,15 @@ func BuildDockerfiles(ctx context.Context, store storage.Store, options define.B } } + if sourceDateEpoch, ok := options.Args[internal.SourceDateEpochName]; ok && options.SourceDateEpoch == nil { + sde, err := strconv.ParseInt(sourceDateEpoch, 10, 64) + if err != nil { + return "", nil, fmt.Errorf("parsing SOURCE_DATE_EPOCH build-arg %q: %w", sourceDateEpoch, err) + } + sdeTime := time.Unix(sde, 0) + options.SourceDateEpoch = &sdeTime + } + systemContext := options.SystemContext for _, platform := range options.Platforms { platformContext := *systemContext diff --git a/tests/bud.bats b/tests/bud.bats index b1fb98993..3d1ba7266 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -8117,3 +8117,32 @@ _EOF fi done } + +@test "bud-with-source-date-epoch-arg" { + _prefetch busybox + local timestamp=60 + local datestamp="1970-01-01T00:01:00Z" + mkdir -p $TEST_SCRATCH_DIR/buildcontext + cat > $TEST_SCRATCH_DIR/buildcontext/Dockerfile <