github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/teamcity-trigger/main.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 // teamcity-trigger launches a variety of nightly build jobs on TeamCity using 12 // its REST API. It is intended to be run from a meta-build on a schedule 13 // trigger. 14 // 15 // One might think that TeamCity would support scheduling the same build to run 16 // multiple times with different parameters, but alas. The feature request has 17 // been open for ten years: https://youtrack.jetbrains.com/issue/TW-6439 18 package main 19 20 import ( 21 "fmt" 22 "log" 23 "os" 24 25 "github.com/abourget/teamcity" 26 "github.com/cockroachdb/cockroach/pkg/cmd/cmdutil" 27 "github.com/kisielk/gotool" 28 ) 29 30 func main() { 31 if len(os.Args) != 1 { 32 fmt.Fprintf(os.Stderr, "usage: %s\n", os.Args[0]) 33 os.Exit(1) 34 } 35 36 branch := cmdutil.RequireEnv("TC_BUILD_BRANCH") 37 serverURL := cmdutil.RequireEnv("TC_SERVER_URL") 38 username := cmdutil.RequireEnv("TC_API_USER") 39 password := cmdutil.RequireEnv("TC_API_PASSWORD") 40 41 tcClient := teamcity.New(serverURL, username, password) 42 runTC(func(buildID string, opts map[string]string) { 43 build, err := tcClient.QueueBuild(buildID, branch, opts) 44 if err != nil { 45 log.Fatalf("failed to create teamcity build (buildID=%s, branch=%s, opts=%+v): %s", 46 build, branch, opts, err) 47 } 48 log.Printf("created teamcity build (buildID=%s, branch=%s, opts=%+v): %s", 49 buildID, branch, opts, build) 50 }) 51 } 52 53 const baseImportPath = "github.com/cockroachdb/cockroach/pkg/" 54 55 var importPaths = gotool.ImportPaths([]string{baseImportPath + "..."}) 56 57 func runTC(queueBuild func(string, map[string]string)) { 58 // Queue stress builds. One per configuration per package. 59 for _, importPath := range importPaths { 60 // The stress program by default runs as many instances in parallel as there 61 // are CPUs. Each instance itself can run tests in parallel. The amount of 62 // parallelism needs to be reduced, or we can run into OOM issues, 63 // especially for race builds and/or logic tests (see 64 // https://github.com/cockroachdb/cockroach/pull/10966). 65 // 66 // We limit both the stress program parallelism and the go test parallelism 67 // to 4 for non-race builds and 2 for race builds. For logic tests, we 68 // halve these values. 69 parallelism := 4 70 71 // Stress logic tests with reduced parallelism (to avoid overloading the 72 // machine, see https://github.com/cockroachdb/cockroach/pull/10966). 73 if importPath == baseImportPath+"sql/logictest" { 74 parallelism /= 2 75 } 76 77 opts := map[string]string{ 78 "env.PKG": importPath, 79 } 80 81 // Run non-race build. 82 opts["env.GOFLAGS"] = fmt.Sprintf("-parallel=%d", parallelism) 83 opts["env.STRESSFLAGS"] = fmt.Sprintf("-p %d", parallelism) 84 queueBuild("Cockroach_Nightlies_Stress", opts) 85 86 // Run race build. Reduce the parallelism to avoid overloading the machine. 87 parallelism /= 2 88 opts["env.GOFLAGS"] = fmt.Sprintf("-race -parallel=%d", parallelism) 89 opts["env.STRESSFLAGS"] = fmt.Sprintf("-p %d", parallelism) 90 91 queueBuild("Cockroach_Nightlies_Stress", opts) 92 } 93 }