-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
39 lines (31 loc) · 1.05 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
import os
from fabric.api import run, sudo, env, cd, local, prefix, put, lcd, settings
from fabric.contrib.project import rsync_project
from fabric.contrib.files import exists, sed
from fabric.utils import puts
server_dir = '/home/project/code-review-web'
tmp_dir = '/tmp/code-review-web' + str(os.getpid())
def _set_user_dir():
global server_dir
with settings(warn_only=True):
issue = run('id root').lower()
def _prepare_local_website(install='true'):
if install =='true':
local('npm run build')
local('mkdir -p %s' % tmp_dir)
local('cp -rv dist/* %s' % tmp_dir)
def prepare_remote_dirs():
_set_user_dir()
if not exists(server_dir):
sudo('mkdir -p %s' % server_dir)
sudo('chmod -R 755 %s' % server_dir)
sudo('chown %s %s' % ('root', server_dir))
def _clean_local_dir():
local('rm -r %s' % tmp_dir)
def host_type():
run('uname -s')
def deploy(install='true'):
_prepare_local_website(install)
prepare_remote_dirs()
rsync_project(local_dir=tmp_dir + '/',remote_dir=server_dir,delete=True)
_clean_local_dir()