-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure-win_worker.ps1
112 lines (90 loc) · 2.84 KB
/
configure-win_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
[CmdletBinding()]
Param(
[switch] $SkipEngineUpgrade,
[string] $DockerVersion,
[string] $UCPFQDN,
[string] $UcpVersion,
[string] $LeaderIP
)
#Variables
$Date = Get-Date -Format "yyyy-MM-dd HHmmss"
$DockerDataPath = "C:\ProgramData\Docker"
function Join-Swarm() {
try
{
Write-Host "Leader IP: $LeaderIP"
$Url = -join("http://", $LeaderIP, ":9024/token/worker/")
Write-Host "Using URL: $Url"
Start-Sleep -Seconds 20
$Stream = ([System.Net.WebRequest]::Create($Url)).GetResponse().GetResponseStream()
$StreamReader = new-object System.IO.StreamReader $Stream
$Token = $StreamReader.ReadToEnd()
Write-Host "Obtained token and Joining swarm"
$JoinTarget = -join($LeaderIP, ":2377")
docker.exe swarm join --token $Token $JoinTarget
return 0
}
catch
{
Write-Host "Exception encountered: "
Write-Host $_.Exception|format-list -force
}
}
function Disable-RealTimeMonitoring () {
Set-MpPreference -DisableRealtimeMonitoring $true
}
function Install-LatestDockerEngine () {
#Get Docker Engine from Master Builds
Invoke-WebRequest -Uri "https://download.docker.com/components/engine/windows-server/17.06/docker-17.06.2-ee-5.zip" -OutFile "docker.zip"
Stop-Service docker
Remove-Item -Force -Recurse $env:ProgramFiles\docker
Expand-Archive -Path "docker.zip" -DestinationPath $env:ProgramFiles -Force
Remove-Item docker.zip
Start-Service docker
}
function Disable-Firewall () {
#Disable firewall (temporary)
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
#Ensure public profile is disabled (solves public profile not persisting issue)
$data = netsh advfirewall show publicprofile
$data = $data[3]
if ($data -Match "ON"){
Set-NetFirewallProfile -Profile Public -Enabled False
}
}
function Set-UcpHostnameEnvironmentVariable() {
$UCPFQDN | Out-File (Join-Path $DockerDataPath "ucp_fqdn")
}
function Get-UcpImages() {
docker pull docker/ucp-dsinfo-win:$UcpVersion
docker pull docker/ucp-agent-win:$UcpVersion
Add-Content setup.ps1 $(docker run --rm docker/ucp-agent-win:$UcpVersion windows-script)
& .\setup.ps1
Remove-Item -Force setup.ps1
}
#Start Script
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
try
{
Start-Transcript -path "C:\ProgramData\Docker\configure-worker $Date.log" -append
Write-Host "Disabling Real Time Monitoring"
Disable-RealTimeMonitoring
if (-not ($SkipEngineUpgrade.IsPresent)) {
Write-Host "Upgrading Docker Engine"
Install-LatestDockerEngine
}
Write-Host "Getting UCP Images"
Get-UcpImages
Write-Host "Disabling Firewall"
Disable-Firewall
Write-Host "Set UCP FQDN Environment Variable"
Set-UcpHostnameEnvironmentVariable
Write-Host "Join Swarm Cluster"
Join-Swarm
Stop-Transcript
}
catch
{
Write-Error $_
}