Skip to content

Commit d29668b

Browse files
committed
cmd/buildlet/stage0: stop using deprecated --reverse flag to buildlet
Updates golang/go#21260 Change-Id: Ic4d96ef3984017944c5a9af087ea7010e5193f32 Reviewed-on: https://go-review.googlesource.com/52650 Reviewed-by: Jessica Frazelle <[email protected]>
1 parent 31150ba commit d29668b

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

cmd/buildlet/stage0/stage0.go

+41-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
// developed and tested locally, the stage0 instead looks for the
99
// META_BUILDLET_BINARY_URL environment to have a URL to the buildlet
1010
// binary.
11+
//
12+
// The stage0 binary is typically baked into the VM or container
13+
// images or manually copied to dedicated once and is typically never
14+
// auto-updated. Changes to this binary should be rare, as it's
15+
// difficult and slow to roll out. Any per-host-type logic to do at
16+
// start-up should be done in x/build/cmd/buildlet instead, which is
17+
// re-downloaded once per build, and rolls out easily.
1118
package main
1219

1320
import (
@@ -125,12 +132,20 @@ func main() {
125132
cmd.Stdout = os.Stdout
126133
cmd.Stderr = os.Stderr
127134
cmd.Env = env
128-
switch buildenv := os.Getenv("GO_BUILDER_ENV"); buildenv {
135+
136+
// buildEnv is set by some builders. It's increasingly set by new ones.
137+
// It predates the buildtype-vs-hosttype split, so the values aren't
138+
// always host types, but they're often host types. They should probably
139+
// be host types in the future, or we can introduce GO_BUILD_HOST_TYPE
140+
// to be explicit and kill off GO_BUILDER_ENV.
141+
buildEnv := os.Getenv("GO_BUILDER_ENV")
142+
143+
switch buildEnv {
129144
case "linux-arm-arm5spacemonkey":
130-
cmd.Args = append(cmd.Args, legacyReverseBuildletArgs(buildenv)...)
145+
cmd.Args = append(cmd.Args, reverseHostTypeArgs("host-linux-arm5spacemonkey")...)
131146
case "host-linux-arm-scaleway":
132147
scalewayArgs := append(
133-
legacyReverseBuildletArgs(buildenv),
148+
reverseHostTypeArgs(buildEnv),
134149
"--hostname="+os.Getenv("HOSTNAME"),
135150
)
136151
cmd.Args = append(cmd.Args,
@@ -140,13 +155,13 @@ func main() {
140155
switch osArch {
141156
case "linux/s390x":
142157
cmd.Args = append(cmd.Args, "--workdir=/data/golang/workdir")
143-
cmd.Args = append(cmd.Args, legacyReverseBuildletArgs("linux-s390x-ibm")...)
158+
cmd.Args = append(cmd.Args, reverseHostTypeArgs("host-linux-s390x")...)
144159
case "linux/arm64":
145-
switch v := os.Getenv("GO_BUILDER_ENV"); v {
160+
switch buildEnv {
146161
case "host-linux-arm64-packet", "host-linux-arm64-linaro":
147162
hostname := os.Getenv("HOSTNAME") // if empty, docker container name is used
148163
cmd.Args = append(cmd.Args,
149-
"--reverse-type="+v,
164+
"--reverse-type="+buildEnv,
150165
"--workdir=/workdir",
151166
"--hostname="+hostname,
152167
"--halt=false",
@@ -157,11 +172,23 @@ func main() {
157172
panic(fmt.Sprintf("unknown/unspecified $GO_BUILDER_ENV value %q", env))
158173
}
159174
case "linux/ppc64":
160-
cmd.Args = append(cmd.Args, legacyReverseBuildletArgs("linux-ppc64-buildlet")...)
175+
// Assume OSU (osuosl.org) host type for now. If we get more, use
176+
// GO_BUILD_HOST_TYPE (see above) and check that.
177+
cmd.Args = append(cmd.Args, reverseHostTypeArgs("host-linux-ppc64-osu")...)
161178
case "linux/ppc64le":
162-
cmd.Args = append(cmd.Args, legacyReverseBuildletArgs("linux-ppc64le-buildlet")...)
179+
// Assume OSU (osuosl.org) host type for now. If we get more, use
180+
// GO_BUILD_HOST_TYPE (see above) and check that.
181+
cmd.Args = append(cmd.Args, reverseHostTypeArgs("host-linux-ppc64le-osu")...)
163182
case "solaris/amd64":
164-
cmd.Args = append(cmd.Args, legacyReverseBuildletArgs("solaris-amd64-smartosbuildlet")...)
183+
if buildEnv != "" {
184+
// Explicit value given. Treat it like a host type.
185+
cmd.Args = append(cmd.Args, reverseHostTypeArgs(buildEnv)...)
186+
} else {
187+
// If there's no value, assume it's the old Joyent builders,
188+
// which are currently GOOS=solaris, but will be illumos after
189+
// golang.org/issue/20603.
190+
cmd.Args = append(cmd.Args, reverseHostTypeArgs("host-solaris-amd64")...)
191+
}
165192
}
166193
// Release the serial port (if we opened it) so the buildlet
167194
// process can open & write to it. At least on Windows, only
@@ -177,12 +204,13 @@ func main() {
177204
}
178205
}
179206

180-
// legacyReverseBuildletArgs passes builder as the deprecated --reverse flag.
181-
// New code should use --reverse-type instead.
182-
func legacyReverseBuildletArgs(builder string) []string {
207+
// reverseHostTypeArgs returns the default arguments for the buildlet
208+
// for the provided host type. (one of the keys of the
209+
// x/build/dashboard.Hosts map)
210+
func reverseHostTypeArgs(hostType string) []string {
183211
return []string{
184212
"--halt=false",
185-
"--reverse=" + builder,
213+
"--reverse-type=" + hostType,
186214
"--coordinator=farmer.golang.org:443",
187215
}
188216
}

0 commit comments

Comments
 (0)