Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1615461
fabfile.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Mar 22, 12:57 AM
Size
4 KB
Mime Type
text/x-python
Expires
Tue, Mar 24, 12:57 AM (7 h, 12 m)
Engine
blob
Format
Raw Data
Handle
354421
Attached To
rDIAS DIAS
fabfile.py
View Options
from
__future__
import
with_statement
from
fabric.api
import
*
from
fabric.contrib.console
import
confirm
from
fabric.colors
import
*
import
time
# globals
env
.
colors
=
True
env
.
format
=
True
env
.
release
=
time
.
strftime
(
'%Y%m
%d
%H%M%S'
)
# variables
env
.
hosts
=
[
'root@web0.diashosp.grnet.gr'
]
env
.
path
=
'/var/www/web_portal'
env
.
deploy_user
=
'www-data'
env
.
deploy_group
=
'www-data'
def
test
():
with
settings
(
warn_only
=
True
):
result
=
local
(
'echo ./manage.py test my_app'
,
capture
=
True
)
if
result
.
failed
and
not
confirm
(
"Tests failed. Continue anyway?"
):
abort
(
"Aborting at user request."
)
def
commit
():
local
(
"git add -p && git commit"
)
def
push
():
local
(
"git push"
)
def
get_code
():
print
(
green
(
"Starting code update"
))
with
settings
(
warn_only
=
True
):
if
run
(
"test -d
%s
"
%
code_dir
)
.
failed
:
run
(
"git clone https://github.com/piwik/piwik.git
%s
"
%
path
)
run
(
"git pull"
)
with
cd
(
env
.
path
):
run
(
"git pull"
)
run
(
"echo touch app.wsgi"
)
def
deploy
():
print
green
(
'>> Starting deploy'
)
local
(
'git archive --format=tar master | gzip >
%(release)s
.tar.gz'
%
env
)
upload_tar_from_git
()
symlink_current_release
()
service_restart
()
def
prepare_deploy
():
test
()
commit
()
push
()
def
stop_service
():
print
yellow
(
'>>> Stopping HTTP service'
)
run
(
"service apache2 stop"
)
def
start_service
():
print
yellow
(
'>>> Starting HTTP service'
)
run
(
"service apache2 start"
)
def
db_migrate
():
# There are no database migrations for DIAS web_portal
print
yellow
(
'>>> Starting Database Migrations'
)
pass
def
update_config
():
# This is temporary until the git code doesn't contain configs any more
# configs should be handled by puppet
print
yellow
(
'>>> Updating configuration files'
)
put
(
'configs/db_connect.php'
,
'
%(path)s
/releases/current/web_portal/secure'
%
env
)
put
(
'configs/jboss_config.xml'
,
'
%(path)s
/releases/current/web_portal/secure/include'
%
env
)
put
(
'configs/memcached_config.xml'
,
'
%(path)s
/releases/current/web_portal/secure/include'
%
env
)
pass
def
fix_permissions
():
print
yellow
(
'>>> Fixing permissions'
)
run
(
"chown -R
%(deploy_user)s
:
%(deploy_group)s
%(path)s
/releases/current"
%
env
)
def
run_puppet
():
print
yellow
(
'>>> Run puppet'
)
#run("puppetd -tv", warn_only=True)
pass
def
upload_tar_from_git
():
print
yellow
(
'>>> uploading .tar.gz package from this host
\'
s @master branch'
)
run
(
"mkdir -p
%(path)s
/releases/
%(release)s
"
%
env
)
run
(
'mkdir -p
%(path)s
/packages'
%
env
)
put
(
'
%(release)s
.tar.gz'
%
env
,
'
%(path)s
/packages/'
%
env
)
run
(
'cd
%(path)s
/releases/
%(release)s
&& tar zxf ../../packages/
%(release)s
.tar.gz'
%
env
)
def
symlink_current_release
():
print
yellow
(
'>>> updating releases/current to point at {path}/releases/{release}'
)
.
format
(
**
env
)
with
cd
(
env
.
path
):
with
settings
(
warn_only
=
True
):
run
(
'rm -f releases/previous'
)
run
(
'mv releases/current releases/previous'
)
run
(
'ln -s
%(release)s
releases/current'
%
env
)
def
service_restart
():
stop_service
()
update_config
()
run_puppet
()
db_migrate
()
fix_permissions
()
start_service
()
def
list_versions
():
with
cd
(
env
.
path
):
run
(
'ls -l releases/'
,
warn_only
=
True
)
def
get_current
():
with
cd
(
env
.
path
):
run
(
'ls -l releases/current'
,
warn_only
=
True
)
def
get_previous
():
with
cd
(
env
.
path
):
run
(
'ls -l releases/previous'
,
warn_only
=
True
)
def
rollback_to_version
(
version
):
env
.
version
=
version
env
.
release
=
version
print
yellow
(
'>>> updating releases/current to point at {path}/releases/{version}'
)
.
format
(
**
env
)
with
cd
(
env
.
path
):
run
(
'rm -f releases/previous'
,
warn_only
=
True
)
run
(
'cp -avp releases/current releases/last_current'
,
warn_only
=
True
)
run
(
'mv releases/current releases/previous'
,
warn_only
=
True
)
run
(
'ln -s
%(version)s
releases/current'
%
env
)
run
(
'rm -rf releases/last_current'
,
warn_only
=
True
)
service_restart
()
def
rollback
():
print
yellow
(
'>>> updating releases/current to point at the version previously deployed on this server'
)
.
format
(
**
env
)
with
cd
(
env
.
path
):
run
(
"cp -avp releases/current releases/previous_new"
)
run
(
"rm -f releases/current"
)
run
(
"mv releases/previous releases/current"
)
run
(
"mv releases/previous_new releases/previous"
)
service_restart
()
Event Timeline
Log In to Comment