|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# ec2 settings |
| 4 | +region="us-west-2" |
| 5 | +image="ami-bf41d28f" |
| 6 | +flavor="m1.large" |
| 7 | +ebs_size=100 |
| 8 | +sg_name=deis-controller |
| 9 | +sg_src=0.0.0.0/0 |
| 10 | +key_name=deis-controller |
| 11 | +export EC2_URL=https://ec2.$region.amazonaws.com/ |
| 12 | + |
| 13 | +# ssh settings |
| 14 | +ssh_key_path=~/.ssh/$key_name |
| 15 | +ssh_user="ubuntu" |
| 16 | + |
| 17 | +# chef settings |
| 18 | +node_name="deis-controller" |
| 19 | +run_list="role[deis-controller]" |
| 20 | + |
| 21 | +function echo_color { |
| 22 | + echo "\033[1m$1\033[0m" |
| 23 | +} |
| 24 | + |
| 25 | +# create security group and authorize ingress |
| 26 | +if ! ec2-describe-group | grep -q "$sg_name"; then |
| 27 | + echo_color "Creating security group: $sg_name" |
| 28 | + set -x |
| 29 | + ec2-create-group $sg_name -d "Managed by Deis" |
| 30 | + set +x |
| 31 | + echo_color "Authorizing TCP ports 22,80,443 from $sg_src..." |
| 32 | + set -x |
| 33 | + ec2-authorize deis-controller -P tcp -p 22 -s $sg_src >/dev/null |
| 34 | + ec2-authorize deis-controller -P tcp -p 80 -s $sg_src >/dev/null |
| 35 | + ec2-authorize deis-controller -P tcp -p 443 -s $sg_src >/dev/null |
| 36 | + set +x |
| 37 | +else |
| 38 | + echo_color "Security group $sg_name exists" |
| 39 | +fi |
| 40 | + |
| 41 | +# create ssh keypair and store it |
| 42 | +if ! test -e $ssh_key_path; then |
| 43 | + echo "Creating new SSH key: $key_name" |
| 44 | + set -x |
| 45 | + ec2-create-keypair $key_name > $ssh_key_path |
| 46 | + chmod 600 $ssh_key_path |
| 47 | + set +x |
| 48 | + echo "Saved to $ssh_key_path" |
| 49 | +else |
| 50 | + echo_color "SSH key $ssh_key_path exists" |
| 51 | +fi |
| 52 | + |
| 53 | +# forcing update of chef server |
| 54 | +`dirname $0`/update-chef-server |
| 55 | + |
| 56 | +# trigger ec2 instance bootstrap |
| 57 | +echo_color "Provisioning $node_name with knife ec2..." |
| 58 | +set -x |
| 59 | +knife ec2 server create \ |
| 60 | + --region $region \ |
| 61 | + --image $image \ |
| 62 | + --flavor $flavor \ |
| 63 | + --groups $sg_name \ |
| 64 | + --tags Name=$node_name \ |
| 65 | + --ssh-key $key_name \ |
| 66 | + --ssh-user $ssh_user \ |
| 67 | + --identity-file $ssh_key_path \ |
| 68 | + --node-name $node_name \ |
| 69 | + --ebs-size $ebs_size \ |
| 70 | + --run-list $run_list |
| 71 | +set +x |
0 commit comments