Skip to content

Commit 0ff2ce2

Browse files
committed
Merge pull request #869 from deis/contrib_use_user_data
fix(contrib/coreos/user-data): prevent reboots; use $private_ipv4 for etcd/fleet
2 parents a99c75a + 9e3b471 commit 0ff2ce2

7 files changed

Lines changed: 56 additions & 46 deletions

File tree

Vagrantfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ Vagrant.configure("2") do |config|
4747
# Enable NFS for sharing the host machine into the coreos-vagrant VM.
4848
config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
4949

50-
# disable update-engine to prevent reboots
51-
config.vm.provision :shell, :inline => "systemctl stop update-engine-reboot-manager && systemctl disable update-engine-reboot-manager && systemctl mask update-engine-reboot-manager", :privileged => true
52-
config.vm.provision :shell, :inline => "systemctl stop update-engine && systemctl disable update-engine && systemctl mask update-engine", :privileged => true
53-
5450
# user-data bootstrapping
5551
config.vm.provision :file, :source => "contrib/coreos/user-data", :destination => "/tmp/vagrantfile-user-data"
5652
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true

contrib/coreos/user-data

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ coreos:
55
# generate a new token for each unique cluster from https://discovery.etcd.io/new
66
# uncomment the following line and replace it with your discovery URL
77
# discovery: https://discovery.etcd.io/12345693838asdfasfadf13939923
8-
addr: $public_ipv4:4001
8+
addr: $private_ipv4:4001
99
peer-addr: $private_ipv4:7001
1010
units:
1111
- name: docker.service
@@ -44,5 +44,25 @@ coreos:
4444
Description=fleet
4545

4646
[Service]
47-
Environment=FLEET_PUBLIC_IP=$public_ipv4
47+
Environment=FLEET_PUBLIC_IP=$private_ipv4
4848
ExecStart=/usr/bin/fleet
49+
- name: stop-reboot-manager.service
50+
command: start
51+
content: |
52+
[Unit]
53+
Description=stop update-engine-reboot-manager
54+
55+
[Service]
56+
Type=oneshot
57+
ExecStart=/usr/bin/systemctl stop update-engine-reboot-manager.service
58+
ExecStartPost=/usr/bin/systemctl mask update-engine-reboot-manager.service
59+
- name: stop-update-engine.service
60+
command: start
61+
content: |
62+
[Unit]
63+
Description=stop update-engine
64+
65+
[Service]
66+
Type=oneshot
67+
ExecStart=/usr/bin/systemctl stop update-engine.service
68+
ExecStartPost=/usr/bin/systemctl mask update-engine.service

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)