-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
65 lines (55 loc) · 2.19 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
import os, random, string
from fabric.api import run, env, cd, settings, put, local, shell_env
# load ~/.ssh/id_rsa
env.key_filename = os.getenv('HOME', '/root') + '/.ssh/id_rsa'
# determine hosts
branch = os.getenv('DRONE_BRANCH', '')
if branch == "master":
env.hosts = ["marge.lavaboom.io:36104"]
api_uri = "https://api.lavaboom.com"
root_domain = "lavaboom.com"
elif branch == "staging":
env.hosts = ["lisa.lavaboom.io:36412"]
api_uri = "https://api.lavaboom.io"
root_domain = "lavaboom.io"
elif branch == "develop":
env.hosts = ["bart.lavaboom.io:36467"]
api_uri = "https://api.lavaboom.co"
root_domain = "lavaboom.co"
# build
def build():
# we install required npm packages with increased number of retries and if it fails we use backup mirror
local("npm install --fetch-retries 3 -g gulp || npm install --fetch-retries 3 --registry http://registry.npmjs.eu -g gulp")
local("npm install --fetch-retries 3 || npm install --fetch-retries 3 --registry http://registry.npmjs.eu")
if branch == "master" or branch == "staging":
with shell_env(API_URI=api_uri, ROOT_DOMAIN=root_domain):
local("gulp production")
elif branch == "develop":
with shell_env(API_URI=api_uri, ROOT_DOMAIN=root_domain):
local("gulp develop")
else:
local("gulp develop")
def deploy():
branch = os.getenv('DRONE_BRANCH', 'master')
commit = os.getenv('DRONE_COMMIT', 'master')
tmp_dir = '/tmp/' + ''.join(random.choice(string.lowercase) for i in xrange(10))
local('tar cvfz dist.tgz dist/')
run('mkdir ' + tmp_dir)
with cd(tmp_dir):
run('mkdir -p ' + tmp_dir + '/web/dist')
put('dist.tgz', tmp_dir + '/web/dist.tgz')
put('Dockerfile', tmp_dir + '/web/Dockerfile')
put('website.conf', tmp_dir + '/web/website.conf')
with cd('web'):
run('tar -xzvf dist.tgz')
run('docker build -t registry.lavaboom.io/lavaboom/web-' + branch + ' .')
run('git clone [email protected]:lavab/docker.git')
with settings(warn_only=True):
run('docker rm -f web-' + branch)
with cd('docker/runners'):
run('./web-' + branch + '.sh')
run('rm -r ' + tmp_dir)
def integrate():
build()
if branch == "master" or branch == "staging" or branch == "develop":
deploy()