mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 22:15:51 +00:00
798b0da470
This moves the distribution definitions into a maintainable hujson file instead of just existing as constants in `distros.go`. Comments are maintained from the inline definitions. This uses jennifer[1] for hygenic source tree creation. This allows us to generate a unique top-level test for each VM run. This should hopefully help make the output of `go test` easier to read. This also separates each test out into its own top-level test so that we can better track the time that each distro takes. I really wish there was a way to have the `test_codegen.go` file _always_ run as a part of the compile process instead of having to rely on people remembering to run `go generate`, but I am limited by my tools. This will let us remove the `-distro-regex` flag and use `go test -run` to pick which distros are run. Signed-off-by: Christine Dodrill <xe@tailscale.com>
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package vms
|
|
|
|
import (
|
|
_ "embed"
|
|
"log"
|
|
|
|
"github.com/tailscale/hujson"
|
|
)
|
|
|
|
// go:generate go run ./gen
|
|
|
|
type Distro struct {
|
|
Name string // amazon-linux
|
|
URL string // URL to a qcow2 image
|
|
SHA256Sum string // hex-encoded sha256 sum of contents of URL
|
|
MemoryMegs int // VM memory in megabytes
|
|
PackageManager string // yum/apt/dnf/zypper
|
|
InitSystem string // systemd/openrc
|
|
}
|
|
|
|
func (d *Distro) InstallPre() string {
|
|
switch d.PackageManager {
|
|
case "yum":
|
|
return ` - [ yum, update, gnupg2 ]
|
|
- [ yum, "-y", install, iptables ]`
|
|
case "zypper":
|
|
return ` - [ zypper, in, "-y", iptables ]`
|
|
|
|
case "dnf":
|
|
return ` - [ dnf, install, "-y", iptables ]`
|
|
|
|
case "apt":
|
|
return ` - [ apt-get, update ]
|
|
- [ apt-get, "-y", install, curl, "apt-transport-https", gnupg2 ]`
|
|
|
|
case "apk":
|
|
return ` - [ apk, "-U", add, curl, "ca-certificates", iptables, ip6tables ]
|
|
- [ modprobe, tun ]`
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
//go:embed distros.hujson
|
|
var distroData string
|
|
|
|
var Distros []Distro = func() []Distro {
|
|
var result []Distro
|
|
err := hujson.Unmarshal([]byte(distroData), &result)
|
|
if err != nil {
|
|
log.Fatalf("error decoding distros: %v", err)
|
|
}
|
|
|
|
return result
|
|
}()
|