Skip to content

Commit 2667fac

Browse files
leodidoona-agent
andcommitted
fix(docker): use deterministic timestamp in docker-export-metadata.json
Use getDeterministicMtime() for BuildTime in docker-export-metadata.json instead of time.Now() to ensure deterministic metadata files. This makes the docker-export-metadata.json file reproducible across builds with the same source code, reducing non-determinism in exported Docker image cache archives. The timestamp is derived from: - Git commit timestamp (normal case) - SOURCE_DATE_EPOCH env var (override) - Returns 0 in test environments Co-authored-by: Ona <no-reply@ona.com>
1 parent d153ac3 commit 2667fac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/leeway/build.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,11 @@ func (p *Package) buildDocker(buildctx *buildContext, wd, result string) (res *p
22212221

22222222
// Add PostProcess to create structured metadata file
22232223
res.PostProcess = func(buildCtx *buildContext, pkg *Package, buildDir string) error {
2224-
return createDockerExportMetadata(buildDir, version, cfg)
2224+
mtime, err := pkg.getDeterministicMtime()
2225+
if err != nil {
2226+
return fmt.Errorf("failed to get deterministic mtime: %w", err)
2227+
}
2228+
return createDockerExportMetadata(buildDir, version, cfg, mtime)
22252229
}
22262230

22272231
// Add subjects function for provenance generation
@@ -2367,11 +2371,11 @@ type DockerImageMetadata struct {
23672371
}
23682372

23692373
// createDockerExportMetadata creates metadata file for exported Docker images
2370-
func createDockerExportMetadata(wd, version string, cfg DockerPkgConfig) error {
2374+
func createDockerExportMetadata(wd, version string, cfg DockerPkgConfig, mtime int64) error {
23712375
metadata := DockerImageMetadata{
23722376
ImageNames: cfg.Image,
23732377
BuiltVersion: version,
2374-
BuildTime: time.Now(),
2378+
BuildTime: time.Unix(mtime, 0),
23752379
CustomMeta: cfg.Metadata,
23762380
}
23772381

0 commit comments

Comments
 (0)