Skip to content

Commit 89025c9

Browse files
author
zmrenwu
committed
Add deploy file (fabric)
1 parent ba9cc82 commit 89025c9

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

deploy_tools/fibfile.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from fabric.contrib.files import append, exists, sed
2+
from fabric.api import env, run, local
3+
import random
4+
5+
REPO_URL = 'https://github.com/djangoStudyTeam/DjangoBlog.git'
6+
7+
8+
def _create_directory_structure_if_necessary(site_folder):
9+
run('mkdir -p %s/%s' % (site_folder, 'env'))
10+
run('mkdir -p %s/%s' % (site_folder, 'source'))
11+
for sub_folder in ('source/weblog/database', 'source/weblog/static'):
12+
run('mkdir -p %s/%s' % (site_folder, sub_folder))
13+
14+
15+
def _get_latest_source(source_folder):
16+
if exists(source_folder + '/.git'):
17+
run('cd %s && git fetch' % (source_folder,))
18+
else:
19+
run('git clone %s %s' % (REPO_URL, source_folder))
20+
current_commit = local('git log -n 1 --format=%H', capture=True)
21+
run('cd %s && git reset --hard %s && git checkout blog-tutorial' % (source_folder, current_commit))
22+
23+
24+
def _update_virtualenv(source_folder):
25+
virtualenv_folder = source_folder + '/../env'
26+
if not exists(virtualenv_folder + '/bin/pip'):
27+
run('virtualenv --python=python3 %s' % (virtualenv_folder,))
28+
run('%s/bin/pip install -r %s/requirements.txt' %
29+
(virtualenv_folder, source_folder))
30+
31+
32+
def _update_static_files(source_folder):
33+
run('cd %s && ../virtualenv/bin/python3 manage.py collectstatic --noinput' %
34+
(source_folder,))
35+
36+
37+
def _update_database(source_folder):
38+
run('cd %s && ../virtualenv/bin/python3 manage.py makemigrations' %
39+
(source_folder,))
40+
run('cd %s && ../virtualenv/bin/python3 manage.py migrate --noinput' %
41+
(source_folder,))
42+
43+
44+
def _update_settings(source_folder, site_name):
45+
setting_path = ''
46+
sed(setting_path, "DEBUG = True", "DEBUG = False")
47+
sed(
48+
setting_path,
49+
"ALLOWED_HOSTS = .+$",
50+
"ALLOWED_HOSTS = ['%s']" % site_name,
51+
)
52+
secret_key_file = source_folder + ''
53+
if not exists(secret_key_file):
54+
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
55+
key = ''.join(random.SystemRandom().choice(chars) for _ in range(50))
56+
append(secret_key_file, "SECRET_KEY = '%s'" % key)
57+
append(setting_path, '\nfrom .secret_key import SECRET_KEY')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ django-markdown-deux==1.0.5
66
django-model-utils==2.5.2
77
django-notifications-hq==1.2
88
django-registration-redux==1.4
9+
gunicorn==19.6.0
910
jieba==0.38
1011
jsonfield==1.0.3
1112
markdown2==2.3.1

weblog/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
DATABASES = {
9797
'default': {
9898
'ENGINE': 'django.db.backends.sqlite3',
99-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
99+
'NAME': os.path.join(BASE_DIR, 'database/db.sqlite3'),
100100
}
101101
}
102102

0 commit comments

Comments
 (0)