-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselenium.yml
481 lines (439 loc) · 13.1 KB
/
selenium.yml
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
AWSTemplateFormatVersion: "2010-09-09"
Description: "[TODO] Selenium Testing Grid"
Parameters:
InstanceType:
Type: String
Description: |
Which instance type should we use to build the ECS cluster?
Default: c4.large
IncludeIE:
Type: String
Default: true
Description: |
Create a IE11 & IE10 Grid node?
AllowedValues:
- true
- false
KeyName:
Type: String
NoEcho: true
Description: |
The EC2 Keypair name to access selenium instances
Conditions:
UseIE: !Equals [ !Ref "IncludeIE", "true" ]
Mappings:
Win2016RegionToAMI:
eu-central-1:
AMI: ami-b5530b5e
eu-west-1:
AMI: ami-4cc09a35
eu-west-2:
AMI: ami-9c6b8dfb
us-east-1:
AMI: ami-838b53fc
Win2012RegionToAMI:
eu-central-1:
AMI: ami-6eb0e885
eu-west-1:
AMI: ami-813015f8
eu-west-2:
AMI: ami-a0d838c7
us-east-1:
AMI: ami-66c71f19
LinuxECSRegionToAMI:
us-east-2:
AMI: ami-b86a5ddd
us-east-1:
AMI: ami-a7a242da
us-west-2:
AMI: ami-92e06fea
us-west-1:
AMI: ami-9ad4dcfa
eu-west-3:
AMI: ami-698b3d14
eu-west-2:
AMI: ami-f4e20693
eu-west-1:
AMI: ami-0693ed7f
eu-central-1:
AMI: ami-0799fa68
ap-northeast-2:
AMI: ami-a5dd70cb
ap-northeast-1:
AMI: ami-68ef940e
ap-southeast-2:
AMI: ami-ee884f8c
ap-southeast-1:
AMI: ami-0a622c76
ca-central-1:
AMI: ami-5ac94e3e
ap-south-1:
AMI: ami-2e461a41
sa-east-1:
AMI: ami-d44008b8
Resources:
ALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: 30
Subnets:
- !Ref SubnetA
- !Ref SubnetB
SecurityGroups:
- !GetAtt VPC.DefaultSecurityGroup
Listener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroup
LoadBalancerArn: !Ref ALB
Port: 80
Protocol: HTTP
ListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref TargetGroup
Conditions:
- Field: path-pattern
Values:
- '*'
ListenerArn: !Ref Listener
Priority: 1
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckPath: /grid/api/hub
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 20
HealthyThresholdCount: 2
Matcher:
HttpCode: 200
Port: 80
Protocol: HTTP
UnhealthyThresholdCount: 2
VpcId: !Ref VPC
Cluster:
Type: AWS::ECS::Cluster
Service:
DependsOn: Listener
Type: AWS::ECS::Service
Properties:
Cluster: !Ref Cluster
DesiredCount: 1
TaskDefinition: !Ref Definition
LoadBalancers:
- TargetGroupArn: !Ref TargetGroup
ContainerPort: 4444
ContainerName: hub
Definition:
Type: AWS::ECS::TaskDefinition
Properties:
Cpu: 2048
Memory: 2048
ContainerDefinitions:
- Name: hub
Essential: true
Image: selenium/hub:3.11.0
PortMappings:
- ContainerPort: 4444
- Name: chrome-65
Essential: true
Image: selenium/node-chrome:3.11.0
Links:
- hub
- Name: firefox-59
Essential: true
Image: selenium/node-firefox:3.11.0
Links:
- hub
- Name: chrome-64
Essential: true
Image: selenium/node-chrome:3.10.0
Links:
- hub
- Name: firefox-58
Essential: true
Image: selenium/node-firefox:3.10.0
Links:
- hub
- Name: chrome-63
Essential: true
Image: selenium/node-chrome:3.8.1-erbium
Links:
- hub
- Name: firefox-57
Essential: true
Image: selenium/node-firefox:3.8.1-erbium
Links:
- hub
VPCInbound:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !GetAtt VPC.DefaultSecurityGroup
IpProtocol: tcp
FromPort: 0
ToPort: 65535
SourceSecurityGroupId: !GetAtt VPC.DefaultSecurityGroup
HTTPInbound:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !GetAtt VPC.DefaultSecurityGroup
IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier:
- !Ref SubnetA
- !Ref SubnetB
LaunchConfigurationName: !Ref LaunchConfiguration
MinSize: 1
MaxSize: 1
DesiredCapacity: 1
Tags:
- Key: Name
Value: Selenium
PropagateAtLaunch: true
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
MaxBatchSize: 1
PauseTime: PT15M
WaitOnResourceSignals: true
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId: !FindInMap [LinuxECSRegionToAMI, !Ref "AWS::Region", AMI]
KeyName: !Ref KeyName
InstanceType: !Ref InstanceType
SecurityGroups:
- !GetAtt VPC.DefaultSecurityGroup
IamInstanceProfile: !Ref InstanceProfile
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum install -y aws-cfn-bootstrap
echo ECS_CLUSTER=${Cluster} >> /etc/ecs/ecs.config
cat /etc/ecs/ecs.config
start ecs
/opt/aws/bin/cfn-signal -e $? --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup
Win2012AutoScalingGroup:
Condition: UseIE
Type: AWS::AutoScaling::AutoScalingGroup
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: 1
PauseTime: PT15M
WaitOnResourceSignals: true
Properties:
VPCZoneIdentifier:
- !Ref SubnetA
- !Ref SubnetB
LaunchConfigurationName: !Ref Win2012LaunchConfiguration
MinSize: 1
MaxSize: 1
DesiredCapacity: 1
Tags:
- Key: Name
Value: Selenium
PropagateAtLaunch: true
Win2012LaunchConfiguration:
Condition: UseIE
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId: !FindInMap [Win2012RegionToAMI, !Ref "AWS::Region", AMI]
KeyName: !Ref KeyName
InstanceType: !Ref InstanceType
SecurityGroups:
- !GetAtt VPC.DefaultSecurityGroup
IamInstanceProfile: !Ref InstanceProfile
UserData:
Fn::Base64: !Sub |
<script>
cfn-init.exe -v -s ${AWS::StackName} -r Win2012LaunchConfiguration --region ${AWS::Region}
cfn-signal.exe -e %ERRORLEVEL% --resource Win2012AutoScalingGroup --stack ${AWS::StackName} --region ${AWS::Region}
shutdown -r
</script>
Metadata:
AWS::CloudFormation::Init:
config:
files:
"c:/tools/capabilities.json":
content: |
[{
"browserName": "internet explorer",
"maxInstances": 1,
"version": "autoversion",
"seleniumProtocol": "WebDriver"
}]
"c:/tools/admin.passwd":
content: !Ref AWS::StackId
"c:/tools/set-password.ps1":
source: https://raw.githubusercontent.com/aws-samples/aws-cfn-windows-hpc-template/master/cfn-init/change-administrator-password.ps1
"c:/tools/ewmp.cmd":
content: |
@ECHO OFF
FOR /F "tokens=3,*" %%a IN ('REG QUERY "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PATH') DO PATH %%a%%b
%*
commands:
1-configure-administrator-user:
command: >
powershell -NoProfile -File c:/tools/set-password.ps1 c:/tools/admin.passwd
waitAfterCompletion: 0
2-install-chocolatey:
command: >
powershell -NoProfile -ExecutionPolicy unrestricted -Command "Invoke-Expression ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
waitAfterCompletion: 0
3-install-selenium-ie-drivers:
command: >
c:\tools\ewmp choco install -y jdk8 selenium-ie-driver autologon
waitAfterCompletion: 0
4-setup-autologon:
command: !Sub >
c:\tools\ewmp autologon Administrator / ${AWS::StackId}
waitAfterCompletion: 0
5-configure-ie-configuration:
command: >
powershell -NoProfile -ExecutionPolicy unrestricted -Command "Invoke-Expression ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/dhoer/choco-selenium/master/ie-configuration.ps1'))"
waitAfterCompletion: 0
6-adjust-secure-mode-registry-key:
command: >
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v WarnonZoneCrossing /d "0" /t REG_DWORD /f
waitAfterCompletion: 0
7-setup-selenium-node:
command: !Sub >
c:\tools\ewmp choco install -y selenium --params "'/role:node /maxSession:1 /hub:http://${ALB.DNSName}:80 /capabilitiesJson:c:\tools\capabilities.json /autostart'"
waitAfterCompletion: 0
Win2016AutoScalingGroup:
Condition: UseIE
Type: AWS::AutoScaling::AutoScalingGroup
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: 1
PauseTime: PT15M
WaitOnResourceSignals: true
Properties:
VPCZoneIdentifier:
- !Ref SubnetA
- !Ref SubnetB
LaunchConfigurationName: !Ref Win2016LaunchConfiguration
MinSize: 1
MaxSize: 1
DesiredCapacity: 1
Tags:
- Key: Name
Value: Selenium
PropagateAtLaunch: true
Win2016LaunchConfiguration:
# AWS::CloudFormation::Init is shared with Win2012LaunchConfiguration
Condition: UseIE
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId: !FindInMap [Win2016RegionToAMI, !Ref "AWS::Region", AMI]
KeyName: !Ref KeyName
InstanceType: !Ref InstanceType
SecurityGroups:
- !GetAtt VPC.DefaultSecurityGroup
IamInstanceProfile: !Ref InstanceProfile
UserData:
Fn::Base64: !Sub |
<script>
cfn-init.exe -v -s ${AWS::StackName} -r Win2012LaunchConfiguration --region ${AWS::Region}
cfn-signal.exe -e %ERRORLEVEL% --resource Win2016AutoScalingGroup --stack ${AWS::StackName} --region ${AWS::Region}
shutdown -r
</script>
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref InstanceRole
InstanceRole:
Type: AWS::IAM::Role
Properties:
Path: "/"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: !Sub "ec2.${AWS::URLSuffix}"
Action: sts:AssumeRole
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
SubnetA:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
MapPublicIpOnLaunch: true
AvailabilityZone: !Select [ 0, !GetAZs "" ]
CidrBlock: 10.0.1.0/24
SubnetB:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
MapPublicIpOnLaunch: true
AvailabilityZone: !Select [ 1, !GetAZs "" ]
CidrBlock: 10.0.2.0/24
Gateway:
Type: AWS::EC2::InternetGateway
GatewayToInternet:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref Gateway
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Route:
DependsOn: GatewayToInternet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref Gateway
SubnetARouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref SubnetA
RouteTableId: !Ref RouteTable
SubnetBRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref SubnetB
RouteTableId: !Ref RouteTable
Outputs:
DNSName:
Description: DNS Name for the Selenium Hub
Value: !GetAtt ALB.DNSName
URL:
Description: URL of the service
Value: !Sub "http://${ALB.DNSName}"
ConsoleURL:
Description: URL of the service
Value: !Sub "http://${ALB.DNSName}/grid/console"