Skip to content

Commit 44c1468

Browse files
committed
fix: generate unique config when build model artifact
Signed-off-by: chlins <[email protected]>
1 parent 17ca99a commit 44c1468

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pkg/backend/build/build.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24+
"time"
2425

2526
modelspec "github.com/CloudNativeAI/modctl/pkg/spec"
2627
"github.com/CloudNativeAI/modctl/pkg/storage"
@@ -30,12 +31,10 @@ import (
3031
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3132
)
3233

33-
// DescriptorEmptyJSON is the descriptor of a blob with content of `{}`.
34-
var DescriptorEmptyJSON = ocispec.Descriptor{
35-
MediaType: ocispec.MediaTypeImageConfig,
36-
Digest: `sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a`,
37-
Size: 2,
38-
Data: []byte(`{}`),
34+
// ModelConfig is a configuration that corresponds to the image config in the image spec.
35+
type ModelConfig struct {
36+
// Created is the time when the model image is created.
37+
Created string `json:"Created"`
3938
}
4039

4140
// BuildLayer converts the file to the image blob and push it to the storage.
@@ -60,13 +59,25 @@ func BuildLayer(ctx context.Context, store storage.Storage, repo, path string) (
6059

6160
// BuildConfig builds the image config and push it to the storage.
6261
func BuildConfig(ctx context.Context, store storage.Storage, repo string) (ocispec.Descriptor, error) {
63-
// by default using the empty JSON config.
64-
_, _, err := store.PushBlob(ctx, repo, bytes.NewReader(DescriptorEmptyJSON.Data))
62+
config := &ModelConfig{
63+
Created: time.Now().Format(time.RFC3339Nano),
64+
}
65+
configJSON, err := json.Marshal(config)
66+
if err != nil {
67+
return ocispec.Descriptor{}, fmt.Errorf("failed to marshal config: %w", err)
68+
}
69+
70+
digest, size, err := store.PushBlob(ctx, repo, bytes.NewReader(configJSON))
6571
if err != nil {
6672
return ocispec.Descriptor{}, fmt.Errorf("failed to push config to storage: %w", err)
6773
}
6874

69-
return DescriptorEmptyJSON, nil
75+
return ocispec.Descriptor{
76+
// reuse the image config media type for runtime compatibility.
77+
MediaType: ocispec.MediaTypeImageConfig,
78+
Size: size,
79+
Digest: godigest.Digest(digest),
80+
}, nil
7081
}
7182

7283
// BuildManifest builds the manifest and push it to the storage.

0 commit comments

Comments
 (0)