mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
Move the container image build logic out of the e2e test setup into cmd/k8s-operator/e2e/internal/build, with a thin CLI wrapper at cmd/k8s-operator/e2e/build, so CI can publish images once per commit and fan out into multiple test jobs that consume them. The command skips images that already exist in the registry, so a retried run doesn't fail if the registry is immutable. Also adds support for the test harness leveraging workload identity federation credentials so we can use GitHub's token issuer for the test code itself, and AWS' OIDC provider for the operator, and avoid using any secrets in CI. Updates tailscale/corp#46577 Signed-off-by: Tom Proctor <[email protected]>
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
// The build command builds and pushes the container images used by the
|
|
// k8s-operator e2e tests, skipping any that already exist in the registry.
|
|
// It exists so CI can publish images once for a commit and fan out into
|
|
// multiple test jobs that run against them (see --registry without --build
|
|
// in the e2e package docs), and so a failed run can be retried even though
|
|
// the registry rejects tag overwrites.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"syscall"
|
|
|
|
"tailscale.com/cmd/k8s-operator/e2e/internal/build"
|
|
)
|
|
|
|
var (
|
|
fRegistry = flag.String("registry", "", "registry to push images to (required)")
|
|
fTag = flag.String("tag", "", "tag for the built images; defaults to the short git hash of HEAD, which requires a clean working tree")
|
|
fArch = flag.String("arch", "", "target node architecture, e.g. amd64; defaults to building all platforms")
|
|
fBaseImage = flag.String("base-image", "", "if set, use this image as the base for all built images, instead of the default base image in build_docker.sh")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
if *fRegistry == "" {
|
|
log.Fatalf("--registry is required")
|
|
}
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
|
|
defer cancel()
|
|
|
|
dir, err := build.RepoRoot()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
tag := *fTag
|
|
if tag == "" {
|
|
var dirty bool
|
|
tag, dirty, err = build.Tag(dir)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if dirty {
|
|
// A dirty tree gets a random tag suffix, so the test jobs that
|
|
// derive the tag from the commit would never find these images.
|
|
log.Fatalf("working tree is dirty; commit your changes or pass an explicit --tag")
|
|
}
|
|
}
|
|
|
|
// Bake in pebble's static CA so images can fetch certs from a pebble
|
|
// ACME server when the tests run with --devcontrol. Unconditional
|
|
// because it's harmless when testing against real control, and keeps
|
|
// the images independent of how the test jobs will use them.
|
|
minica := filepath.Join(dir, "cmd", "k8s-operator", "e2e", "certs", "pebble.minica.crt")
|
|
if _, err := os.Stat(minica); err != nil {
|
|
log.Fatalf("pebble CA cert not found (not a tailscale.com checkout?): %v", err)
|
|
}
|
|
|
|
err = build.EnsurePushed(ctx, build.Opts{
|
|
Dir: dir,
|
|
Registry: *fRegistry,
|
|
Tag: tag,
|
|
Arch: *fArch,
|
|
BaseImage: *fBaseImage,
|
|
ExtraCACerts: []string{minica},
|
|
Logf: log.Printf,
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|