registry: commit manifest on successful /v1/push

This commit is contained in:
Blake Mizerany 2024-03-31 15:09:04 -07:00
parent c0eddb10fd
commit 04f38cf3f4
2 changed files with 20 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"io/fs"
"os"
"path"
"bllamo.com/build/blob"
"bllamo.com/build/internal/blobstore"
@ -21,6 +22,10 @@ var (
ErrNotFound = errors.New("not found")
)
func ManifestKey(domain string, ref blob.Ref) string {
return path.Join("manifests", domain, ref.Name(), ref.Tag(), ref.Build())
}
type mediaType string
// Known media types

View File

@ -10,6 +10,8 @@ import (
"net/http"
"time"
"bllamo.com/build"
"bllamo.com/build/blob"
"bllamo.com/client/ollama"
"bllamo.com/oweb"
"bllamo.com/registry/apitype"
@ -50,6 +52,11 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) error {
return err
}
ref := blob.ParseRef(pr.Ref)
if !ref.FullyQualified() {
return oweb.Mistake("invalid", "name", "must be fully qualified")
}
mc, err := minio.New("localhost:9000", &minio.Options{
Creds: credentials.NewStaticV4("minioadmin", "minioadmin", ""),
Secure: false,
@ -87,8 +94,14 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) error {
}
}
// TODO(bmizerany): commit to db
// ref, _ := strings.CutPrefix(r.URL.Path, "/v1/push/")
if len(requirements) == 0 {
const cheatTODO = "registry.ollama.ai/library"
key := build.ManifestKey(cheatTODO, ref)
_, err := mc.PutObject(r.Context(), "test", key, bytes.NewReader(pr.Manifest), int64(len(pr.Manifest)), minio.PutObjectOptions{})
if err != nil {
return err
}
}
return oweb.EncodeJSON(w, &apitype.PushResponse{Requirements: requirements})
}