-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
85 lines (73 loc) · 3.32 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
import os
import smtplib
from email.mime.text import MIMEText
from fabric.api import env, cd, run, shell_env, sudo, hosts, execute, settings, local
from fabric.colors import green
env.hosts = ['134.213.147.235']
env.user = 'root'
env.key_filename = '~/.ssh/id_di'
env.forward_agent = True
def deploy(js=False):
if js:
# TODO automatically figure out if produciton build needs updated
# (we don't run webpack watch with produciton settings as that
# generates files for intermediate states. We only want to run it
# once before deployment)
local('./node_modules/.bin/webpack -p --config webpack.prod.config.js')
local('git add webpack-stats-prod.json ditto/static/dist')
# TODO if last commit isn't pushed we could --amend and avoid
# the extra commit
local('git commit -m "Update production assets"')
changes = local('git log heroku/master.. --oneline --no-color --reverse > /tmp/log; cat /tmp/log', capture=True)
local('git push origin master')
local('git push heroku master')
for line in changes.splitlines():
print green(line)
with settings(warn_only=True):
execute(email, changes)
def builddb():
with cd('/srv/venv/ditto/ditto'):
with shell_env(DJANGO_CONFIGURATION='Production', DJANGO_SETTINGS_MODULE='config.production'):
sudo("echo 'drop database app_data;create database app_data' | ../../bin/python manage.py dbshell",
user="pydev")
sudo("echo 'source /usr/lib/mongooseim//lib/ejabberd-2.1.8+mim-1.5.0/priv/mysql.sql' | ../../bin/python manage.py dbshell",
user="pydev")
# Set up data for main site
sudo(' ../../bin/python manage.py migrate',
user="pydev")
sudo(' ../../bin/python manage.py runscript setup_test_data',
user="pydev")
# Delete the mnesia database
sudo('rm -rf /usr/lib/mongooseim/Mnesia*')
# Restart chat so anything cached by the chat server is forgotten
sudo('mongooseimctl restart')
# Set up data for example network for Kvoti
#newnetwork('di')
def newnetwork(name):
# TODO this needs to create the Tenant record in the main 'database'
with cd('/srv/venv/ditto/ditto'):
with shell_env(DJANGO_CONFIGURATION='Production', DJANGO_TENANT=name):
sudo(' ../../bin/python manage.py migrate',
user="pydev")
sudo(' ../../bin/python manage.py runscript setup_test_data',
user="pydev")
sudo(' ../../bin/python manage.py runscript setup_test_form',
user="pydev")
# don't set up chat data for now while we're playing with the chat bot
# sudo(' ../../bin/python manage.py runscript setup_chat_data',
# user="pydev")
@hosts('localhost')
def email(body):
fromaddr = '[email protected]'
toaddrs = ['[email protected]', '[email protected]']
msg = MIMEText(body)
msg['Subject'] = '[DITTO] deployment'
msg['From'] = fromaddr
msg['To'] = ','.join(toaddrs)
username = '[email protected]'
password = os.environ['FAB_EMAIL_PASS']
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg.as_string())
server.quit()