forked from mozilla-releng/OpenCloudConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap_generic_worker.ps1
118 lines (105 loc) · 6.8 KB
/
bootstrap_generic_worker.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
$TASKCLUSTER_VERSION = "45.0.0"
$arch = "386"
$clientID = "project/releng/generic-worker/azure-gecko-t-win7-32-hw"
$workerPoolId = "releng-hardware/gecko-t-win7-32-hw"
$workerGroup = "azure-win7-hv-dev"
$workerID = ""
# use TLS 1.2 (see bug 1443595)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# capture env
Get-ChildItem Env: | Out-File "C:\install_env.txt"
# needed for making http requests
$client = New-Object system.net.WebClient
$shell = new-object -com shell.application
# utility function to download a zip file and extract it
function Expand-ZIPFile($file, $destination, $url)
{
$client.DownloadFile($url, $file)
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
# allow powershell scripts to run
Set-ExecutionPolicy Unrestricted -Force -Scope Process
# install chocolatey package manager
#Invoke-Expression ($client.DownloadString('https://chocolatey.org/install.ps1'))
# install nssm
#Expand-ZIPFile -File "C:\nssm-2.24.zip" -Destination "C:\" -Url "http://www.nssm.cc/release/nssm-2.24.zip"
# download generic-worker
New-Item -ItemType Directory -Path C:\ -Name "generic-worker" -Force
Invoke-WebRequest -Uri "https://github.com/taskcluster/taskcluster/releases/download/v${TASKCLUSTER_VERSION}/generic-worker-multiuser-windows-${arch}" -OutFile "C:\generic-worker\generic-worker.exe"
# install generic-worker, using the steps suggested in https://docs.taskcluster.net/docs/reference/workers/worker-runner/deployment#recommended-setup
Set-Content -Path c:\generic-worker\install.bat @"
set nssm=C:\nssm-2.24-103-gdee49fc\win32\nssm.exe
%nssm% install "Generic Worker" c:\generic-worker\generic-worker.exe
%nssm% set "Generic Worker" AppDirectory c:\generic-worker
%nssm% set "Generic Worker" AppParameters run --config c:\generic-worker\generic-worker-config.yml --worker-runner-protocol-pipe \\.\pipe\generic-worker
%nssm% set "Generic Worker" DisplayName "Generic Worker"
%nssm% set "Generic Worker" Description "A taskcluster worker that runs on all mainstream platforms"
%nssm% set "Generic Worker" Start SERVICE_DEMAND_START
%nssm% set "Generic Worker" Type SERVICE_WIN32_OWN_PROCESS
%nssm% set "Generic Worker" AppNoConsole 1
%nssm% set "Generic Worker" AppAffinity All
%nssm% set "Generic Worker" AppStopMethodSkip 0
%nssm% set "Generic Worker" AppExit Default Exit
%nssm% set "Generic Worker" AppRestartDelay 0
%nssm% set "Generic Worker" AppStdout c:\generic-worker\generic-worker-service.log
%nssm% set "Generic Worker" AppStderr c:\generic-worker\generic-worker-service.log
%nssm% set "Generic Worker" AppRotateFiles 0
"@
Start-Process C:\generic-worker\install.bat -Wait -NoNewWindow
# download worker-runner
New-Item -ItemType Directory -Path C:\ -Name "worker-runner" -Force
Invoke-WebRequest -Uri "https://ronin-puppet-package-repo.s3.us-west-2.amazonaws.com/Windows/start-worker-windows-386" -OutFile "C:\worker-runner\start-worker.exe"
# install worker-runner
Set-Content -Path c:\worker-runner\install.bat @"
set nssm=C:\nssm-2.24-103-gdee49fc\win32\nssm.exe
%nssm% install worker-runner c:\worker-runner\start-worker.exe
%nssm% set worker-runner AppDirectory c:\worker-runner
%nssm% set worker-runner AppParameters c:\worker-runner\runner.yml
%nssm% set worker-runner DisplayName "Worker Runner"
%nssm% set worker-runner Description "Interface between workers and Taskcluster services"
%nssm% set worker-runner Start SERVICE_AUTO_START
%nssm% set worker-runner Type SERVICE_WIN32_OWN_PROCESS
%nssm% set worker-runner AppNoConsole 1
%nssm% set worker-runner AppAffinity All
%nssm% set worker-runner AppStopMethodSkip 0
%nssm% set worker-runner AppExit Default Exit
%nssm% set worker-runner AppRestartDelay 0
%nssm% set worker-runner AppStdout c:\worker-runner\worker-runner-service.log
%nssm% set worker-runner AppStderr c:\worker-runner\worker-runner-service.log
%nssm% set worker-runner AppRotateFiles 1
%nssm% set worker-runner AppRotateOnline 1
%nssm% set worker-runner AppRotateSeconds 3600
%nssm% set worker-runner AppRotateBytes 0
"@
Start-Process C:\worker-runner\install.bat -Wait -NoNewWindow
# configure worker-runner
Set-Content -Path c:\worker-runner\runner.yml @"
provider:
clientID: $($clientID)
providerType: standalone
rootURL: https://firefox-ci-tc.services.mozilla.com
accessToken: xxxx
workerPoolID: $($workerPoolId)
workerGroup: $($workerGroup)
workerID: $($workerID)
worker:
implementation: generic-worker
service: "Generic Worker"
configPath: c:\generic-worker\generic-worker-config.yml
protocolPipe: \\.\pipe\generic-worker
cacheOverRestarts: c:\generic-worker\start-worker-cache.json
workerConfig:
ed25519SigningKeyLocation: c:\generic-worker\generic-worker-ed25519-signing-key.key
"@
Invoke-WebRequest -uri "https://github.com/taskcluster/taskcluster/releases/download/v${TASKCLUSTER_VERSION}/livelog-windows-${Arch}" -OutFile "C:\generic-worker\livelog.exe"
Invoke-WebRequest -uri "https://github.com/taskcluster/taskcluster/releases/download/v${TASKCLUSTER_VERSION}/taskcluster-proxy-windows-${Arch}" -OutFile "C:\generic-worker\taskcluster-proxy.exe"
# configure hosts file for taskcluster-proxy access via http://taskcluster
$HostsFile_Base64 = "IyBDb3B5cmlnaHQgKGMpIDE5OTMtMjAwOSBNaWNyb3NvZnQgQ29ycC4NCiMNCiMgVGhpcyBpcyBhIHNhbXBsZSBIT1NUUyBmaWxlIHVzZWQgYnkgTWljcm9zb2Z0IFRDUC9JUCBmb3IgV2luZG93cy4NCiMNCiMgVGhpcyBmaWxlIGNvbnRhaW5zIHRoZSBtYXBwaW5ncyBvZiBJU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4xICAgICAgICB0YXNrY2x1c3RlciAgICANCg=="
$HostsFile_Content = [System.Convert]::FromBase64String($HostsFile_Base64)
Set-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Value $HostsFile_Content -Encoding Byte
# generate ed25519 key
Start-Process C:\generic-worker\generic-worker.exe -ArgumentList "new-ed25519-keypair --file C:\generic-worker\generic-worker-ed25519-signing-key.key" -Wait -NoNewWindow -PassThru