cmd/sync-containers: update latest and stable tags

Fixes https://github.com/tailscale/tailscale/issues/7251

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
pull/7254/head
Denton Gentry 2 years ago committed by Denton Gentry
parent fa932fefe7
commit 5bca44d572

@ -85,6 +85,15 @@ func main() {
log.Printf("%d tags to remove: %s\n", len(remove), strings.Join(remove, ", ")) log.Printf("%d tags to remove: %s\n", len(remove), strings.Join(remove, ", "))
log.Printf("Not removing any tags for safety.\n") log.Printf("Not removing any tags for safety.\n")
} }
var wellKnown = [...]string{"latest", "stable"}
for _, tag := range wellKnown {
if needsUpdate(*src, *dst, tag) {
if err := copyTag(*src, *dst, tag, opts...); err != nil {
log.Printf("Updating tag %q: progress error: %v", tag, err)
}
}
}
} }
func copyTag(srcStr, dstStr, tag string, opts ...remote.Option) error { func copyTag(srcStr, dstStr, tag string, opts ...remote.Option) error {
@ -178,3 +187,26 @@ func diffTags(src, dst []string) (add, remove []string) {
sort.Strings(remove) sort.Strings(remove)
return add, remove return add, remove
} }
func needsUpdate(srcStr, dstStr, tag string) bool {
src, err := name.ParseReference(fmt.Sprintf("%s:%s", srcStr, tag))
if err != nil {
return false
}
dst, err := name.ParseReference(fmt.Sprintf("%s:%s", dstStr, tag))
if err != nil {
return false
}
srcDesc, err := remote.Get(src)
if err != nil {
return false
}
dstDesc, err := remote.Get(dst)
if err != nil {
return true
}
return srcDesc.Digest != dstDesc.Digest
}

Loading…
Cancel
Save