Skip to content

Commit d82b975

Browse files
committed
Merge pull request #4086 from carmstrong/pr-4032
feat(contrib/ec2): allow easier selection of CoreOS version
2 parents 31578ed + b5682db commit d82b975

5 files changed

Lines changed: 51 additions & 44 deletions

File tree

contrib/aws/deis.template.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,7 @@
127127
},
128128

129129
"Mappings" : {
130-
"CoreOSAMIs" : {
131-
"eu-central-1" : { "PV" : "ami-fe6b52e3", "HVM" : "ami-f86b52e5" },
132-
"ap-northeast-1" : { "PV" : "ami-9ec1119e", "HVM" : "ami-9cc1119c" },
133-
"us-gov-west-1" : { "PV" : "ami-854828a6", "HVM" : "ami-874828a4" },
134-
"sa-east-1" : { "PV" : "ami-d9b839c4", "HVM" : "ami-d5b839c8" },
135-
"ap-southeast-2" : { "PV" : "ami-7985fc43", "HVM" : "ami-7b85fc41" },
136-
"ap-southeast-1" : { "PV" : "ami-d4033b86", "HVM" : "ami-da033b88" },
137-
"us-east-1" : { "PV" : "ami-c16583aa", "HVM" : "ami-c36583a8" },
138-
"us-west-2" : { "PV" : "ami-995f60a9", "HVM" : "ami-975f60a7" },
139-
"us-west-1" : { "PV" : "ami-877a92c3", "HVM" : "ami-857a92c1" },
140-
"eu-west-1" : { "PV" : "ami-e38cfc94", "HVM" : "ami-e18cfc96" }
141-
},
130+
"CoreOSAMIs" : {},
142131
"RootDevices" : {
143132
"HVM" : { "Name": "/dev/xvda" },
144133
"PV" : { "Name": "/dev/sda" }

contrib/aws/gen-json.py

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
#!/usr/bin/env python
2+
import argparse
23
import json
34
import os
5+
import urllib
46
import yaml
57

8+
parser = argparse.ArgumentParser()
9+
parser.add_argument('--channel', help='the CoreOS channel to use', default='stable')
10+
parser.add_argument('--version', help='the CoreOS version to use', default='current')
11+
args = vars(parser.parse_args())
12+
13+
url = "http://{channel}.release.core-os.net/amd64-usr/{version}/coreos_production_ami_all.json".format(**args)
14+
try:
15+
amis = json.load(urllib.urlopen(url))
16+
except (IOError, ValueError):
17+
print "The URL {} is invalid.".format(url)
18+
raise
19+
620
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
721

822
# Add AWS-specific units to the shared user-data
@@ -72,13 +86,13 @@
7286
'''
7387

7488
new_units = [
75-
dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}),
76-
dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}),
77-
dict({'name': 'docker.service', 'drop-ins': [{'name': '90-after-docker-volume.conf', 'content': DOCKER_DROPIN}]}),
78-
dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}),
79-
dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}),
80-
dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}),
81-
dict({'name': 'etcd.service', 'drop-ins': [{'name': '90-after-etcd-volume.conf', 'content': ETCD_DROPIN}]})
89+
dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}),
90+
dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}),
91+
dict({'name': 'docker.service', 'drop-ins': [{'name': '90-after-docker-volume.conf', 'content': DOCKER_DROPIN}]}),
92+
dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}),
93+
dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}),
94+
dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}),
95+
dict({'name': 'etcd.service', 'drop-ins': [{'name': '90-after-etcd-volume.conf', 'content': ETCD_DROPIN}]})
8296
]
8397

8498
data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r'))
@@ -93,37 +107,38 @@
93107
header = ["#cloud-config", "---"]
94108
dump = yaml.dump(data, default_flow_style=False)
95109

96-
template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'),'r'))
110+
template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'), 'r'))
97111

98-
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ "\n", header + dump.split("\n") ]
112+
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = ["\n", header + dump.split("\n")]
99113
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
114+
template['Mappings']['CoreOSAMIs'] = dict(map(lambda n: (n['name'], dict(PV=n['pv'], HVM=n['hvm'])), amis['amis']))
100115

101116
VPC_ID = os.getenv('VPC_ID', None)
102117
VPC_SUBNETS = os.getenv('VPC_SUBNETS', None)
103118
VPC_PRIVATE_SUBNETS = os.getenv('VPC_PRIVATE_SUBNETS', VPC_SUBNETS)
104119
VPC_ZONES = os.getenv('VPC_ZONES', None)
105120

106121
if VPC_ID and VPC_SUBNETS and VPC_ZONES and len(VPC_SUBNETS.split(',')) == len(VPC_ZONES.split(',')):
107-
# skip VPC, subnet, route, and internet gateway creation
108-
del template['Resources']['VPC']
109-
del template['Resources']['Subnet1']
110-
del template['Resources']['Subnet2']
111-
del template['Resources']['Subnet1RouteTableAssociation']
112-
del template['Resources']['Subnet2RouteTableAssociation']
113-
del template['Resources']['InternetGateway']
114-
del template['Resources']['GatewayToInternet']
115-
del template['Resources']['PublicRouteTable']
116-
del template['Resources']['PublicRoute']
117-
del template['Resources']['CoreOSServerLaunchConfig']['DependsOn']
118-
del template['Resources']['DeisWebELB']['DependsOn']
119-
120-
# update VpcId fields
121-
template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID
122-
template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID
123-
124-
# update subnets and zones
125-
template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',')
126-
template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_PRIVATE_SUBNETS.split(',')
127-
template['Resources']['DeisWebELB']['Properties']['Subnets'] = VPC_SUBNETS.split(',')
122+
# skip VPC, subnet, route, and internet gateway creation
123+
del template['Resources']['VPC']
124+
del template['Resources']['Subnet1']
125+
del template['Resources']['Subnet2']
126+
del template['Resources']['Subnet1RouteTableAssociation']
127+
del template['Resources']['Subnet2RouteTableAssociation']
128+
del template['Resources']['InternetGateway']
129+
del template['Resources']['GatewayToInternet']
130+
del template['Resources']['PublicRouteTable']
131+
del template['Resources']['PublicRoute']
132+
del template['Resources']['CoreOSServerLaunchConfig']['DependsOn']
133+
del template['Resources']['DeisWebELB']['DependsOn']
134+
135+
# update VpcId fields
136+
template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID
137+
template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID
138+
139+
# update subnets and zones
140+
template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',')
141+
template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_PRIVATE_SUBNETS.split(',')
142+
template['Resources']['DeisWebELB']['Properties']['Subnets'] = VPC_SUBNETS.split(',')
128143

129144
print json.dumps(template)

contrib/aws/provision-aws-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bailout() {
4949

5050
# create an AWS cloudformation stack based on CoreOS's default template
5151
aws cloudformation create-stack \
52-
--template-body "$($THIS_DIR/gen-json.py)" \
52+
--template-body "$($THIS_DIR/gen-json.py --channel $COREOS_CHANNEL --version $COREOS_VERSION)" \
5353
--stack-name $STACK_NAME \
5454
--parameters "$(<$THIS_DIR/cloudformation.json)" \
5555
$EXTRA_AWS_CLI_ARGS

contrib/aws/update-aws-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $CONTRIB_DIR/util/check-user-data.sh
3232

3333
# update the AWS CloudFormation stack
3434
aws cloudformation update-stack \
35-
--template-body "$($THIS_DIR/gen-json.py)" \
35+
--template-body "$($THIS_DIR/gen-json.py --channel $COREOS_CHANNEL --version $COREOS_VERSION)" \
3636
--stack-name $NAME \
3737
--parameters "$(<$THIS_DIR/cloudformation.json)" \
3838
$EXTRA_AWS_CLI_ARGS

contrib/utils.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ function echo_red {
1111
function echo_green {
1212
echo -e "\033[0;32m$1\033[0m"
1313
}
14+
15+
COREOS_CHANNEL=${COREOS_CHANNEL:-stable}
16+
COREOS_VERSION=${COREOS_VERSION:-647.2.0}

0 commit comments

Comments
 (0)