-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
55 lines (40 loc) · 1.73 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from fabric.api import env, local, task, put, sudo, run, env, cd, execute
if env.get('vagrant'):
vagrant()
@task
def vagrant():
''' Use local vagrant environment '''
exists = local('(cd providers/vagrant && vagrant status | grep "default .* not created" || exit 0)', capture=True)
if len(exists) == 0:
exists = local('(cd providers/vagrant && vagrant status | grep "default .* aborted" || exit 0)', capture=True)
print len(exists)
if len(exists) > 0:
local("(cd providers/vagrant && vagrant up)")
env.hosts = ['127.0.0.1:2222']
env.user = 'vagrant'
result = local('(cd providers/vagrant && vagrant ssh-config | grep IdentityFile)', capture=True)
env.key_filename = result.split()[1].strip('\"')
@task
def provision():
with cd("/srv/dev-puppet"):
sudo("puppet apply -d --modulepath=modules manifests/site.pp")
@task
def ship_source():
''' ship env.source_path code to specified hosts'''
local('(cd ' + env.source_path + " && tar cfz /tmp/mclean-build.tar.gz *)")
put('/tmp/mclean-build.tar.gz', '/tmp/mclean-build.tar.gz', use_sudo=True)
sudo("rm -rf /tmp/mclean-build")
sudo("mkdir /tmp/mclean-build ; tar xfz /tmp/mclean-build.tar.gz -C /tmp/mclean-build")
sudo("ls /tmp/mclean-build")
with cd("/tmp/mclean-build"):
sudo("docker build -t mclean-build/" + env.target + " .")
execute(update_container, env.target)
@task
def update_container(target):
'''update container: target'''
# TODO make better
sudo('mkdir -p /tmp/mclean-remote')
put('./mclean-remote/update_container.js', '/tmp/mclean-remote', use_sudo=True)
with cd("/tmp/mclean-remote"):
sudo('npm install async optimist docker.io redis')
sudo('node update_container.js mclean-build/' + target)