-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
128 lines (109 loc) · 3.78 KB
/
__main__.py
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
"""
Open edX Instance deployment and provision.
"""
from pulumi import export, Config, ResourceOptions, get_stack
from pulumi_aws import ec2, iam, GetAmiFilterArgs
import provisioners
def decode_key(key):
if key.startswith("-----BEGIN RSA PRIVATE KEY-----"):
return key
return key.encode("ascii")
stack = get_stack()
config = Config()
key_name = config.get("keyName")
public_key = config.get("publicKey")
private_key = config.require_secret("privateKey").apply(decode_key)
private_key_passphrase = config.get_secret("privateKeyPassphrase")
tags = {"pulumi_managed": "true", "auto_off": "true"}
size = "t3a.large"
# TODO make this a config variable
OPENEDX_RELEASE = "open-release/lilac.master"
ami = ec2.get_ami(
most_recent=True,
owners=["679593333241"],
filters=[
GetAmiFilterArgs(
name="name",
values=["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
),
],
)
# Create a security group
security_group = ec2.SecurityGroup(
"openedx-sg",
description="Basic Open edX security group",
egress=[
ec2.SecurityGroupEgressArgs(
protocol="-1",
from_port=0,
to_port=0,
cidr_blocks=["0.0.0.0/0"],
)
],
ingress=[
ec2.SecurityGroupIngressArgs(
protocol=ec2.ProtocolType.TCP,
from_port=80,
to_port=80,
cidr_blocks=["0.0.0.0/0"],
),
ec2.SecurityGroupIngressArgs(
protocol=ec2.ProtocolType.TCP,
from_port=22,
to_port=22,
cidr_blocks=["0.0.0.0/0"],
),
ec2.SecurityGroupIngressArgs(
protocol=ec2.ProtocolType.TCP,
from_port=18000,
to_port=18999,
cidr_blocks=["0.0.0.0/0"],
),
],
tags={**tags, "Name": f"Open edX {stack}"},
)
if key_name is None:
key = ec2.KeyPair("openedx-key", public_key=public_key)
key_name = key.key_name
# TODO Make the spot price a config variable
openedx_instance = ec2.Instance(
"openedx-instance",
# spot_price="0.03",
instance_type=size,
vpc_security_group_ids=[security_group.id],
ami=ami.id,
key_name=key_name,
root_block_device=ec2.InstanceRootBlockDeviceArgs(
delete_on_termination=True,
volume_size=50,
encrypted=True,
),
tags={**tags, "Name": f"Open edX {stack}"},
)
# Provision EC2 instance
conn = provisioners.ConnectionArgs(
host=openedx_instance.public_ip,
username="ubuntu",
private_key=private_key,
private_key_passphrase=private_key_passphrase,
)
# https://openedx.atlassian.net/wiki/spaces/OpenOPS/pages/1969455764/Koa+Native+Open+edX+platform+Ubuntu+20.04+64+bit+Installation
install_openedx = provisioners.RemoteExec(
"install-openedx",
conn=conn,
commands=[
"sudo locale-gen en_GB en_GB.UTF-8",
"sudo dpkg --configure -a",
"sudo apt-get update",
"sudo apt-get upgrade -y",
"echo -e \"EDXAPP_LMS_BASE: '$(curl ipinfo.io/ip)'\nEDXAPP_CMS_BASE: '$(curl ipinfo.io/ip):18010'\" > config.yml",
'export LC_ALL="en_GB.UTF-8"',
'export LC_CTYPE="en_GB.UTF-8"',
#f"wget https://raw.githubusercontent.com/edx/configuration/{OPENEDX_RELEASE}/util/install/ansible-bootstrap.sh -O - | sudo -E bash",
#f"wget https://raw.githubusercontent.com/edx/configuration/{OPENEDX_RELEASE}/util/install/generate-passwords.sh -O - | bash",
#f"export OPENEDX_RELEASE={OPENEDX_RELEASE} && wget https://raw.githubusercontent.com/edx/configuration/{OPENEDX_RELEASE}/util/install/native.sh -O - | bash & > install.out",
],
opts=ResourceOptions(depends_on=[openedx_instance], parent=openedx_instance),
)
export("public_ip", openedx_instance.public_ip)
export("public_dns", openedx_instance.public_dns)