diff --git a/server/images.go b/server/images.go index e949fb18..447a63a6 100644 --- a/server/images.go +++ b/server/images.go @@ -135,13 +135,6 @@ type Message struct { Content string `json:"content"` } -type ManifestV2 struct { - SchemaVersion int `json:"schemaVersion"` - MediaType string `json:"mediaType"` - Config *Layer `json:"config"` - Layers []*Layer `json:"layers"` -} - type ConfigV2 struct { ModelFormat string `json:"model_format"` ModelFamily string `json:"model_family"` @@ -160,7 +153,7 @@ type RootFS struct { DiffIDs []string `json:"diff_ids"` } -func GetManifest(mp ModelPath) (*ManifestV2, string, error) { +func GetManifest(mp ModelPath) (*Manifest, string, error) { fp, err := mp.GetManifestPath() if err != nil { return nil, "", err @@ -170,7 +163,7 @@ func GetManifest(mp ModelPath) (*ManifestV2, string, error) { return nil, "", err } - var manifest *ManifestV2 + var manifest *Manifest bts, err := os.ReadFile(fp) if err != nil { @@ -822,7 +815,7 @@ func PushModel(ctx context.Context, name string, regOpts *registryOptions, fn fu func PullModel(ctx context.Context, name string, regOpts *registryOptions, fn func(api.ProgressResponse)) error { mp := ParseModelPath(name) - var manifest *ManifestV2 + var manifest *Manifest var err error var noprune string @@ -929,7 +922,7 @@ func PullModel(ctx context.Context, name string, regOpts *registryOptions, fn fu return nil } -func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *registryOptions) (*ManifestV2, error) { +func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *registryOptions) (*Manifest, error) { requestURL := mp.BaseURL().JoinPath("v2", mp.GetNamespaceRepository(), "manifests", mp.Tag) headers := make(http.Header) @@ -940,7 +933,7 @@ func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *registryOptio } defer resp.Body.Close() - var m *ManifestV2 + var m *Manifest if err := json.NewDecoder(resp.Body).Decode(&m); err != nil { return nil, err } diff --git a/server/manifest.go b/server/manifest.go index 61dd1ab4..726bb48d 100644 --- a/server/manifest.go +++ b/server/manifest.go @@ -14,7 +14,10 @@ import ( ) type Manifest struct { - ManifestV2 + SchemaVersion int `json:"schemaVersion"` + MediaType string `json:"mediaType"` + Config *Layer `json:"config"` + Layers []*Layer `json:"layers"` filepath string fi os.FileInfo @@ -66,7 +69,7 @@ func ParseNamedManifest(n model.Name) (*Manifest, error) { p := filepath.Join(manifests, n.Filepath()) - var m ManifestV2 + var m Manifest f, err := os.Open(p) if err != nil { return nil, err @@ -83,12 +86,11 @@ func ParseNamedManifest(n model.Name) (*Manifest, error) { return nil, err } - return &Manifest{ - ManifestV2: m, - filepath: p, - fi: fi, - digest: fmt.Sprintf("%x", sha256sum.Sum(nil)), - }, nil + m.filepath = p + m.fi = fi + m.digest = fmt.Sprintf("%x", sha256sum.Sum(nil)) + + return &m, nil } func WriteManifest(name model.Name, config *Layer, layers []*Layer) error { @@ -108,7 +110,7 @@ func WriteManifest(name model.Name, config *Layer, layers []*Layer) error { } defer f.Close() - m := ManifestV2{ + m := Manifest{ SchemaVersion: 2, MediaType: "application/vnd.docker.distribution.manifest.v2+json", Config: config, diff --git a/server/manifest_test.go b/server/manifest_test.go index ceee31d8..ca6c3d2e 100644 --- a/server/manifest_test.go +++ b/server/manifest_test.go @@ -25,7 +25,7 @@ func createManifest(t *testing.T, path, name string) { } defer f.Close() - if err := json.NewEncoder(f).Encode(ManifestV2{}); err != nil { + if err := json.NewEncoder(f).Encode(Manifest{}); err != nil { t.Fatal(err) } }