forked from mangroveorg/datawinners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.sh
executable file
·173 lines (147 loc) · 5.25 KB
/
go.sh
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
function prepare_mangrove_env {
(cd $MGROOT_DIR && pip install -r requirements.pip && python setup.py develop)
}
function prepare_datawinner_log {
sudo mkdir /var/log/datawinners
sudo chmod 755 /var/log/datawinners
sudo touch /var/log/datawinners/datawinners.log
sudo touch /var/log/datawinners/datawinners-performance.log
sudo touch /var/log/datawinners/datawinners_reminders.log
sudo touch /var/log/datawinners/datawinners_xform.log
sudo touch /var/log/datawinners/websubmission.log
sudo touch /var/log/datawinners/sp-submission.log
sudo chown $USER /var/log/datawinners/datawinners.log
sudo chown $USER /var/log/datawinners/datawinners-performance.log
sudo chown $USER /var/log/datawinners/datawinners_reminders.log
sudo chown $USER /var/log/datawinners/datawinners_xform.log
sudo chown $USER /var/log/datawinners/websubmission.log
sudo chown $USER /var/log/datawinners/sp-submission.log
}
function patch_postgresql {
cd $HOME/virtual_env/datawinner/lib/python2.7/site-packages/django
patch -p1 < $DWROOT_DIR/postgis-adapter-2.patch
}
function prepare_datawinner_env {
cp "$DWROOT_DIR/datawinners/config/local_settings_example.py" "$DWROOT_DIR/datawinners/local_settings.py"
pip install -r requirements.pip
}
function migrate_db {
echo "go migrate database"
python "$DWROOT_DIR/datawinners/manage.py" migrate
}
function pre_commit {
echo "go pre commit"
prepare_env && \
unit_test && function_test
}
function prepare_env {
prepare_datawinner_log && update_source && prepare_mangrove_env && prepare_datawinner_env && patch_postgresql
}
function restore_couchdb_and_postgres {
check_host_is_dev && \
restore_postgresql_database && \
recreate_couch_db && \
recreate_feed_db && \
recreate_search_index
}
function unit_test {
echo "running unit test"
#compile_messages && \
(cd "$DWROOT_DIR/datawinners" && python manage.py test --verbosity=2 --with-xunit --xunit-file=/tmp/nosetests.xml)
}
function mangrove_unit_test {
echo "running mangrove unit test"
(cd ~/virtual_env/datawinners/src/mangrove/mangrove && nosetests -v)
}
function js_tests {
echo "running javascript unit tests"
(cd "$DWROOT_DIR/datawinners/tests/js_test" && ./phantomjs.runner.sh ./jasmine_runner/*.html)
}
function recreate_couch_db {
check_host_is_dev && \
(cd "$DWROOT_DIR/datawinners" && python manage.py recreatedb)
}
function recreate_feed_db {
check_host_is_dev && \
(cd "$DWROOT_DIR/datawinners" && python manage.py recreatefeeddb)
}
function kill_gunicorn {
if [ -f /tmp/mangrove_gunicorn_${JOB_NAME} ]
then
kill -9 `cat /tmp/mangrove_gunicorn_${JOB_NAME}`
fi
}
function function_test {
echo "running function test"
export WORKSPACE=~/workspace/datawinners
cd $WORKSPACE
export PYTHONPATH=$WORKSPACE:$WORKSPACE/func_tests
dropdb ftdb || echo ftdb database is not present
createdb -T template_postgis ftdb
#ps -ef|grep Xvfb |grep -v grep || Xvfb :99 -ac >>/dev/null 2>&1 &
#export DISPLAY=":99"
#export PYTHONPATH=$WORKSPACE
# pip install -r requirements.pip
cp datawinners/config/local_settings_ft.py datawinners/local_settings.py
cp datawinners/config/local_settings_ft.py func_tests/resources/local_settings.py
cd datawinners
python manage.py syncdb --noinput
python manage.py migrate --noinput
python manage.py recreatedb
python manage.py compilemessages
kill_gunicorn
gunicorn_django -D -b 0.0.0.0:9000 --pid=/tmp/mangrove_gunicorn_${JOB_NAME} -w 8
cd $WORKSPACE/func_tests && nosetests -v -a "functional_test" --with-xunit --xunit-file=${WORKSPACE}/xunit.xml --processes=1 --process-timeout=900
kill_gunicorn
}
function smoke_test {
echo "running smoke test"
cp "$DWROOT_DIR/datawinners/config/local_settings_example.py" "$DWROOT_DIR/func_tests/resources/local_settings.py"
(cd "$DWROOT_DIR/func_tests" && nosetests --rednose -v -a smoke)
}
function restore_postgresql_database {
check_host_is_dev && \
echo "recreating database"
dropdb mangrove && createdb -T template_postgis mangrove && \
(cd "$DWROOT_DIR/datawinners" && python manage.py syncdb --noinput && python manage.py migrate)
}
function init_env {
bash -c dw
prepare_env && \
(cd "$DWROOT_DIR/datawinners" && python manage.py compilemessages) && \
restore_postgresql_database && \
unit_test && function_test
}
function compile_messages {
cd "$DWROOT_DIR/datawinners" && python manage.py compilemessages
}
function run_server {
cd "$DWROOT_DIR/datawinners" && python manage.py runserver 0.0.0.0:8000
}
function check_host_is_dev {
if [[ "$HOSTNAME" = *dwdev* ]]
then
return 0
else
return 1
fi
}
function show_help {
echo "Usage: build.sh [COMMAND]"
echo "COMMAND"
echo "pc: \tthis will run all the unit test and function test"
echo "ut: \tthis will run all the unit test"
echo "ft: \tthis will run all the function test"
echo "rd: \tdestory and recreate database"
echo "us: \tupdate source codes of mangrove and datawinners"
echo "cm: \tcimpile the django.po"
echo "init: \t initialize environment for the first time"
echo "rs: \t run server on the 127.0.0.1:8000"
}
function recreate_search_index {
cd "$DWROOT_DIR/datawinners" && python manage.py recreate_search_indexes
}
function compile_css {
cd "$DWROOT_DIR/datawinners" && python manage.py compile_css
}