2023-11-22 21:28:49 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func WriteManifest(name string, config *Layer, layers []*Layer) error {
|
|
|
|
manifest := ManifestV2{
|
|
|
|
SchemaVersion: 2,
|
|
|
|
MediaType: "application/vnd.docker.distribution.manifest.v2+json",
|
|
|
|
Config: config,
|
|
|
|
Layers: layers,
|
|
|
|
}
|
|
|
|
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := json.NewEncoder(&b).Encode(manifest); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
modelpath := ParseModelPath(name)
|
|
|
|
manifestPath, err := modelpath.GetManifestPath()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-12-15 22:25:12 +00:00
|
|
|
if err := os.MkdirAll(filepath.Dir(manifestPath), 0o755); err != nil {
|
2023-11-22 21:28:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-12-15 22:25:12 +00:00
|
|
|
return os.WriteFile(manifestPath, b.Bytes(), 0o644)
|
2023-11-22 21:28:49 +00:00
|
|
|
}
|