-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
103 lines (83 loc) · 2.95 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
96
97
98
99
100
101
102
103
from datetime import datetime
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'udoco.settings' # NOQA
sys.path += ['.'] # NOQA
import subprocess
from django.conf import settings
from fabric.api import local
import requests
os.environ['AWS_ACCESS_KEY_ID'] = settings.AWS_ACCESS_KEY_ID
os.environ['AWS_SECRET_ACCESS_KEY'] = settings.AWS_SECRET_ACCESS_KEY
def test():
local('coverage run --source=udoco manage.py test')
local('coverage report --fail-under=92')
local('flake8 --ignore=D100,D104 --exclude=udoco/migrations/* --max-line-length=80')
def manage_certs():
"""Generate a certificate."""
update = True
if not os.path.exists('certbot'):
local('mkdir -p certbot')
update = False
local(
'certbot --config-dir certbot --work-dir certbot --logs-dir '
'certbot -d www.udoco.org certonly --manual'
)
if update:
local('heroku certs:update --confirm udoco '
'certbot/live/www.udoco.org/fullchain.pem '
'certbot/live/www.udoco.org/privkey.pem')
else:
local('heroku certs:add certbot/live/www.udoco.org/fullchain.pem '
'certbot/live/www.udoco.org/privkey.pem')
def staticupload():
local(
'DATABASE_URL=sqlite:// GITVERSION=`git rev-parse --short HEAD` '
'manage.py collectstatic --noinput')
def migrate():
local('heroku run python manage.py migrate')
def deploy_notify():
"""Notify telemetry about deployment."""
try:
os.environ['SENTRY_AUTH_TOKEN']
except KeyError:
print('No SENTRY_AUTH_TOKEN found in environment variables.')
sys.exit(1)
gitrev = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
payload = {
'environment': 'production',
'dateReleased': datetime.now().isoformat(),
'version': gitrev,
'ref': gitrev,
'url': 'https://github.com/AmeliaLLC/udoco/commit/{}'.format(gitrev),
'projects': [
'udoco',
],
}
endpoint = 'https://sentry.io/api/0/organizations/{}/releases/'.format( # NOQA
'amelia-consulting')
requests.post(
endpoint,
headers={
'Authorization': 'Bearer {}'.format(
os.environ['SENTRY_AUTH_TOKEN']),
'Content-Type': 'application/json'
},
json=payload).raise_for_status()
def deploy():
try:
os.environ['REACT_APP_SENTRY_DSN']
except KeyError:
print('No REACT_APP_SENTRY_DSN found in environment variables.')
sys.exit(1)
local('git push origin')
local('git push --tags origin')
local('rm -f static/app.js static/app.css')
local('cd frontend && npm install && npm run integrate')
staticupload()
local('heroku config:set GITVERSION=`git rev-parse --short HEAD`')
local('heroku config:set SENTRY_DSN={}'.format(os.environ['SENTRY_DSN']))
local('git push heroku master')
migrate()
deploy_notify()