Update taglist for real
This commit is contained in:
parent
29b6a209a4
commit
f2e3de4b5d
1 changed files with 61 additions and 2 deletions
|
@ -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 {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -504,7 +563,7 @@ var containerPublishCmd = &cobra.Command{
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
//defer oi.Close()
|
||||
defer oi.Close()
|
||||
|
||||
if err = oi.LoadFromDockerArchives(localPath); err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
Loading…
Reference in a new issue