Skip to content

Commit 50746ae

Browse files
authored
feat(build): add flag to omit creation timestamp for reproducible builds (#277)
Signed-off-by: chlins <[email protected]>
1 parent 1b60837 commit 50746ae

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

cmd/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func init() {
6262
// TODO: set the raw flag to true by default in future.
6363
flags.BoolVar(&buildConfig.Raw, "raw", false, "turning on this flag will build model artifact layers in raw format")
6464
flags.BoolVar(&buildConfig.Reasoning, "reasoning", false, "turning on this flag will mark this model as reasoning model in the config")
65+
flags.BoolVar(&buildConfig.NoCreationTime, "no-creation-time", false, "turning on this flag will not set createdAt in the config, which will be helpful for repeated builds")
6566

6667
if err := viper.BindPFlags(flags); err != nil {
6768
panic(fmt.Errorf("bind cache list flags to viper: %w", err))

pkg/backend/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (b *backend) Build(ctx context.Context, modelfilePath, workDir, target stri
113113
SourceURL: sourceInfo.URL,
114114
SourceRevision: revision,
115115
Reasoning: cfg.Reasoning,
116+
NoCreationTime: cfg.NoCreationTime,
116117
}, layers)
117118
if err != nil {
118119
return fmt.Errorf("failed to build model config: %w", err)

pkg/backend/build/builder.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,18 @@ func BuildModelConfig(modelConfig *buildconfig.Model, layers []ocispec.Descripto
257257
}
258258
}
259259

260-
createdAt := time.Now()
261260
descriptor := modelspec.ModelDescriptor{
262-
CreatedAt: &createdAt,
263261
Family: modelConfig.Family,
264262
Name: modelConfig.Name,
265263
SourceURL: modelConfig.SourceURL,
266264
Revision: modelConfig.SourceRevision,
267265
}
268266

267+
if !modelConfig.NoCreationTime {
268+
createdAt := time.Now()
269+
descriptor.CreatedAt = &createdAt
270+
}
271+
269272
diffIDs := make([]godigest.Digest, 0, len(layers))
270273
for _, layer := range layers {
271274
diffIDs = append(diffIDs, layer.Digest)

pkg/backend/build/config/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ type Model struct {
2828
SourceURL string
2929
SourceRevision string
3030
Reasoning bool
31+
NoCreationTime bool
3132
}

pkg/config/build.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Build struct {
3535
SourceRevision string
3636
Raw bool
3737
Reasoning bool
38+
NoCreationTime bool
3839
}
3940

4041
func NewBuild() *Build {
@@ -50,6 +51,7 @@ func NewBuild() *Build {
5051
SourceRevision: "",
5152
Raw: false,
5253
Reasoning: false,
54+
NoCreationTime: false,
5355
}
5456
}
5557

0 commit comments

Comments
 (0)