Skip to content

Commit 9e3b471

Browse files
committed
fix(contrib/ec2): use shared user-data
Previously, contrib/ec2 used its own stripped-down user-data file. We have customizations in contrib/coreos/user-data, and we want all providers using the same user-data file. To do this, we introduce a Python script which will dynamically generate the appropriate JSON payload from contrib/coreos/user-data when running the provision-ec2-cluster script. While ideally this would be achieved without requiring an external scripting language, this is very easy to achieve in Python, and we already require Python as a dependency (since the AWS CLI is a Python package). Also, have EC2 respect DEIS_NUM_INSTANCES like every other provider does. closes #858, #826
1 parent 8dfbe8c commit 9e3b471

5 files changed

Lines changed: 34 additions & 40 deletions

File tree

contrib/ec2/README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,29 @@ $ ssh-keygen -q -t rsa -f ~/.ssh/deis -N '' -C deis
2525
$ aws ec2 import-key-pair --key-name deis --public-key-material file://~/.ssh/deis.pub
2626
```
2727

28-
## Customize cloudformation.json
29-
Edit [cloudformation.json][cf-params], ensuring to add a new discovery URL.
30-
You can get a new one by sending a new request to http://discovery.etcd.io/new.
28+
## Choose number of instances
29+
By default, the script will provision 3 servers. You can override this by setting `DEIS_NUM_INSTANCES`:
3130
```console
31+
$ export DEIS_NUM_INSTANCES=5
32+
```
33+
34+
## Customize user-data
35+
Edit [user-data](../coreos/user-data) and add a new discovery URL.
36+
You can get a new one by sending a request to http://discovery.etcd.io/new.
37+
38+
## Customize cloudformation.json
39+
By default, this script spins up m3.large instances. You can override this
40+
by adding a new entry to [cloudformation.json](cloudformation.json) like so:
41+
42+
```
3243
{
33-
"ParameterKey": "DiscoveryURL",
34-
"ParameterValue": "https://discovery.etcd.io/40826e8da55f4d9026935ab67b243c6a"
44+
"ParameterKey": "InstanceType",
45+
"ParameterValue": "m3.xlarge"
3546
}
3647
```
37-
NOTE: If you're interested in running your own discovery endpoint or want to know more
38-
about the discovery URL, see http://discovery.etcd.io for more information. You can also
39-
read more on how you can customize this cluster by looking at the
40-
[CoreOS EC2 template][template] and applying it to [cloudformation.json][cf-params].
48+
49+
The only entry in cloudformation.json required to launch your cluster is `KeyPair`,
50+
which is already filled out. The defaults will be applied for the other settings.
4151

4252
## Run the provision script
4353
Run the [cloudformation provision script][pro-script] to spawn a new CoreOS cluster:
@@ -77,5 +87,4 @@ email: info@opdemand.com
7787

7888
[aws-cli]: https://github.com/aws/aws-cli
7989
[template]: https://s3.amazonaws.com/coreos.com/dist/aws/coreos-alpha.template
80-
[cf-params]: cloudformation.json
8190
[pro-script]: provision-ec2-cluster.sh

contrib/ec2/cloudformation.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@
22
{
33
"ParameterKey": "KeyPair",
44
"ParameterValue": "deis"
5-
},
6-
{
7-
"ParameterKey": "DiscoveryURL",
8-
"ParameterValue": "https://discovery.etcd.io/06f9b54a2ffe65f072109924604b4cd7"
95
}
106
]

contrib/ec2/deis.template

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@
4444
"Description": "Number of nodes in cluster (3-12).",
4545
"Type": "Number"
4646
},
47-
"DiscoveryURL": {
48-
"Description": "An unique etcd cluster discovery URL. Grab a new token from https://discovery.etcd.io/new",
49-
"Type": "String"
50-
},
51-
"AdvertisedIPAddress": {
52-
"Description": "Use 'private' if your etcd cluster is within one region or 'public' if it spans regions or cloud providers.",
53-
"Default": "private",
54-
"AllowedValues": ["private", "public"],
55-
"Type": "String"
56-
},
5747
"AllowSSHFrom": {
5848
"Description": "The net block (CIDR) that SSH is available to.",
5949
"Default": "0.0.0.0/0",
@@ -169,21 +159,7 @@
169159
"InstanceType": {"Ref": "InstanceType"},
170160
"KeyName": {"Ref": "KeyPair"},
171161
"SecurityGroups": [{"Ref": "CoreOSSecurityGroup"}, {"Ref": "DeisSecurityGroup"}],
172-
"UserData" : { "Fn::Base64":
173-
{ "Fn::Join": [ "", [
174-
"#cloud-config\n\n",
175-
"coreos:\n",
176-
" etcd:\n",
177-
" discovery: ", { "Ref": "DiscoveryURL" }, "\n",
178-
" addr: $", { "Ref": "AdvertisedIPAddress" }, "_ipv4:4001\n",
179-
" peer-addr: $", { "Ref": "AdvertisedIPAddress" }, "_ipv4:7001\n",
180-
" units:\n",
181-
" - name: etcd.service\n",
182-
" command: start\n",
183-
" - name: fleet.service\n",
184-
" command: start\n"
185-
] ]
186-
}
162+
"UserData" : { "Fn::Base64": { "Fn::Join": [ "", [ ] ] }
187163
}
188164
}
189165
}

contrib/ec2/gen-json.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
import json
3+
import os
4+
5+
template = json.load(open("deis.template",'r'))
6+
7+
with open('../coreos/user-data','r') as f:
8+
lines = f.readlines()
9+
10+
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ '', lines ]
11+
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
12+
13+
print json.dumps(template)

contrib/ec2/provision-ec2-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fi
1818

1919
# create an EC2 cloudformation stack based on CoreOS's default template
2020
aws cloudformation create-stack \
21-
--template-body "$(<deis.template)" \
21+
--template-body "$(./gen-json.py)" \
2222
--stack-name deis \
2323
--parameters "$(<cloudformation.json)"
2424

0 commit comments

Comments
 (0)