Skip to content
This repository was archived by the owner on Feb 20, 2020. It is now read-only.

Commit 6c4d51f

Browse files
committed
Bug 1534223 - support running worker behind taskcluster-proxy
1 parent 0b44f90 commit 6c4d51f

File tree

9 files changed

+114
-77
lines changed

9 files changed

+114
-77
lines changed

.taskcluster.yml

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ tasks:
2929
- pull_request.synchronize
3030
- push
3131
scopes:
32+
- assume:project:taskcluster:generic-worker-tester
3233
- generic-worker:cache:generic-worker-checkout
3334
payload:
35+
features:
36+
taskclusterProxy: true
3437
maxRunTime: 3600
3538
command:
3639
- set CGO_ENABLED=0
@@ -68,7 +71,6 @@ tasks:
6871
- go install -tags nativeEngine -v -ldflags "-X main.revision=%revision%" ./...
6972
- set CGO_ENABLED=1
7073
- set GORACE=history_size=7
71-
- C:\generic-worker\generic-worker-test-creds.cmd
7274
- 'go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=%revision%" -v -race ./...'
7375
- set GW_TESTS_RUN_AS_TASK_USER=true
7476
- 'go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=%revision%" -v -race'
@@ -112,8 +114,11 @@ tasks:
112114
- pull_request.synchronize
113115
- push
114116
scopes:
117+
- assume:project:taskcluster:generic-worker-tester
115118
- generic-worker:cache:generic-worker-checkout
116119
payload:
120+
features:
121+
taskclusterProxy: true
117122
maxRunTime: 3600
118123
command:
119124
- set CGO_ENABLED=0
@@ -139,8 +144,9 @@ tasks:
139144
- go generate
140145
- set revision={{ event.head.sha }}
141146
- go install -tags nativeEngine -v -ldflags "-X main.revision=%revision%" ./...
142-
- set GORACE=history_size=7
143-
- C:\generic-worker\generic-worker-test-creds.cmd
147+
# go test: -race and -msan are only supported on:
148+
# linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64
149+
# i.e. - *not* on windows/386
144150
- 'go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=%revision%" -v ./...'
145151
- set GW_TESTS_RUN_AS_TASK_USER=true
146152
- 'go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=%revision%" -v'
@@ -184,8 +190,11 @@ tasks:
184190
- pull_request.synchronize
185191
- push
186192
scopes:
193+
- assume:project:taskcluster:generic-worker-tester
187194
- generic-worker:cache:generic-worker-checkout
188195
payload:
196+
features:
197+
taskclusterProxy: true
189198
maxRunTime: 3600
190199
command:
191200
- set CGO_ENABLED=0
@@ -223,7 +232,6 @@ tasks:
223232
- go install -tags nativeEngine -v -ldflags "-X main.revision=%revision%" ./...
224233
- set CGO_ENABLED=1
225234
- set GORACE=history_size=7
226-
- C:\generic-worker\generic-worker-test-creds.cmd
227235
- 'go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=%revision%" -v -race ./...'
228236
- set GW_TESTS_RUN_AS_TASK_USER=true
229237
- 'go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=%revision%" -v -race'
@@ -267,8 +275,11 @@ tasks:
267275
- pull_request.synchronize
268276
- push
269277
scopes:
278+
- assume:project:taskcluster:generic-worker-tester
270279
- generic-worker:cache:generic-worker-checkout
271280
payload:
281+
features:
282+
taskclusterProxy: true
272283
maxRunTime: 3600
273284
command:
274285
- - /bin/bash
@@ -280,7 +291,6 @@ tasks:
280291
export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"
281292
go version
282293
go env
283-
source "${GW_CREDS_BOOTSTRAP}"
284294
mkdir -p "${GOPATH}/src/github.com/taskcluster"
285295
cd "${GOPATH}/src/github.com/taskcluster"
286296
if [ ! -d generic-worker/.git ]; then rm -rf generic-worker; git clone '{{ event.head.repo.url }}' 'generic-worker'; fi
@@ -298,8 +308,8 @@ tasks:
298308
go install -tags nativeEngine -v -ldflags "-X main.revision=$(git rev-parse HEAD)" ./...
299309
# output of wc command can contain spaces on darwin, so no quotes around expression
300310
test $(git status --porcelain | wc -l) == 0
301-
GORACE=history_size=7 CGO_ENABLED=1 go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=$(git rev-parse HEAD)" -race -v ./...
302-
ineffassign .
311+
GORACE=history_size=7 CGO_ENABLED=1 go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=$(git rev-parse HEAD)" -v -race ./...
312+
"${GOPATH}/bin/ineffassign" .
303313
artifacts:
304314
- name: public/build/generic-worker-darwin-amd64
305315
path: gopath1.10.8/bin/generic-worker
@@ -340,8 +350,11 @@ tasks:
340350
# - pull_request.synchronize
341351
# - push
342352
# scopes:
353+
# - assume:project:taskcluster:generic-worker-tester
343354
# - generic-worker:cache:generic-worker-checkout
344355
# payload:
356+
# features:
357+
# taskclusterProxy: true
345358
# maxRunTime: 3600
346359
# command:
347360
# - - /bin/bash
@@ -351,10 +364,8 @@ tasks:
351364
# export GOROOT="$(pwd)/go1.10.8/go"
352365
# export GOPATH="$(pwd)/gopath1.10.8"
353366
# export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"
354-
# export CGO_ENABLED=0
355367
# go version
356368
# go env
357-
# source "${GW_CREDS_BOOTSTRAP}"
358369
# mkdir -p "${GOPATH}/src/github.com/taskcluster"
359370
# cd "${GOPATH}/src/github.com/taskcluster"
360371
# if [ ! -d generic-worker/.git ]; then rm -rf generic-worker; git clone '{{ event.head.repo.url }}' 'generic-worker'; fi
@@ -371,8 +382,11 @@ tasks:
371382
# go generate
372383
# go install -tags nativeEngine -v -ldflags "-X main.revision=$(git rev-parse HEAD)" ./...
373384
# test "$(git status --porcelain | wc -l)" == 0
374-
# GORACE=history_size=7 go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=$(git rev-parse HEAD)" -v ./...
375-
# ineffassign .
385+
# # go test: -race and -msan are only supported on:
386+
# # linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64
387+
# # i.e. - *not* on linux/arm
388+
# go test -tags nativeEngine -timeout 45m -ldflags "-X github.com/taskcluster/generic-worker.revision=$(git rev-parse HEAD)" -v ./...
389+
# "${GOPATH}/bin/ineffassign" .
376390
# artifacts:
377391
# - name: public/build/generic-worker-linux-armv6l
378392
# path: gopath1.10.8/bin/generic-worker
@@ -407,12 +421,11 @@ tasks:
407421
- pull_request.synchronize
408422
- push
409423
scopes:
424+
- assume:project:taskcluster:generic-worker-tester
410425
- generic-worker:cache:generic-worker-checkout
411-
- secrets:get:repo:github.com/taskcluster/generic-worker
412426
payload:
413427
features:
414-
taskclusterProxy:
415-
true
428+
taskclusterProxy: true
416429
maxRunTime: 3600
417430
command:
418431
- - /bin/bash
@@ -424,8 +437,6 @@ tasks:
424437
export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"
425438
go version
426439
go env
427-
curl -s "${TASKCLUSTER_PROXY_URL}/secrets/v1/secret/repo:github.com/taskcluster/generic-worker" | sed -n 's/.*"b64_encoded_credentials_script": "\(.*\)".*/\1/p' | base64 -d > ~/env_private.sh
428-
source ~/env_private.sh
429440
mkdir -p "${GOPATH}/src/github.com/taskcluster"
430441
cd "${GOPATH}/src/github.com/taskcluster"
431442
if [ ! -d generic-worker/.git ]; then rm -rf generic-worker; git clone '{{ event.head.repo.url }}' 'generic-worker'; fi
@@ -478,12 +489,11 @@ tasks:
478489
- pull_request.synchronize
479490
- push
480491
scopes:
492+
- assume:project:taskcluster:generic-worker-tester
481493
- generic-worker:cache:generic-worker-checkout
482-
- secrets:get:repo:github.com/taskcluster/generic-worker
483494
payload:
484495
features:
485-
taskclusterProxy:
486-
true
496+
taskclusterProxy: true
487497
maxRunTime: 3600
488498
command:
489499
- - /bin/bash
@@ -495,8 +505,6 @@ tasks:
495505
export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"
496506
go version
497507
go env
498-
curl -s "${TASKCLUSTER_PROXY_URL}/secrets/v1/secret/repo:github.com/taskcluster/generic-worker" | sed -n 's/.*"b64_encoded_credentials_script": "\(.*\)".*/\1/p' | base64 -d > ~/env_private.sh
499-
source ~/env_private.sh
500508
mkdir -p "${GOPATH}/src/github.com/taskcluster"
501509
cd "${GOPATH}/src/github.com/taskcluster"
502510
if [ ! -d generic-worker/.git ]; then rm -rf generic-worker; git clone '{{ event.head.repo.url }}' 'generic-worker'; fi
@@ -548,8 +556,7 @@ tasks:
548556
maxRunTime: 3600
549557
image: taskcluster/upload-project-docs:latest
550558
features:
551-
taskclusterProxy:
552-
true
559+
taskclusterProxy: true
553560
command:
554561
- /bin/bash
555562
- '--login'
@@ -586,7 +593,7 @@ tasks:
586593
- pull_request.synchronize
587594
- push
588595
scopes:
589-
- secrets:get:repo:github.com/taskcluster/generic-worker
596+
- assume:project:taskcluster:generic-worker-tester
590597
- docker-worker:cache:generic-worker-checkout
591598
payload:
592599
features:

