@@ -16,17 +16,14 @@ import (
16
16
"fmt"
17
17
"io/ioutil"
18
18
"log"
19
- "net/http"
20
19
"os"
21
20
"os/exec"
22
21
"path/filepath"
23
- "runtime"
24
22
"strings"
25
23
"time"
26
24
27
25
"github.com/aws/aws-sdk-go/aws/ec2metadata"
28
26
"github.com/aws/aws-sdk-go/aws/session"
29
- "golang.org/x/build/buildenv"
30
27
"golang.org/x/build/internal/cloud"
31
28
)
32
29
42
39
)
43
40
44
41
var (
45
- buildKey []byte
46
- scalewayMeta = new (scalewayMetadata )
47
- isReverse = true
48
- isSingleRun = false
42
+ buildKey []byte
43
+ isReverse = true
44
+ isSingleRun = false
49
45
// ec2UD contains a copy of the EC2 vm user data retrieved from the metadata.
50
46
ec2UD * cloud.EC2UserData
51
47
// ec2MetaClient is an EC2 metadata client.
55
51
func main () {
56
52
flag .Parse ()
57
53
58
- if onScaleway () {
59
- * memory = ""
60
- * image = "eu.gcr.io/symbolic-datum-552/scaleway-builder"
61
- * pull = true
62
- * numInst = 1
63
- * basename = "scaleway"
64
- initScalewayMeta ()
65
- } else if onEC2 () {
54
+ if onEC2 () {
66
55
initEC2Meta ()
67
56
* memory = ""
68
57
* image = ec2UD .BuildletImageURL
@@ -115,29 +104,9 @@ func onEC2() bool {
115
104
return ec2MdClient ().AvailableWithContext (ctx )
116
105
}
117
106
118
- func onScaleway () bool {
119
- if * builderEnv == "host-linux-arm-scaleway" {
120
- return true
121
- }
122
- if runtime .GOOS == "linux" && runtime .GOARCH == "arm" {
123
- if _ , err := os .Stat ("/usr/local/bin/oc-metadata" ); err == nil {
124
- return true
125
- }
126
- }
127
- return false
128
- }
129
-
130
107
func getBuildKey () []byte {
131
108
key , err := ioutil .ReadFile (* keyFile )
132
109
if err != nil {
133
- if onScaleway () {
134
- const prefix = "buildkey_host-linux-arm-scaleway_"
135
- for _ , tag := range scalewayMeta .Tags {
136
- if strings .HasPrefix (tag , prefix ) {
137
- return []byte (strings .TrimPrefix (tag , prefix ))
138
- }
139
- }
140
- }
141
110
log .Fatalf ("error reading build key from --key=%s: %v" , * keyFile , err )
142
111
}
143
112
return bytes .TrimSpace (key )
@@ -162,10 +131,6 @@ func checkFix() error {
162
131
}
163
132
container , name , status := f [0 ], f [1 ], f [2 ]
164
133
prefix := * basename
165
- if scalewayMeta != nil {
166
- // scaleway containers are named after their instance.
167
- prefix = scalewayMeta .Hostname
168
- }
169
134
if ! strings .HasPrefix (name , prefix ) {
170
135
continue
171
136
}
@@ -177,12 +142,7 @@ func checkFix() error {
177
142
178
143
for num := 1 ; num <= * numInst ; num ++ {
179
144
var name string
180
- if scalewayMeta != nil && scalewayMeta .Hostname != "" {
181
- // The -name passed to 'docker run' should match the
182
- // c1 instance hostname for debugability.
183
- // There should only be one running container per c1 instance.
184
- name = scalewayMeta .Hostname
185
- } else if onEC2 () {
145
+ if onEC2 () {
186
146
name = ec2UD .BuildletName
187
147
} else {
188
148
name = fmt .Sprintf ("%s%02d" , * basename , num )
@@ -250,9 +210,6 @@ func checkFix() error {
250
210
if * builderEnv != "" {
251
211
cmd .Args = append (cmd .Args , "-e" , "GO_BUILDER_ENV=" + * builderEnv )
252
212
}
253
- if u := buildletBinaryURL (); u != "" {
254
- cmd .Args = append (cmd .Args , "-e" , "META_BUILDLET_BINARY_URL=" + u )
255
- }
256
213
cmd .Args = append (cmd .Args ,
257
214
"-e" , "GO_BUILD_KEY_PATH=/buildkey/gobuildkey" ,
258
215
"-e" , "GO_BUILD_KEY_DELETE_AFTER_READ=true" ,
@@ -268,24 +225,6 @@ func checkFix() error {
268
225
return nil
269
226
}
270
227
271
- type scalewayMetadata struct {
272
- Name string `json:"name"`
273
- Hostname string `json:"hostname"`
274
- Tags []string `json:"tags"`
275
- }
276
-
277
- func (m * scalewayMetadata ) HasTag (t string ) bool {
278
- if m == nil {
279
- return false
280
- }
281
- for _ , v := range m .Tags {
282
- if v == t {
283
- return true
284
- }
285
- }
286
- return false
287
- }
288
-
289
228
func initEC2Meta () {
290
229
if ! onEC2 () {
291
230
log .Fatal ("attempt to initialize metadata on non-EC2 instance" )
@@ -309,37 +248,10 @@ func initEC2Meta() {
309
248
}
310
249
}
311
250
312
- func initScalewayMeta () {
313
- const metaURL = "http://169.254.42.42/conf?format=json"
314
- res , err := http .Get (metaURL )
315
- if err != nil {
316
- log .Fatalf ("failed to get scaleway metadata: %v" , err )
317
- }
318
- defer res .Body .Close ()
319
- if res .StatusCode != http .StatusOK {
320
- log .Fatalf ("failed to get scaleway metadata from %s: %v" , metaURL , res .Status )
321
- }
322
- if err := json .NewDecoder (res .Body ).Decode (scalewayMeta ); err != nil {
323
- log .Fatalf ("invalid JSON from scaleway metadata URL %s: %v" , metaURL , err )
324
- }
325
- }
326
-
327
251
func removeContainer (container string ) {
328
252
if out , err := exec .Command ("docker" , "rm" , "-f" , container ).CombinedOutput (); err != nil {
329
253
log .Printf ("error running docker rm -f %s: %v, %s" , container , err , out )
330
254
return
331
255
}
332
256
log .Printf ("Removed container %s" , container )
333
257
}
334
-
335
- func buildletBinaryURL () string {
336
- if ! onScaleway () {
337
- // Only used for Scaleway currently.
338
- return ""
339
- }
340
- env := buildenv .Production
341
- if scalewayMeta .HasTag ("staging" ) {
342
- env = buildenv .Staging
343
- }
344
- return fmt .Sprintf ("https://storage.googleapis.com/%s/buildlet.linux-arm" , env .BuildletBucket )
345
- }
0 commit comments