Skip to content

Commit 3ac0199

Browse files
committed
Add missing bin/ dirs and remove bin from .gitignore.
1 parent 918a18f commit 3ac0199

4 files changed

Lines changed: 152 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dist
1010
build
1111
eggs
1212
parts
13-
bin
1413
var
1514
sdist
1615
develop-eggs

chef/bin/provision-ec2-controller

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

chef/bin/update-chef-server

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
function echo_color {
4+
echo "\033[1m$1\033[0m"
5+
}
6+
7+
# change directory to the git repository root
8+
cd $(git rev-parse --show-toplevel)/chef
9+
10+
echo_color "Updating cookbooks..."
11+
knife cookbook upload -a
12+
13+
echo_color "Updating roles..."
14+
for role in `ls roles/*.rb`; do
15+
knife role from file $role
16+
done
17+
18+
data_bags=$(knife data bag list)
19+
20+
if test "${data_bags#*deis-formations}" == "$data_bags"; then
21+
echo_color "Creating deis-formations data bag..."
22+
knife data bag create deis-formations
23+
fi
24+
25+
if test "${data_bags#*deis-build}" == "$data_bags"; then
26+
echo_color "Creating deis-build data bag..."
27+
knife data bag create deis-build
28+
echo "Uploading initial data bag items..."
29+
knife data bag from file deis-build data_bags/deis-build/gitosis.json
30+
fi
31+
32+
if test "${data_bags#*deis-ssh}" == "$data_bags"; then
33+
echo_color "Creating deis-ssh data bag..."
34+
knife data bag create deis-ssh
35+
echo "Uploading initial data bag items..."
36+
for item in `ls data_bags/deis-ssh`; do
37+
knife data bag from file deis-ssh data_bags/deis-ssh/$item
38+
done
39+
fi
40+
41+
echo_color "Chef server up-to-date."

controller/bin/build-release-run

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/opt/deis/controller/venv/bin/python
2+
import os
3+
import sys
4+
import json
5+
6+
if __name__ == '__main__':
7+
# prepare pythonpath and django settings
8+
base_path = os.path.abspath(os.path.join(__file__, '..', '..'))
9+
sys.path.insert(0, base_path)
10+
os.environ['DJANGO_SETTINGS_MODULE'] = 'deis.settings'
11+
from api import models
12+
# deserialize build
13+
inp = sys.stdin.read()
14+
build = json.loads(inp)
15+
# pull username out of ssh key
16+
ssh_key = build.pop('ssh_key')
17+
username = ssh_key.split('_')[0]
18+
from django.contrib.auth.models import User
19+
u=User.objects.get(username=username)
20+
build['owner'] = u
21+
# lookup formation
22+
formation_id = build.pop('formation')
23+
formation = models.Formation.objects.get(
24+
owner=u, id=formation_id)
25+
build['formation'] = formation
26+
# create the new build
27+
b = models.Build.objects.create(**build)
28+
# send release signal
29+
models.release_signal.send(sender=b,
30+
build=b, formation=formation, user=u)
31+
# pull the formation again with the new release
32+
formation = models.Formation.objects.get(
33+
owner=u, id=formation_id)
34+
# calculate the formation and converge it
35+
databag = formation.calculate()
36+
formation.converge(databag)
37+
# return a json dump of the databag
38+
sys.stdout.write(json.dumps(databag))
39+
sys.stdout.flush()
40+
sys.exit(0)

0 commit comments

Comments
 (0)