From 628f1feb3686a7525d582dc4851ca1bf7fc6d6fd Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Mon, 1 Apr 2024 23:16:18 -0700 Subject: [PATCH] build: back to taking manifests as []byte Its nicer to have the manifests be an opaque []byte, rather than a struct. This way users of the build package don't need to know about the internal structure of the manifests. The registry can interpret the manifests as it sees fit, while letting build keep its own Go type of manifest which is easier to work with in the build package. --- build/build.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/build/build.go b/build/build.go index 9f80820d..d26718a7 100644 --- a/build/build.go +++ b/build/build.go @@ -92,9 +92,14 @@ func (s *Server) Build(ref string, f model.File) error { Size: size, }) + data, err := json.Marshal(manifestJSON{Layers: layers}) + if err != nil { + return err + } + return s.setManifestData( br.WithBuild(info.FileType.String()), - Manifest{Layers: layers}, + data, ) } @@ -161,20 +166,16 @@ func (s *Server) resolve(ref blob.Ref) (data []byte, path string, err error) { return data, path, nil } -func (s *Server) SetManifestData(ref string, m Manifest) error { +func (s *Server) SetManifestData(ref string, data []byte) error { br, err := parseCompleteRef(ref) if err != nil { return err } - return s.setManifestData(br, m) + return s.setManifestData(br, data) } // Set sets the data for the given ref. -func (s *Server) setManifestData(br blob.Ref, m Manifest) error { - data, err := json.Marshal(m) - if err != nil { - return err - } +func (s *Server) setManifestData(br blob.Ref, data []byte) error { path, err := s.refFileName(br) if err != nil { return err @@ -195,7 +196,7 @@ func (s *Server) refFileName(ref blob.Ref) (string, error) { return filepath.Join(s.st.Dir(), "manifests", filepath.Join(ref.Parts()...)), nil } -type Manifest struct { +type manifestJSON struct { // Layers is the list of layers in the manifest. Layers []layerJSON `json:"layers"` } @@ -208,14 +209,14 @@ type layerJSON struct { Size int64 `json:"size"` } -func (s *Server) getManifest(ref blob.Ref) (Manifest, error) { +func (s *Server) getManifest(ref blob.Ref) (manifestJSON, error) { data, path, err := s.resolve(ref) if err != nil { - return Manifest{}, err + return manifestJSON{}, err } - var m Manifest + var m manifestJSON if err := json.Unmarshal(data, &m); err != nil { - return Manifest{}, &fs.PathError{Op: "unmarshal", Path: path, Err: err} + return manifestJSON{}, &fs.PathError{Op: "unmarshal", Path: path, Err: err} } return m, nil }