Skip to content

Commit 2739380

Browse files
author
Gabriel Monroy
committed
add helper script for provisioning an ec2 controller
1 parent 98b14f0 commit 2739380

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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="recipe[deis::default],recipe[deis::gitosis],recipe[deis::build],recipe[deis::postgresql],recipe[deis::server]"
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+
# trigger ec2 instance bootstrap
54+
echo_color "Provisioning $node_name with knife ec2..."
55+
set -x
56+
knife ec2 server create \
57+
--region $region \
58+
--image $image \
59+
--flavor $flavor \
60+
--groups $sg_name \
61+
--tags Name=$node_name \
62+
--ssh-key $key_name \
63+
--ssh-user $ssh_user \
64+
--identity-file $ssh_key_path \
65+
--node-name $node_name \
66+
--ebs-size $ebs_size \
67+
--run-list $run_list
68+
set +x

0 commit comments

Comments
 (0)