|
1 | 1 | #!/usr/bin/env python |
2 | 2 | import json |
3 | 3 | import os |
| 4 | +import yaml |
4 | 5 |
|
5 | | -template = json.load(open("deis.template.json",'r')) |
| 6 | +CURR_DIR = os.path.dirname(os.path.realpath(__file__)) |
6 | 7 |
|
7 | | -with open('../coreos/user-data','r') as f: |
8 | | - lines = f.readlines() |
| 8 | +# Add EC2-specific units to the shared user-data |
| 9 | +FORMAT_EPHEMERAL = ''' |
| 10 | + [Unit] |
| 11 | + Description=Formats the ephemeral drive |
| 12 | + ConditionPathExists=!/etc/docker-volume-formatted |
| 13 | + [Service] |
| 14 | + Type=oneshot |
| 15 | + RemainAfterExit=yes |
| 16 | + ExecStart=/usr/sbin/wipefs -f /dev/xvdf |
| 17 | + ExecStart=/usr/sbin/mkfs.btrfs -f /dev/xvdf |
| 18 | + ExecStart=/bin/touch /etc/docker-volume-formatted |
| 19 | +''' |
| 20 | +DOCKER_MOUNT = ''' |
| 21 | + [Unit] |
| 22 | + Description=Mount ephemeral to /var/lib/docker |
| 23 | + Requires=format-ephemeral.service |
| 24 | + After=format-ephemeral.service |
| 25 | + Before=docker.service |
| 26 | + [Mount] |
| 27 | + What=/dev/xvdf |
| 28 | + Where=/var/lib/docker |
| 29 | + Type=btrfs |
| 30 | +''' |
9 | 31 |
|
10 | | -template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ '', lines ] |
| 32 | +data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r')) |
| 33 | +data['coreos']['units'].append(dict({'name': 'format-ephemeral.service', 'command': 'start', 'content': FORMAT_EPHEMERAL})) |
| 34 | +data['coreos']['units'].append(dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': DOCKER_MOUNT})) |
| 35 | + |
| 36 | +header = ["#cloud-config", "---"] |
| 37 | +dump = yaml.dump(data, default_flow_style=False) |
| 38 | + |
| 39 | +template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'),'r')) |
| 40 | + |
| 41 | +template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ "\n", header + dump.split("\n") ] |
11 | 42 | template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3)) |
12 | 43 |
|
13 | 44 | VPC_ID = os.getenv('VPC_ID', None) |
|
0 commit comments