golang.org/x/build@v0.0.0-20240506185731-218518f32b70/cmd/makemac/config.go (about) 1 // Copyright 2024 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "cmp" 9 "fmt" 10 "log" 11 "slices" 12 13 "go.chromium.org/luci/swarming/client/swarming" 14 ) 15 16 // swarmingConfig describes a swarming server. 17 type swarmingConfig struct { 18 Host string // Swarming host URL 19 Pool string // Pool containing MacService bots 20 21 client swarming.Client 22 } 23 24 var ( 25 // Public swarming host. 26 publicSwarming = &swarmingConfig{ 27 Host: "chromium-swarm.appspot.com", 28 Pool: "luci.golang.shared-workers", 29 } 30 // Security swarming host. 31 internalSwarming = &swarmingConfig{ 32 Host: "chrome-swarming.appspot.com", 33 Pool: "luci.golang.security-try-workers", 34 } 35 ) 36 37 // imageConfig describes how many instances of a specific image type should 38 // exist. 39 type imageConfig struct { 40 Hostname string // LUCI hostname prefix 41 Cert string // Bot certificate (resolved with internal/secret) 42 Key string // bot key (resolved with internal/secret) 43 Image string // image SHA 44 MinCount int // minimum instance count to maintain 45 } 46 47 // Production image configuration for each swarming host. 48 // 49 // After changing an image here, makemac will automatically destroy instances 50 // with the old image. Changing hostname, cert, or key will _not_ automatically 51 // destroy instances. 52 // 53 // TODO(prattmic): rather than storing secrets in secret manager, makemac could 54 // use genbotcert to generate valid certificate/key pairs on the fly, unique to 55 // each lease, which could then have unique hostnames. 56 var prodImageConfig = map[*swarmingConfig][]imageConfig{ 57 publicSwarming: { 58 { 59 Hostname: "darwin-amd64-10_15", 60 Cert: "secret:symbolic-datum-552/darwin-amd64-10_15-cert", 61 Key: "secret:symbolic-datum-552/darwin-amd64-10_15-key", 62 Image: "57b56e0a86984934370bf00058b2bd708031d256104167a3bbbc5ff5aaaf6939", 63 MinCount: 5, // release branches only 64 }, 65 { 66 Hostname: "darwin-amd64-11", 67 Cert: "secret:symbolic-datum-552/darwin-amd64-11-cert", 68 Key: "secret:symbolic-datum-552/darwin-amd64-11-key", 69 Image: "3279e7f8aef8a1d02ba0897de44e5306f94c8cacec3c8c662a897b810879f655", 70 MinCount: 10, 71 }, 72 { 73 Hostname: "darwin-amd64-12", 74 Cert: "secret:symbolic-datum-552/darwin-amd64-12-cert", 75 Key: "secret:symbolic-datum-552/darwin-amd64-12-key", 76 Image: "959a409833522fcba0be62c0c818d68b29d4e1be28d3cbf43dbbc81cb3e3fdeb", 77 MinCount: 10, 78 }, 79 { 80 Hostname: "darwin-amd64-13", 81 Cert: "secret:symbolic-datum-552/darwin-amd64-13-cert", 82 Key: "secret:symbolic-datum-552/darwin-amd64-13-key", 83 Image: "30efbbd26e846da8158a7252d47b3adca15b30270668a95620ace3502cdcaa36", 84 MinCount: 10, 85 }, 86 { 87 Hostname: "darwin-amd64-14", 88 Cert: "secret:symbolic-datum-552/darwin-amd64-14-cert", 89 Key: "secret:symbolic-datum-552/darwin-amd64-14-key", 90 Image: "3ec96f33cf17c85bd6d1bbf122c327bc9e5c62620c3ef9ff63e2db4feebdd8da", 91 MinCount: 10, 92 }, 93 }, 94 internalSwarming: { 95 { 96 Hostname: "darwin-amd64-14-security", 97 Cert: "secret:symbolic-datum-552/darwin-amd64-14-security-cert", 98 Key: "secret:symbolic-datum-552/darwin-amd64-14-security-key", 99 Image: "3ec96f33cf17c85bd6d1bbf122c327bc9e5c62620c3ef9ff63e2db4feebdd8da", 100 MinCount: 1, // in the process of being brought up 101 }, 102 }, 103 } 104 105 // imageConfigMap returns a map from imageConfig.Image to imageConfig. 106 func imageConfigMap(cc []imageConfig) map[string]*imageConfig { 107 m := make(map[string]*imageConfig) 108 for _, c := range cc { 109 c := c 110 if _, ok := m[c.Image]; ok { 111 panic(fmt.Sprintf("duplicate image %s in image config", c.Image)) 112 } 113 m[c.Image] = &c 114 } 115 return m 116 } 117 118 // sortedSwarmingConfigs returns the swarming configs in c, sorted by host. 119 func sortedSwarmingConfigs(c map[*swarmingConfig][]imageConfig) []*swarmingConfig { 120 scs := make([]*swarmingConfig, 0, len(c)) 121 for sc := range c { 122 scs = append(scs, sc) 123 } 124 slices.SortFunc(scs, func(a, b *swarmingConfig) int { 125 return cmp.Compare(a.Host, b.Host) 126 }) 127 return scs 128 } 129 130 func init() { 131 // Panic if prodImageConfig contains duplicates. 132 for _, c := range prodImageConfig { 133 imageConfigMap(c) 134 } 135 } 136 137 func logImageConfig(sc *swarmingConfig, cc []imageConfig) { 138 log.Printf("%s image configuration:", sc.Host) 139 for _, c := range cc { 140 log.Printf("\t%s: image=%s\tcount=%d", c.Hostname, c.Image, c.MinCount) 141 } 142 }