/
play.py
144 lines (97 loc) · 3.24 KB
/
play.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import context_managers
import utils
import operations
from fabric.api import env, require, cd, runs_once, sudo, abort
@runs_once
def setup_paths():
require("play_root", "project_name")
env.project_path = os.path.join(env.play_root, env.project_name)
env.config_source = os.path.join("conf", "application.conf.template")
env.config_target = os.path.join("conf", "application.conf")
def sync_deps():
"""
Download project dependencies and sync modules/lib dirs.
Abort if there are any missing dependencies.
"""
require(
"project_path",
"http_proxy",
"https_proxy",
"sudo_user",
)
with context_managers.proxy(env.http_proxy, env.https_proxy):
out = utils.play_run(env.project_path, "dependencies --sync", user=env.sudo_user)
if "WARNING" in out:
abort("Missing dependencies")
def tail(stderr=False):
"""
Tail the output of an application using supervisord.
stderr argument can be supplied to return STDERR instead of STDOUT.
"""
require("project_name")
cmd = "supervisorctl tail play-%s" % env.project_name
if stderr:
cmd += " stderr"
sudo(cmd, shell=False)
def status():
"""
Query the status of an application using supervisord.
"""
require("project_name")
utils.supervisorctl("status", "play-%s" % env.project_name)
def restart():
"""
Restart the application using supervisord.
"""
require("project_name")
utils.supervisorctl("restart", "play-%s" % env.project_name)
def start_play():
"""
Start the play application.
"""
require("project_name")
utils.supervisorctl("start", "play-%s" % env.project_name)
def stop_play():
"""
Stop the currently running play application.
"""
require("project_name")
utils.supervisorctl("stop", "play-%s" % env.project_name)
@runs_once
def migratedb(command="apply"):
"""
Perform database migrations using Evolutions.
"""
require("project_path", "sudo_user")
utils.play_run(env.project_path, "evolutions:%s" % command, user=env.sudo_user)
def deploy_play(ref=None, debug=False, dirty=False):
"""
Standard Play deployment actions.
"""
operations.fetch_render_copy(ref, debug, dirty, True)
sync_deps()
migratedb()
restart()
def dirty_play_test(ref=None, debug=False, dirty=True):
"""
Deploy LOCAL code and start app in test mode
"""
require("project_name","sudo_user")
operations.fetch_render_copy(ref, debug, dirty, True)
sync_deps()
# migratedb() should not be required as new db created for tests
stop_play()
utils.play_run(env.project_path, "test -XX:CompileCommand=exclude,jregex/Pretokenizer,next" , user=env.sudo_user)
def dirty_play_autotest(ref=None, debug=False, dirty=True):
"""
Deploy LOCAL code and run automatic tests
"""
require("project_name","sudo_user")
operations.fetch_render_copy(ref, debug, dirty, True)
sync_deps()
# migratedb() should not be required as new db created for tests
stop_play()
utils.play_run(env.project_path, "autotest -XX:CompileCommand=exclude,jregex/Pretokenizer,next" , user=env.sudo_user)
# restart app in prod mode afterwards
start_play()