forked from derbyjs/derby-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
95 lines (73 loc) · 2.63 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
from fabric.api import task, env, run, local, sudo, put, execute
from fabric.context_managers import cd
from fabric.contrib.files import exists
from fabric.utils import error
from time import sleep
import sys
env.use_ssh_config = True
env.roledefs['stage'] = ['derbyjs-2.do.leverha.us']
env.roledefs['prod'] = ['derbyjs-1.do.leverha.us']
#env.user = 'deploy'
lever = {}
lever['repo_cache'] = '~/.deploy_repo_cache'
lever['image'] = 'lever/derbyjs'
lever['repository'] = 'https://github.com/derbyjs/derby-site.git'
lever['services'] = ['derbyjs/mongo', 'derbyjs/redis', 'derbyjs/derby-site']
# Setup tasks
@task
def bootstrap():
'''Places upstart and varnish configs, reload varnish'''
if not exists('/etc/varnish'):
error('Varnish is not installed. Has this host been chef bootstrapped with the "derbyjs-com" role?')
put('varnish/*', remote_path='/etc/varnish/', use_sudo=True)
sudo('mkdir -p /etc/init/derbyjs')
put('init/*', remote_path='/etc/init/derbyjs/', use_sudo=True)
sudo('service varnish reload')
# Build/deploy tasks
@task
def tag(tag):
'''Tag the current HEAD, pushes tags to origin'''
local('git tag %s' % (tag))
local('git push origin --tags')
def initctl(action=None, service=None):
'''Control upstart services'''
if action not in ['start', 'stop', 'status']:
print "Must provide a valid action to initctl() (start, stop, status)"
sys.exit(1)
if service is None:
services = lever['services']
else:
services = [service]
for svc in services:
sudo('%s %s' % (action, svc), warn_only=True)
@task
def start():
'''Start derby-examples AND dependent services (redis, mongo)'''
initctl('start')
@task
def stop():
'''Stop derby-examples AND dependent services (redis, mongo)'''
initctl('stop')
@task
def deploy(tag):
'''Pull latest master from origin, build new docker image, restart derby-site services'''
# TODO Start redis/mongo services if not running
if not exists('%s/%s' % (lever['repo_cache'], 'derby-site')):
execute(clone)
with cd('%s/derby-site' % (lever['repo_cache'])):
#run('git fetch')
#run('git reset --hard %s' % tag)
run('git pull -r')
run('docker build -t derbyjs/derby-site .')
sleep(2)
# Ensure dependent services running
execute(start)
# Proper restart
sudo('stop derbyjs/derby-site', warn_only=True)
sudo('start derbyjs/derby-site')
def clone():
if not exists(lever['repo_cache']):
run('mkdir %s' % lever['repo_cache'])
with cd(lever['repo_cache']):
run('git clone %s' % lever['repository'])