This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
/
fabfile.py
executable file
·88 lines (64 loc) · 1.63 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
#!/usr/bin/env python
from __future__ import with_statement
import os
import sys
import subprocess
import time
try:
from fabric.api import *
from fabric.contrib.console import confirm
except ImportError:
print ("""The 'fabric' package is currently not installed. You can install it by typing:\n
sudo apt-get install fabric
""")
sys.exit()
#
# Username and hostname to ssh to.
#
env.hosts = ['www.steve.org.uk:2222']
env.user = 's-mark'
def deploy():
"""
Deploy the application,
"""
#
# Setup our release identifier.
#
env.release = time.strftime('%Y%m%d%H%M%S')
#
# Create a tar-file and upload it
#
local('git archive --format=tar master | gzip > %(release)s.tar.gz' % env)
run( "mkdir ~/releases/ || true")
put('%(release)s.tar.gz' % env, '~/releases/' % env)
#
# Remove the local copy.
#
local('rm %(release)s.tar.gz' % env)
#
# Untar the remote version
#
run( "mkdir ~/releases/%(release)s && cd ~/releases/%(release)s && tar zxf ../%(release)s.tar.gz" % env )
#
# Now symlink in the current release
#
run( "rm -f ~/current || true " )
run( "ln -s ~/releases/%(release)s ~/current" % env )
#
# And restart
#
run( "kill -9 $(cat lighttpd.pid)" )
#
# This is our entry point.
#
if __name__ == '__main__':
if len(sys.argv) > 1:
#
# If we got an argument then invoke fabric with it.
#
subprocess.call(['fab', '-f', __file__] + sys.argv[1:])
else:
#
# Otherwise list our targets.
#
subprocess.call(['fab', '-f', __file__, '--list'])