aws_helper_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/taskcluster/slugid-go/slugid"
16+
tcclient "github.com/taskcluster/taskcluster-client-go"
1617
"github.com/taskcluster/taskcluster-client-go/tcpurgecache"
1718
"github.com/taskcluster/taskcluster-client-go/tcqueue"
1819
)
@@ -45,13 +46,12 @@ func (m *MockAWSProvisionedEnvironment) ValidPublicConfig(t *testing.T) map[stri
4546
"downloadsDir": filepath.Join(cwd, "downloads"),
4647
"idleTimeoutSecs": 60,
4748
"numberOfTasksToRun": 1,
49+
"queueBaseURL": tcqueue.New(nil, tcclient.RootURLFromEnvVars()).BaseURL,
50+
"purgeCacheBaseURL": tcpurgecache.New(nil, tcclient.RootURLFromEnvVars()).BaseURL,
4851
// should be enough for tests, and travis-ci.org CI environments
4952
// don't have a lot of free disk
50-
"queueBaseURL": tcqueue.New(nil, os.Getenv("TASKCLUSTER_ROOT_URL")).BaseURL,
51-
"purgeCacheBaseURL": tcpurgecache.New(nil, os.Getenv("TASKCLUSTER_ROOT_URL")).BaseURL,
52-
"requiredDiskSpaceMegabytes": 16,
53-
"runTasksAsCurrentUser": os.Getenv("GW_TESTS_RUN_AS_TASK_USER") == "",
54-
// "secretsBaseURL": "http://localhost:13243/secrets",
53+
"requiredDiskSpaceMegabytes": 16,
54+
"runTasksAsCurrentUser": os.Getenv("GW_TESTS_RUN_AS_TASK_USER") == "",
5555
"sentryProject": "generic-worker-tests",
5656
"shutdownMachineOnIdle": false,
5757
"shutdownMachineOnInternalError": false,
@@ -125,21 +125,19 @@ func (m *MockAWSProvisionedEnvironment) userData(t *testing.T, w http.ResponseWr
125125
data = m.WorkerTypeDefinitionUserData(t)
126126
}
127127
resp := map[string]interface{}{
128-
"data": data,
129-
"capacity": 1,
130-
"workerType": workerType,
131-
"provisionerId": "test-provisioner",
132-
"region": "test-worker-group",
133-
"availabilityZone": "neuss-germany",
134-
"instanceType": "p3.teenyweeny",
135-
"spotBid": 3.5,
136-
"price": 3.02,
137-
// "taskclusterRootUrl": os.Getenv("TASKCLUSTER_ROOT_URL"), // don't use tcclient.RootURLFromEnvVars() since we don't want ClientID of CI
128+
"data": data,
129+
"capacity": 1,
130+
"workerType": workerType,
131+
"provisionerId": "test-provisioner",
132+
"region": "test-worker-group",
133+
"availabilityZone": "neuss-germany",
134+
"instanceType": "p3.teenyweeny",
135+
"spotBid": 3.5,
136+
"price": 3.02,
138137
"taskclusterRootUrl": "http://localhost:13243",
139138
"launchSpecGenerated": time.Now(),
140139
"lastModified": time.Now().Add(time.Minute * -30),
141-
// "provisionerBaseUrl": "http://localhost:13243/provisioner",
142-
"securityToken": "12345",
140+
"securityToken": "12345",
143141
}
144142
WriteJSON(t, w, resp)
145143
}

