Will Norris 3ec5be3f51 all: remove AUTHORS file and references to it
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>
2026-01-23 15:49:45 -08:00

278 lines
8.6 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
// Package qnap contains dist Targets for building QNAP Tailscale packages.
//
// QNAP dev docs over at https://www.qnap.com/en/how-to/tutorial/article/qpkg-development-guidelines.
package qnap
import (
"embed"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"path/filepath"
"slices"
"sync"
"tailscale.com/release/dist"
)
type target struct {
goenv map[string]string
arch string
signer *signer
}
type signer struct {
gcloudCredentialsBase64 string
gcloudProject string
gcloudKeyring string
keyName string
certificateBase64 string
certificateIntermediariesBase64 string
}
func (t *target) String() string {
return fmt.Sprintf("qnap/%s", t.arch)
}
func (t *target) Build(b *dist.Build) ([]string, error) {
// Stop early if we don't have docker running.
if _, err := exec.LookPath("docker"); err != nil {
return nil, fmt.Errorf("docker not found, cannot build: %w", err)
}
qnapBuilds := getQnapBuilds(b, t.signer)
inner, err := qnapBuilds.buildInnerPackage(b, t.goenv)
if err != nil {
return nil, err
}
return t.buildQPKG(b, qnapBuilds, inner)
}
const (
qnapTag = "1" // currently static, we don't seem to bump this
)
func (t *target) buildQPKG(b *dist.Build, qnapBuilds *qnapBuilds, inner *innerPkg) ([]string, error) {
if _, err := exec.LookPath("docker"); err != nil {
return nil, fmt.Errorf("docker not found, cannot build: %w", err)
}
if err := qnapBuilds.makeDockerImage(b); err != nil {
return nil, fmt.Errorf("makeDockerImage: %w", err)
}
filename := fmt.Sprintf("Tailscale_%s-%s_%s.qpkg", b.Version.Short, qnapTag, t.arch)
filePath := filepath.Join(b.Out, filename)
args := []string{"run", "--rm",
"--network=host",
"-e", fmt.Sprintf("ARCH=%s", t.arch),
"-e", fmt.Sprintf("TSTAG=%s", b.Version.Short),
"-e", fmt.Sprintf("QNAPTAG=%s", qnapTag),
"-v", fmt.Sprintf("%s:/tailscale", inner.tailscalePath),
"-v", fmt.Sprintf("%s:/tailscaled", inner.tailscaledPath),
// Tailscale folder has QNAP package setup files needed for building.
"-v", fmt.Sprintf("%s:/Tailscale", filepath.Join(qnapBuilds.tmpDir, "files/Tailscale")),
"-v", fmt.Sprintf("%s:/build-qpkg.sh", filepath.Join(qnapBuilds.tmpDir, "files/scripts/build-qpkg.sh")),
"-v", fmt.Sprintf("%s:/out", b.Out),
}
if t.signer != nil {
log.Println("Will sign with Google Cloud HSM")
args = append(args,
"-e", fmt.Sprintf("GCLOUD_CREDENTIALS_BASE64=%s", t.signer.gcloudCredentialsBase64),
"-e", fmt.Sprintf("GCLOUD_PROJECT=%s", t.signer.gcloudProject),
"-e", fmt.Sprintf("GCLOUD_KEYRING=%s", t.signer.gcloudKeyring),
"-e", fmt.Sprintf("QNAP_SIGNING_KEY_NAME=%s", t.signer.keyName),
"-e", fmt.Sprintf("QNAP_SIGNING_CERT_BASE64=%s", t.signer.certificateBase64),
"-e", fmt.Sprintf("QNAP_SIGNING_CERT_INTERMEDIARIES_BASE64=%s", t.signer.certificateIntermediariesBase64),
"-e", fmt.Sprintf("QNAP_SIGNING_SCRIPT=%s", "/sign-qpkg.sh"),
"-v", fmt.Sprintf("%s:/sign-qpkg.sh", filepath.Join(qnapBuilds.tmpDir, "files/scripts/sign-qpkg.sh")),
)
}
args = append(args,
"build.tailscale.io/qdk:latest",
"/build-qpkg.sh",
)
cmd := b.Command(b.Repo, "docker", args...)
// dist.Build runs target builds in parallel goroutines by default.
// For QNAP, this is an issue because the underlaying qbuild builder will
// create tmp directories in the shared docker image that end up conflicting
// with one another.
// So we use a mutex to only allow one "docker run" at a time.
qnapBuilds.dockerImageMu.Lock()
defer qnapBuilds.dockerImageMu.Unlock()
log.Printf("Building %s", filePath)
out, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("docker run %v: %s", err, out)
}
return []string{filePath, filePath + ".md5"}, nil
}
type qnapBuildsMemoizeKey struct{}
type innerPkg struct {
tailscalePath string
tailscaledPath string
}
// qnapBuilds holds extra build context shared by all qnap builds.
type qnapBuilds struct {
// innerPkgs contains per-goenv compiled binary paths.
// It is used to avoid repeated compilations for the same architecture.
innerPkgs dist.Memoize[*innerPkg]
dockerImageMu sync.Mutex
// tmpDir is a temp directory used for building qpkgs.
// It gets cleaned up when the dist.Build is closed.
tmpDir string
}
// getQnapBuilds returns the qnapBuilds for b, creating one if needed.
func getQnapBuilds(b *dist.Build, signer *signer) *qnapBuilds {
return b.Extra(qnapBuildsMemoizeKey{}, func() any {
builds, err := newQNAPBuilds(b, signer)
if err != nil {
panic(fmt.Errorf("setUpTmpDir: %v", err))
}
return builds
}).(*qnapBuilds)
}
//go:embed all:files
var buildFiles embed.FS
// newQNAPBuilds creates a new qnapBuilds instance to hold context shared by
// all qnap targets, and sets up its local temp directory used for building.
//
// The qnapBuilds.tmpDir is filled with the contents of the buildFiles embedded
// FS for building.
//
// We do this to allow for this tailscale.com/release/dist/qnap package to be
// used from both the corp and OSS repos. When built from OSS source directly,
// this is a superfluous extra step, but when imported as a go module to another
// repo (such as corp), we must do this to allow for the module's build files
// to be reachable and editable from docker.
//
// This runs only once per dist.Build instance, is shared by all qnap targets,
// and gets cleaned up upon close of the dist.Build.
//
// When a signer is provided, newQNAPBuilds also sets up the qpkg signature
// files in qbuild's expected location within m.tmpDir.
func newQNAPBuilds(b *dist.Build, signer *signer) (*qnapBuilds, error) {
m := new(qnapBuilds)
log.Print("Setting up qnap tmp build directory")
m.tmpDir = filepath.Join(b.Repo, "tmp-qnap-build")
b.AddOnCloseFunc(func() error {
return os.RemoveAll(m.tmpDir)
})
if err := fs.WalkDir(buildFiles, "files", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
outPath := filepath.Join(m.tmpDir, path)
if d.IsDir() {
return os.MkdirAll(outPath, 0755)
}
file, err := fs.ReadFile(buildFiles, path)
if err != nil {
return err
}
perm := fs.FileMode(0644)
if slices.Contains([]string{".sh", ".cgi"}, filepath.Ext(path)) {
perm = 0755
}
return os.WriteFile(outPath, file, perm)
}); err != nil {
return nil, err
}
return m, nil
}
// buildInnerPackage builds the go binaries used for qnap packages.
// These binaries get embedded with Tailscale package metadata to form qnap
// releases.
func (m *qnapBuilds) buildInnerPackage(b *dist.Build, goenv map[string]string) (*innerPkg, error) {
return m.innerPkgs.Do(goenv, func() (*innerPkg, error) {
if err := b.BuildWebClientAssets(); err != nil {
return nil, err
}
ts, err := b.BuildGoBinary("tailscale.com/cmd/tailscale", goenv)
if err != nil {
return nil, err
}
tsd, err := b.BuildGoBinary("tailscale.com/cmd/tailscaled", goenv)
if err != nil {
return nil, err
}
// The go binaries above get built and put into a /tmp directory created
// by b.TmpDir(). But, we build QNAP with docker, which doesn't always
// allow for mounting tmp directories (seemingly dependent on docker
// host).
// https://stackoverflow.com/questions/65267251/docker-bind-mount-directory-in-tmp-not-working
//
// So here, we move the binaries into a directory within the b.Repo
// path and clean it up when the builder closes.
tmpDir := filepath.Join(m.tmpDir, fmt.Sprintf("/binaries-%s-%s-%s", b.Version.Short, goenv["GOOS"], goenv["GOARCH"]))
if err = os.MkdirAll(tmpDir, 0755); err != nil {
return nil, err
}
b.AddOnCloseFunc(func() error {
return os.RemoveAll(tmpDir)
})
tsBytes, err := os.ReadFile(ts)
if err != nil {
return nil, err
}
tsdBytes, err := os.ReadFile(tsd)
if err != nil {
return nil, err
}
tsPath := filepath.Join(tmpDir, "tailscale")
if err := os.WriteFile(tsPath, tsBytes, 0755); err != nil {
return nil, err
}
tsdPath := filepath.Join(tmpDir, "tailscaled")
if err := os.WriteFile(tsdPath, tsdBytes, 0755); err != nil {
return nil, err
}
return &innerPkg{tailscalePath: tsPath, tailscaledPath: tsdPath}, nil
})
}
func (m *qnapBuilds) makeDockerImage(b *dist.Build) error {
return b.Once("make-qnap-docker-image", func() error {
log.Printf("Building qnapbuilder docker image")
cmd := b.Command(b.Repo, "docker", "build",
"-f", filepath.Join(m.tmpDir, "files/scripts/Dockerfile.qpkg"),
"-t", "build.tailscale.io/qdk:latest",
filepath.Join(m.tmpDir, "files/scripts"),
)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("docker build %v: %s", err, out)
}
return nil
})
}