mirror of
https://github.com/tailscale/tailscale.git
synced 2026-02-11 10:41:43 +01:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
215 lines
5.1 KiB
Go
215 lines
5.1 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
// The sync-containers command synchronizes container image tags from one
|
|
// registry to another.
|
|
//
|
|
// It is intended as a workaround for ghcr.io's lack of good push credentials:
|
|
// you can either authorize "classic" Personal Access Tokens in your org (which
|
|
// are a common vector of very bad compromise), or you can get a short-lived
|
|
// credential in a Github action.
|
|
//
|
|
// Since we publish to both Docker Hub and ghcr.io, we use this program in a
|
|
// Github action to effectively rsync from docker hub into ghcr.io, so that we
|
|
// can continue to forbid dangerous Personal Access Tokens in the tailscale org.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/google/go-containerregistry/pkg/authn"
|
|
"github.com/google/go-containerregistry/pkg/authn/github"
|
|
"github.com/google/go-containerregistry/pkg/name"
|
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
|
"github.com/google/go-containerregistry/pkg/v1/remote"
|
|
"github.com/google/go-containerregistry/pkg/v1/types"
|
|
)
|
|
|
|
var (
|
|
src = flag.String("src", "", "Source image")
|
|
dst = flag.String("dst", "", "Destination image")
|
|
max = flag.Int("max", 0, "Maximum number of tags to sync (0 for all tags)")
|
|
dryRun = flag.Bool("dry-run", true, "Don't actually sync anything")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *src == "" {
|
|
log.Fatalf("--src is required")
|
|
}
|
|
if *dst == "" {
|
|
log.Fatalf("--dst is required")
|
|
}
|
|
|
|
keychain := authn.NewMultiKeychain(authn.DefaultKeychain, github.Keychain)
|
|
opts := []remote.Option{
|
|
remote.WithAuthFromKeychain(keychain),
|
|
remote.WithContext(context.Background()),
|
|
}
|
|
|
|
stags, err := listTags(*src, opts...)
|
|
if err != nil {
|
|
log.Fatalf("listing source tags: %v", err)
|
|
}
|
|
dtags, err := listTags(*dst, opts...)
|
|
if err != nil {
|
|
log.Fatalf("listing destination tags: %v", err)
|
|
}
|
|
|
|
add, remove := diffTags(stags, dtags)
|
|
if ln := len(add); ln > 0 {
|
|
log.Printf("%d tags to push: %s", len(add), strings.Join(add, ", "))
|
|
if *max > 0 && ln > *max {
|
|
log.Printf("Limiting sync to %d tags", *max)
|
|
add = add[:*max]
|
|
}
|
|
}
|
|
for _, tag := range add {
|
|
if !*dryRun {
|
|
log.Printf("Syncing tag %q", tag)
|
|
if err := copyTag(*src, *dst, tag, opts...); err != nil {
|
|
log.Printf("Syncing tag %q: progress error: %v", tag, err)
|
|
}
|
|
} else {
|
|
log.Printf("Dry run: would sync tag %q", tag)
|
|
}
|
|
}
|
|
|
|
if len(remove) > 0 {
|
|
log.Printf("%d tags to remove: %s\n", len(remove), strings.Join(remove, ", "))
|
|
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 {
|
|
src, err := name.ParseReference(fmt.Sprintf("%s:%s", srcStr, tag))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
dst, err := name.ParseReference(fmt.Sprintf("%s:%s", dstStr, tag))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
desc, err := remote.Get(src)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ch := make(chan v1.Update, 10)
|
|
opts = append(opts, remote.WithProgress(ch))
|
|
progressDone := make(chan struct{})
|
|
|
|
go func() {
|
|
defer close(progressDone)
|
|
for p := range ch {
|
|
fmt.Printf("Syncing tag %q: %d%% (%d/%d)\n", tag, int(float64(p.Complete)/float64(p.Total)*100), p.Complete, p.Total)
|
|
if p.Error != nil {
|
|
fmt.Printf("error: %v\n", p.Error)
|
|
}
|
|
}
|
|
}()
|
|
|
|
switch desc.MediaType {
|
|
case types.OCIManifestSchema1, types.DockerManifestSchema2:
|
|
img, err := desc.Image()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := remote.Write(dst, img, opts...); err != nil {
|
|
return err
|
|
}
|
|
case types.OCIImageIndex, types.DockerManifestList:
|
|
idx, err := desc.ImageIndex()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := remote.WriteIndex(dst, idx, opts...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
<-progressDone
|
|
return nil
|
|
}
|
|
|
|
func listTags(repoStr string, opts ...remote.Option) ([]string, error) {
|
|
repo, err := name.NewRepository(repoStr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
tags, err := remote.List(repo, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
sort.Strings(tags)
|
|
return tags, nil
|
|
}
|
|
|
|
func diffTags(src, dst []string) (add, remove []string) {
|
|
srcd := make(map[string]bool)
|
|
for _, tag := range src {
|
|
srcd[tag] = true
|
|
}
|
|
dstd := make(map[string]bool)
|
|
for _, tag := range dst {
|
|
dstd[tag] = true
|
|
}
|
|
|
|
for _, tag := range src {
|
|
if !dstd[tag] {
|
|
add = append(add, tag)
|
|
}
|
|
}
|
|
for _, tag := range dst {
|
|
if !srcd[tag] {
|
|
remove = append(remove, tag)
|
|
}
|
|
}
|
|
sort.Strings(add)
|
|
sort.Strings(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
|
|
}
|