Files
tailscale/gokrazy/build.go
Brad Fitzpatrick 654c105f8b tstest/natlab/vmtest, gokrazy, cmd/tailscale/cli: add minimal-build vmtests
Add vmtests that boot pairs of gokrazy VMs whose tailscale and tailscaled
are minimal builds and check that IP traffic flows between them over
WireGuard, so we notice if a minimal build stops doing its one job:
build_dist.sh --extra-small (direct path through NATs), that minus NAT
traversal (DERP across NATs, direct on a shared LAN), and DERP-only.

They found that "tailscale up" built with ts_omit_ipnbus returned before
calling Start or EditPrefs, making it a no-op. Fix that, and have it wait
for the Running state by polling tailscaled's status instead of watching
the IPN bus, so scripts can rely on it as with normal builds.

The extra-small feature list moves to featuretags.ExtraSmall so
build_dist.sh (via a new "featuretags --extra-small") and vmtest share
it. The gokrazy builder gains --output and --go-build-tags flags to build
the variant images, and natlabprep --gokrazy prebuilds them all for CI.

Updates #13038
Updates #12614

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I0caa2c7b3adf2399da09b6d07a942f1dc34e8486
2026-09-30 15:53:47 -07:00

94 lines
2.8 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
// This program builds the Tailscale Appliance Gokrazy image.
//
// As of 2024-06-02 this is a exploratory work in progress and is
// not intended for serious use.
//
// The build logic lives in tailscale.com/gokrazy/build; this is a thin
// CLI wrapper around it.
//
// Tracking issue is https://github.com/tailscale/tailscale/issues/1866
package main
import (
"context"
"encoding/json"
"errors"
"flag"
"log"
"os"
"strings"
"tailscale.com/gokrazy/build"
)
var (
app = flag.String("app", "tsapp", "appliance name; one of the subdirectories of gokrazy/")
bucket = flag.String("bucket", "tskrazy-import", "S3 bucket to upload disk image to while making AMI")
buildLocal = flag.Bool("build", false, "if true, just build locally and stop, without uploading")
gaf = flag.Bool("gaf", false, "if true, build a gokrazy archive format file instead of a full disk image")
jsonOut = flag.Bool("json", false, "emit one machine-readable JSON result line to stdout")
region = flag.String("region", "", "AWS region for import+register; default us-east-1 (honors $AWS_REGION)")
output = flag.String("output", "", "base name of the .img or .gaf file to write; default is --app")
goBuildTags = map[string][]string{}
)
func init() {
flag.Func("go-build-tags", "PKG=TAG1,TAG2 to build Go package PKG with the given build tags, overriding config.json; may be repeated", func(v string) error {
pkg, tags, ok := strings.Cut(v, "=")
if !ok || pkg == "" {
return errors.New("want PKG=TAG1,TAG2")
}
goBuildTags[pkg] = strings.Split(tags, ",")
return nil
})
}
func main() {
flag.Parse()
res, err := run(context.Background())
// With --json, print one machine-readable result line to stdout,
// including any error, so consumers see the outcome on stdout rather
// than only via the exit code. All logs/progress go to stderr.
if *jsonOut {
if encErr := json.NewEncoder(os.Stdout).Encode(&res); encErr != nil {
log.Fatalf("encoding json result: %v", encErr)
}
}
if err != nil {
log.Fatalf("%v", err)
}
}
// run builds the appliance and returns the machine-readable result. The
// artifact is a CLI choice mapped to the matching Builder method: --gaf →
// GAF, --build → local image only, otherwise the full AMI pipeline.
func run(ctx context.Context) (build.Result, error) {
b, err := build.New(build.Config{
App: *app,
Bucket: *bucket,
Region: build.ResolveRegion(*region, os.Getenv("AWS_REGION")),
Output: *output,
GoBuildTags: goBuildTags,
})
if err != nil {
return build.Result{App: *app, Error: err.Error()}, err
}
switch {
case *gaf:
_, err = b.BuildGAF(ctx)
case *buildLocal:
_, err = b.BuildImage(ctx)
default:
_, err = b.BuildAndImportAMI(ctx)
}
return b.Result(), err
}