70a93057cd
previous layer creation was not ideal because: 1. it required reading the input file multiple times, once to calculate the sha256 checksum, another to write it to disk, and potentially one more to decode the underlying gguf 2. used io.ReadSeeker which is prone to user error. if the file isn't reset correctly or in the right place, it could end up reading an empty file there are also some brittleness when reading existing layers else writing the inherited layers will error reading an already closed file this commit aims to fix these issues by restructuring layer creation. 1. it will now write the layer to a temporary file as well as the hash function and move it to the final location on Commit 2. layers are read once once when copied to the destination. exception is raw model files which still requires a second read to decode the model metadata
34 lines
681 B
Go
34 lines
681 B
Go
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
|
|
}
|
|
|
|
if err := os.MkdirAll(filepath.Dir(manifestPath), 0755); err != nil {
|
|
return err
|
|
}
|
|
|
|
return os.WriteFile(manifestPath, b.Bytes(), 0644)
|
|
}
|