Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Add PutManifestV2 convenience method to upload schema2 manifests #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (registry *Registry) DeleteManifest(repository string, digest digest.Digest
return nil
}

// PutManifest uploads manifest to the given repository/reference.
// Manifest is typically either of type schema2.DeserializedManifest or schema1.SignedManifest
func (registry *Registry) PutManifest(repository, reference string, manifest distribution.Manifest) error {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.put url=%s repository=%s reference=%s", url, repository, reference)
Expand All @@ -124,3 +126,19 @@ func (registry *Registry) PutManifest(repository, reference string, manifest dis
}
return err
}

// PutManifestV2 uploads the given schama2.Manifest to the given repository/reference and returns with its digest.
// If you want to upload a schema2.DeserializedManifest, please use the generic PutManifest().
func (registry *Registry) PutManifestV2(repository, reference string, manifest *schema2.Manifest) (digest.Digest, error) {
deserializedManifest, err := schema2.FromStruct(*manifest)
if err != nil {
return "", err
}
_, canonical, err := deserializedManifest.Payload()
if err != nil {
return "", err
}
digest := digest.FromBytes(canonical)
err = registry.PutManifest(repository, reference, deserializedManifest)
return digest, err
}