mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-15 07:27:30 +00:00
gokrazy/natlab: update gokrazy, wire up natlab tests to GitHub CI
Updates #13038 Change-Id: I610f9076816f44d59c0ca405a1b4f5eb4c6c0594 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
3e18434595
commit
5eafce7e25
@@ -11,7 +11,6 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
@@ -30,7 +29,6 @@ import (
|
||||
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")
|
||||
goArch = flag.String("arch", cmp.Or(os.Getenv("GOARCH"), "amd64"), "GOARCH architecture to build for: arm64 or amd64")
|
||||
build = flag.Bool("build", false, "if true, just build locally and stop, without uploading")
|
||||
)
|
||||
|
||||
@@ -54,6 +52,26 @@ func findMkfsExt4() (string, error) {
|
||||
return "", errors.New("No mkfs.ext4 found on system")
|
||||
}
|
||||
|
||||
var conf gokrazyConfig
|
||||
|
||||
// gokrazyConfig is the subset of gokrazy/internal/config.Struct
|
||||
// that we care about.
|
||||
type gokrazyConfig struct {
|
||||
// Environment is os.Environment pairs to use when
|
||||
// building userspace.
|
||||
// See https://gokrazy.org/userguide/instance-config/#environment
|
||||
Environment []string
|
||||
}
|
||||
|
||||
func (c *gokrazyConfig) GOARCH() string {
|
||||
for _, e := range c.Environment {
|
||||
if v, ok := strings.CutPrefix(e, "GOARCH="); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@@ -61,6 +79,19 @@ func main() {
|
||||
log.Fatalf("--app must be non-empty name such as 'tsapp' or 'natlabapp'")
|
||||
}
|
||||
|
||||
confJSON, err := os.ReadFile(filepath.Join(*app, "config.json"))
|
||||
if err != nil {
|
||||
log.Fatalf("reading config.json: %v", err)
|
||||
}
|
||||
if err := json.Unmarshal(confJSON, &conf); err != nil {
|
||||
log.Fatalf("unmarshaling config.json: %v", err)
|
||||
}
|
||||
switch conf.GOARCH() {
|
||||
case "amd64", "arm64":
|
||||
default:
|
||||
log.Fatalf("config.json GOARCH %q must be amd64 or arm64", conf.GOARCH())
|
||||
}
|
||||
|
||||
if err := buildImage(); err != nil {
|
||||
log.Fatalf("build image: %v", err)
|
||||
}
|
||||
@@ -106,7 +137,6 @@ func buildImage() error {
|
||||
// Build the tsapp.img
|
||||
var buf bytes.Buffer
|
||||
cmd := exec.Command("go", "run",
|
||||
"-exec=env GOOS=linux GOARCH="+*goArch+" ",
|
||||
"github.com/gokrazy/tools/cmd/gok",
|
||||
"--parent_dir="+dir,
|
||||
"--instance="+*app,
|
||||
@@ -253,13 +283,13 @@ func waitForImportSnapshot(importTaskID string) (snapID string, err error) {
|
||||
|
||||
func makeAMI(name, ebsSnapID string) (ami string, err error) {
|
||||
var arch string
|
||||
switch *goArch {
|
||||
switch conf.GOARCH() {
|
||||
case "arm64":
|
||||
arch = "arm64"
|
||||
case "amd64":
|
||||
arch = "x86_64"
|
||||
default:
|
||||
return "", fmt.Errorf("unknown arch %q", *goArch)
|
||||
return "", fmt.Errorf("unknown arch %q", conf.GOARCH())
|
||||
}
|
||||
out, err := exec.Command("aws", "ec2", "register-image",
|
||||
"--name", name,
|
||||
|
Reference in New Issue
Block a user