gwconfig/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type (
4747
PrivateIP net.IP `json:"privateIP"`
4848
ProvisionerBaseURL string `json:"provisionerBaseURL"`
4949
ProvisionerID string `json:"provisionerId"`
50+
ProxyURL string `json:"proxyURL"`
5051
PublicIP net.IP `json:"publicIP"`
5152
PurgeCacheBaseURL string `json:"purgeCacheBaseURL"`
5253
QueueBaseURL string `json:"queueBaseURL"`
@@ -107,9 +108,7 @@ func (c *Config) Validate() error {
107108
name string
108109
disallowed interface{}
109110
}{
110-
{value: c.AccessToken, name: "accessToken", disallowed: ""},
111111
{value: c.CachesDir, name: "cachesDir", disallowed: ""},
112-
{value: c.ClientID, name: "clientId", disallowed: ""},
113112
{value: c.DownloadsDir, name: "downloadsDir", disallowed: ""},
114113
{value: c.Ed25519SigningKeyLocation, name: "ed25519SigningKeyLocation", disallowed: ""},
115114
{value: c.LiveLogExecutable, name: "livelogExecutable", disallowed: ""},

helper_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func setup(t *testing.T) (teardown func()) {
134134
// should be enough for tests, and travis-ci.org CI environments don't
135135
// have a lot of free disk
136136
RequiredDiskSpaceMegabytes: 16,
137-
RootURL: os.Getenv("TASKCLUSTER_ROOT_URL"),
137+
RootURL: tcclient.RootURLFromEnvVars(),
138138
RunAfterUserCreation: "",
139139
RunTasksAsCurrentUser: os.Getenv("GW_TESTS_RUN_AS_TASK_USER") == "",
140140
SentryProject: "generic-worker-tests",
@@ -175,14 +175,14 @@ func setup(t *testing.T) (teardown func()) {
175175

176176
func NewQueue(t *testing.T) *tcqueue.Queue {
177177
// check we have all the env vars we need to run this test
178-
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
179-
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
180-
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
181-
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
182-
}
183-
// BaseURL shouldn't be proxy otherwise requests will use CI clientId
184-
// rather than env var TASKCLUSTER_CLIENT_ID
185-
return tcqueue.New(tcclient.CredentialsFromEnvVars(), os.Getenv("TASKCLUSTER_ROOT_URL"))
178+
if os.Getenv("TASKCLUSTER_PROXY_URL") == "" {
179+
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
180+
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
181+
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
182+
t.Skip("Skipping test since TASKCLUSTER_PROXY_URL is not set, and also one or more of TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} are also not set")
183+
}
184+
}
185+
return tcqueue.NewFromEnv()
186186
}
187187

188188
func scheduleTask(t *testing.T, td *tcqueue.TaskDefinitionRequest, payload GenericWorkerPayload) (taskID string) {

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ func loadConfig(filename string, queryAWSUserData bool, queryGCPMetaData bool) (
248248
NumberOfTasksToRun: 0,
249249
ProvisionerBaseURL: "",
250250
ProvisionerID: "test-provisioner",
251+
ProxyURL: "",
251252
PurgeCacheBaseURL: "",
252253
QueueBaseURL: "",
253254
RequiredDiskSpaceMegabytes: 10240,

taskcluster_proxy_broken_on_docker_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
package main
44

55
import (
6-
"fmt"
76
"os"
87
"testing"
98
)
109

1110
func TestTaskclusterProxy(t *testing.T) {
12-
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
13-
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
14-
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
15-
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
11+
if os.Getenv("TASKCLUSTER_PROXY_URL") == "" {
12+
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
13+
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
14+
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
15+
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
16+
}
1617
}
1718

1819
defer setup(t)()
@@ -26,7 +27,7 @@ func TestTaskclusterProxy(t *testing.T) {
2627
goRun(
2728
"curlget.go",
2829
// note that curlget.go supports substituting the proxy URL from its runtime environment
29-
fmt.Sprintf("TASKCLUSTER_PROXY_URL/queue/v1/task/KTBKfEgxR5GdfIIREQIvFQ/runs/0/artifacts/SampleArtifacts/_/X.txt"),
30+
"TASKCLUSTER_PROXY_URL/queue/v1/task/KTBKfEgxR5GdfIIREQIvFQ/runs/0/artifacts/SampleArtifacts/_/X.txt",
3031
)...,
3132
),
3233
MaxRunTime: 60,

tcproxy/tcproxy_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
)
1212

1313
func TestTcProxy(t *testing.T) {
14-
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
15-
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
16-
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
17-
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
14+
if os.Getenv("TASKCLUSTER_PROXY_URL") == "" {
15+
if os.Getenv("TASKCLUSTER_CLIENT_ID") == "" ||
16+
os.Getenv("TASKCLUSTER_ACCESS_TOKEN") == "" ||
17+
os.Getenv("TASKCLUSTER_ROOT_URL") == "" {
18+
t.Skip("Skipping test since TASKCLUSTER_{CLIENT_ID,ACCESS_TOKEN,ROOT_URL} env vars not set")
19+
}
1820
}
1921

2022
var executable string
@@ -30,7 +32,7 @@ func TestTcProxy(t *testing.T) {
3032
Certificate: os.Getenv("TASKCLUSTER_CERTIFICATE"),
3133
AuthorizedScopes: []string{"queue:get-artifact:SampleArtifacts/_/X.txt"},
3234
}
33-
ll, err := New(executable, 34569, os.Getenv("TASKCLUSTER_ROOT_URL"), creds)
35+
ll, err := New(executable, 34569, tcclient.RootURLFromEnvVars(), creds)
3436
// Do defer before checking err since err could be a different error and
3537
// process may have already started up.
3638
defer func() {

testdata/resolvetask.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import (
44
"log"
55
"os"
66

7-
tcclient "github.com/taskcluster/taskcluster-client-go"
87
"github.com/taskcluster/taskcluster-client-go/tcqueue"
98
)
109

1110
func main() {
12-
queue := tcqueue.New(tcclient.CredentialsFromEnvVars(), os.Getenv("TASKCLUSTER_ROOT_URL"))
11+
queue := tcqueue.NewFromEnv()
1312
taskID := os.Getenv("TASK_ID")
1413
_, err := queue.CancelTask(taskID)
1514
if err != nil {

0 commit comments

Comments
 (0)