-
Notifications
You must be signed in to change notification settings - Fork 11
/
fabfile.py
112 lines (85 loc) · 3.62 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
104
105
106
107
108
109
110
111
112
import os
from fabric import api
from fabric import utils
from fabric.contrib.project import rsync_project
# Deploy Config
api.env.user = 'deploy'
api.env.hosts = ['portland.pynorth.org']
api.env.use_ssh_config = True
# Git
api.env.repo = 'git://github.com/pyconca/2016-web.git'
api.env.remote = 'origin'
# Local
api.env.local_root_dir = os.path.dirname(os.path.abspath(__file__))
api.env.local_build_dir = os.path.join(api.env.local_root_dir, 'build/')
# The above needs to end with `/` or else rsync get's mad.
@api.task
def stag():
api.env.environment = 'staging'
# Directories
api.env.root_dir = '/srv/www/pycon.ca/staging.2016/'
api.env.html_dir = os.path.join(api.env.root_dir, 'html')
api.env.venv_dir = os.path.join(api.env.root_dir, 'venv')
api.env.app_dir = os.path.join(api.env.root_dir, 'app')
# Python Helpers
api.env.venv_python = os.path.join(api.env.venv_dir, 'bin/python')
api.env.venv_pip = os.path.join(api.env.venv_dir, 'bin/pip')
# Git
api.env.branch = 'develop'
@api.task
def prod():
api.env.environment = 'production'
# Directories
api.env.root_dir = '/srv/www/pycon.ca/2016/'
api.env.html_dir = os.path.join(api.env.root_dir, 'html')
api.env.venv_dir = os.path.join(api.env.root_dir, 'venv')
api.env.app_dir = os.path.join(api.env.root_dir, 'app')
# Python Helpers
api.env.venv_python = os.path.join(api.env.venv_dir, 'bin/python')
api.env.venv_pip = os.path.join(api.env.venv_dir, 'bin/pip')
# Git
api.env.branch = 'master'
@api.task
def deploy():
api.require('environment')
# Check to make sure that there isn't any unchecked files
git_status = api.local('git status --porcelain', capture=True)
if git_status:
utils.abort('There are unchecked files.')
# Push the repo to the remote
api.local('git push {0} {1}'.format(api.env.remote, api.env.branch))
# Build the static website.
api.local('python manage.py freeze')
# rsync the website to the server.
rsync_project(remote_dir=api.env.html_dir,
local_dir=api.env.local_build_dir,
delete=False,
exclude=['static/scss/',
'static/bower/',
'static/.webassets-cache/'])
# Draw a ship
utils.puts(" | | | ")
utils.puts(" )_) )_) )_) ")
utils.puts(" )___))___))___)\ ")
utils.puts(" )____)____)_____)\\ ")
utils.puts(" _____|____|____|____\\\__ ")
utils.puts(" ---------\ /--------- ")
utils.puts(" ^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ")
utils.puts(" ^^^^ ^^^^ ^^^ ^^ ")
utils.puts(" ^^^^ ^^^ ")
@api.task
def git_auto_deploy():
with api.lcd(api.env.app_dir):
api.local('git reset --hard HEAD')
api.local('git pull {0} {1}'.format(api.env.remote, api.env.branch))
# Install some dependencies
api.local('{} install -U -r requirements.txt'.format(api.env.venv_pip))
api.local('bower install --upgrade')
# Generate the website
api.local('{} manage.py tr-compile'.format(api.env.venv_python))
api.local('{} manage.py freeze'.format(api.env.venv_python))
# Copy the generated website
api.local('rsync --delete --exclude "static/scss/" --exclude '
'"static/bower/" --exclude "static/.webassets-cache/" '
'-pthrvz {0} {1}'.format(api.env.local_build_dir,
api.env.html_dir))