-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathapp.py
More file actions
88 lines (77 loc) · 2.86 KB
/
app.py
File metadata and controls
88 lines (77 loc) · 2.86 KB
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
#!/usr/bin/env python3
"""
EC2 Windows provider example demonstrating EC2 runner configuration for Windows.
This example demonstrates:
- EC2 provider with Windows runners
- Custom Windows image builder with additional tools
- VPC configuration
"""
import aws_cdk as cdk
from aws_cdk import Stack
from aws_cdk import aws_ec2 as ec2
from cloudsnorkel.cdk_github_runners import (
GitHubRunners,
Ec2RunnerProvider,
RunnerImageComponent,
Os,
)
class Ec2WindowsProviderStack(Stack):
def __init__(self, scope, construct_id, **kwargs):
super().__init__(scope, construct_id, **kwargs)
# Note: Creating a VPC is not required. Providers can use the default VPC or an existing VPC.
# We create one here to make this example self-contained and testable.
# Create a VPC with public and private subnets
vpc = ec2.Vpc(
self, "VPC",
max_azs=2,
subnet_configuration=[
ec2.SubnetConfiguration(
name="Public",
subnet_type=ec2.SubnetType.PUBLIC,
cidr_mask=24
),
ec2.SubnetConfiguration(
name="Private",
subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS,
cidr_mask=24
)
]
)
# Create a Windows image builder for EC2
ec2_windows_image_builder = Ec2RunnerProvider.image_builder(
self, "EC2WindowsImageBuilder",
os=Os.WINDOWS,
vpc=vpc,
)
# Add custom components to the Windows image
ec2_windows_image_builder.add_component(
RunnerImageComponent.custom(
name="Windows Tools",
commands=[
"$ErrorActionPreference = 'Stop'",
"$url = \"https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe\"",
"$installer = \"$env:TEMP\\python-installer.exe\"",
"Invoke-WebRequest -Uri $url -OutFile $installer",
"$p = Start-Process $installer -PassThru -Wait -ArgumentList \"/quiet InstallAllUsers=1 PrependPath=1\"",
"if ($p.ExitCode -ne 0) { throw \"Exit code is $p.ExitCode\" }",
"Remove-Item $installer"
]
)
)
# EC2 provider with Windows
ec2_windows_provider = Ec2RunnerProvider(
self, "EC2WindowsProvider",
labels=["ec2", "windows", "x64"],
vpc=vpc,
image_builder=ec2_windows_image_builder,
)
# Create the GitHub runners infrastructure
GitHubRunners(
self, "GitHubRunners",
providers=[
ec2_windows_provider,
],
)
app = cdk.App()
Ec2WindowsProviderStack(app, "ec2-windows-provider-example")
app.synth()