cmd/coordinator,dashboard: add privateGoProxy setting

Builders behind firewall may not access to proxy.golang.org but has
its own private Go module proxy

linux-mips64le-mengzhuo
linux-amd64-wsl
linux-riscv64-unmatched

NeedsGoProxy is for long test used which we should not change.

Update golang/go#42971

Change-Id: If300b751487ae08e05f5200581eb4c2719706a56
Reviewed-on: https://go-review.googlesource.com/c/build/+/275412
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Lee Baokun <bk@golangcn.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/coordinator/buildstatus.go b/cmd/coordinator/buildstatus.go
index d7883e9..d7af7da 100644
--- a/cmd/coordinator/buildstatus.go
+++ b/cmd/coordinator/buildstatus.go
@@ -1124,8 +1124,11 @@
 	env := append(st.conf.Env(),
 		"GOROOT="+goroot,
 		"GOPATH="+gopath,
-		"GOPROXY="+moduleProxy(), // GKE value but will be ignored/overwritten by reverse buildlets
 	)
+	if !st.conf.IsReverse() {
+		// GKE value but will be ignored/overwritten by reverse buildlets
+		env = append(env, "GOPROXY="+moduleProxy())
+	}
 	env = append(env, st.conf.ModulesEnv(st.SubName)...)
 
 	args := []string{"test"}
diff --git a/dashboard/builders.go b/dashboard/builders.go
index 7311cb8..c91f272 100644
--- a/dashboard/builders.go
+++ b/dashboard/builders.go
@@ -887,6 +887,11 @@
 	// to run cmd/go tests fetching from the network.
 	needsGoProxy bool
 
+	// privateGoProxy for builder has it's own Go proxy instead of
+	// proxy.golang.org, after setting this builder will respect
+	// GOPROXY enviroment value.
+	privateGoProxy bool
+
 	// InstallRacePackages controls which packages to "go install
 	// -race <pkgs>" after running make.bash (or equivalent).  If
 	// the builder ends in "-race", the default if non-nil is just
@@ -959,7 +964,7 @@
 func (c *BuildConfig) ModulesEnv(repo string) (env []string) {
 	// EC2 and reverse builders should set the public module proxy
 	// address instead of the internal proxy.
-	if (c.HostConfig().isEC2 || c.IsReverse()) && repo != "go" {
+	if (c.HostConfig().isEC2 || c.IsReverse()) && repo != "go" && !c.PrivateGoProxy() {
 		env = append(env, "GOPROXY=https://proxy.golang.org")
 	}
 	switch repo {
@@ -1155,6 +1160,9 @@
 
 func (c *BuildConfig) NeedsGoProxy() bool { return c.needsGoProxy }
 
+// PrivateGoProxy for builder has it's own Go proxy instead of proxy.golang.org
+func (c *BuildConfig) PrivateGoProxy() bool { return c.privateGoProxy }
+
 // BuildsRepoPostSubmit reports whether the build configuration type c
 // should build the given repo ("go", "net", etc) and branch
 // ("master", "release-branch.go1.12") as a post-submit build
@@ -2517,6 +2525,7 @@
 		Name:           "linux-mips64le-mengzhuo",
 		buildsRepo:     onlyMasterDefault,
 		distTestAdjust: mipsDistTestPolicy,
+		privateGoProxy: true, // this builder is behind firewall
 	})
 	addBuilder(BuildConfig{
 		FlakyNet:       true,
@@ -2589,6 +2598,7 @@
 		FlakyNet:       true,
 		buildsRepo:     onlyMasterDefault,
 		distTestAdjust: riscvDistTestPolicy,
+		privateGoProxy: true, // this builder is behind firewall
 	})
 	addBuilder(BuildConfig{
 		Name:           "linux-s390x-ibm",
@@ -2701,11 +2711,12 @@
 		},
 	})
 	addBuilder(BuildConfig{
-		Name:         "linux-amd64-wsl",
-		HostType:     "host-linux-amd64-wsl",
-		Notes:        "Windows 10 WSL2 Ubuntu",
-		FlakyNet:     true,
-		SkipSnapshot: true, // The builder has a slow uplink bandwidth.
+		Name:           "linux-amd64-wsl",
+		HostType:       "host-linux-amd64-wsl",
+		Notes:          "Windows 10 WSL2 Ubuntu",
+		FlakyNet:       true,
+		SkipSnapshot:   true, // The builder has a slow uplink bandwidth.
+		privateGoProxy: true, // this builder is behind firewall
 	})
 	addBuilder(BuildConfig{
 		Name:     "linux-amd64-perf",