Update taglist for real

This commit is contained in:
Quentin 2023-05-03 10:51:36 +02:00
parent 29b6a209a4
commit f2e3de4b5d
Signed by: quentin
GPG key ID: E9602264D639FF68

View file

@ -475,8 +475,67 @@ func NewStaticRegistryManager(buck *blob.Bucket, name string) *StaticRegistryMan
} }
} }
type TagList struct {
Name string `json:"name"`
Tags []string `json:"tags"`
}
func (l *StaticRegistryManager) ComputeTagList() (TagList, error) {
digestPrefix := "sha256:"
cutDigestPrefix := len(digestPrefix)
tagList := TagList{
Name: l.name,
}
iter := l.buck.List(&blob.ListOptions{
Prefix: fmt.Sprintf("v2/%s/manifests/", l.name),
Delimiter: "/",
})
for {
obj, err := iter.Next(context.Background())
if err == io.EOF {
break
}
if err != nil {
return tagList, err
}
ksplit := strings.Split(obj.Key, "/")
if len(ksplit) < 1 {
return tagList, errors.New(fmt.Sprintf("Invalid key name %s", obj.Key))
}
fname := ksplit[len(ksplit)-1]
if len(fname) >= cutDigestPrefix && fname[:cutDigestPrefix] == digestPrefix {
// we ignore sha256 addressed manifests
continue
}
tagList.Tags = append(tagList.Tags, fname)
}
return tagList, nil
}
func (l *StaticRegistryManager) UpdateTagList() error { func (l *StaticRegistryManager) UpdateTagList() error {
fmt.Println("Not yet implemented") fmt.Printf("--- update taglist ---\n")
tagList, err := l.ComputeTagList()
if err != nil {
return err
}
fmt.Printf("computed tag list: %v\n", tagList)
txt, err := json.Marshal(tagList)
if err != nil {
return err
}
dst := path.Join("v2", l.name, "tags", "list")
err = NewUploadFromByte(l.buck, txt).ContentType("application/json").UploadTo(dst)
if err != nil {
return err
}
fmt.Printf("taglist -> %s\n", dst)
return nil return nil
} }
@ -504,7 +563,7 @@ var containerPublishCmd = &cobra.Command{
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
//defer oi.Close() defer oi.Close()
if err = oi.LoadFromDockerArchives(localPath); err != nil { if err = oi.LoadFromDockerArchives(localPath); err != nil {
fmt.Println(err) fmt.Println(err)