forked from slavdict/slavdict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
235 lines (196 loc) · 6.44 KB
/
Makefile
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
SHELL = /bin/bash
GITWORKTREE = /var/www/slavdict
GITDIR = /usr/local/src/wwwgit/slavdict.git
SETTINGS_FILE = slavdict/settings.py
DATE_TIME := $(shell date +%Y-%m-%d--%H-%M)
IS_PRODUCTION = production
IS_DEVELOPMENT = development
SLAVDICT_ENVIRONMENT ?= ${IS_PRODUCTION}
PYTHON = pipenv run python
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
GIT = git --work-tree=${GITWORKTREE} --git-dir=${GITDIR}
else
GIT = git
endif
JSLIBS_PATH := $(shell ${PYTHON} ${SETTINGS_FILE} --jslibs-path)
JSLIBS_FILES := ${JSLIBS_PATH}*.{js,map,txt,swf}
JSLIBS_VERSION_FILE := ${JSLIBS_PATH}version.txt
JSLIBS_NEW_VERSION := $(shell ${PYTHON} ${SETTINGS_FILE} --jslibs-version)
JSLIBS_OLD_VERSION := $(shell cat ${JSLIBS_VERSION_FILE} 2>/dev/null)
LOCCHDIR = /root/slavdict-local-changes-untracked
DIFFFILE = /root/slavdict-local-changes-${DATE_TIME}.diff
RESOURCE_VERSION = sass/_resource_version.sass
default: indesign
shell:
PYTHONSTARTUP=etc/django_shell_rc.py ${PYTHON} ./manage.py shell
restart: stop update start
update: copydiff destroy_loc_changes checkout collectstatic fixown migrate
update-lite: copydiff destroy_loc_changes checkout fixown
killbg:
test ! -e .bgpids || ( xargs -a .bgpids kill ; rm .bgpids ; true )
run: killbg migrate collectstatic
@echo "Запуск сервера в тестовом окружении..."
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_DEVELOPMENT})
livereload static & echo $$! >>.bgpids
compass watch & echo $$! >>.bgpids
trap 'trap - INT TERM ERR; $(MAKE) killbg' INT TERM ERR; \
${PYTHON} ./manage.py runserver
else
@echo "Окружение не является тестовым"
false
endif
stop:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
sudo service nginx stop
sudo service uwsgi stop slavdict
endif
start:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
sudo service uwsgi start slavdict
sudo service nginx start
endif
copydiff:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
mkdir -p ${LOCCHDIR}
${GIT} diff --no-color >${DIFFFILE}
test -s ${DIFFFILE} || rm -f ${DIFFFILE}
${GIT} status -s | grep --color=never '?? ' | cut -c4- \
| xargs -I '{}' rsync -av '{}' ${LOCCHDIR}/
${GIT} status -s | grep --color=never '?? ' | cut -c4- \
| xargs -I '{}' rm -fr '{}'
endif
destroy_loc_changes:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
${GIT} reset --hard HEAD
endif
checkout:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
${GIT} pull origin master
endif
_revert:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
${GIT} reset --hard HEAD^
endif
revert: _revert collectstatic fixown
fixown:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_PRODUCTION})
chown -R www-data:www-data ./
chmod u+x bin/*.sh
endif
collectstatic: hash
test -e ${RESOURCE_VERSION} || touch ${RESOURCE_VERSION}
compass compile -e ${SLAVDICT_ENVIRONMENT}
${PYTHON} ./manage.py collectstatic --noinput
migrate:
${PYTHON} ./manage.py migrate
clean:
-find -name '*.pyc' -execdir rm '{}' \;
-rm -f static/*.css
-rm -f ${JSLIBS_FILES}
-rm -fR .sass-cache/
-rm -fR .static/*
jslibs:
if [ "${JSLIBS_OLD_VERSION}" != "${JSLIBS_NEW_VERSION}" ];\
then \
rm -f ${JSLIBS_FILES} ; \
${PYTHON} ${SETTINGS_FILE} --jslibs | xargs -n3 wget ; \
echo ${JSLIBS_NEW_VERSION} > ${JSLIBS_VERSION_FILE} ; \
fi
hash: jslibs
test -e .temp_hash && rm .temp_hash || true
${GIT} ls-tree --name-only -r HEAD -- sass static \
| xargs sha256sum >>.temp_hash
find static/js/outsourcing -type f -iname '*.js' \
-exec sha256sum '{}' \; >>.temp_hash
sort .temp_hash -o .temp_hash
sha256sum .temp_hash | cut -c1-8 >.hash
echo '$$shash:' "'$$(cat .hash)'" >${RESOURCE_VERSION}
indesign-prepare:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_DEVELOPMENT})
rsync bin/indesign_xml_dumper.py slavdict:/var/www/slavdict/bin/
ssh slavdict chown www-data:www-data /var/www/slavdict/bin/indesign_xml_dumper.py
rsync -av templates/indesign slavdict:/var/www/slavdict/templates/
ssh slavdict chown -R www-data:www-data /var/www/slavdict/templates/indesign/
endif
indesign-listen:
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_DEVELOPMENT})
ls .list bin/indesign_xml_dumper.py templates/indesign/* | entr bash -c 'time cat .list | xargs ${PYTHON} bin/indesign_xml_dumper.py >/home/nurono/VirtualBox\ SharedFolder/slavdict-indesign.xml'
endif
indesign: indesign-prepare
ifeq (${SLAVDICT_ENVIRONMENT}, ${IS_DEVELOPMENT})
rsync -av bin slavdict:/var/www/slavdict/
rsync -av slavdict/jinja_extensions slavdict:/var/www/slavdict/slavdict/
rsync -av templates/indesign slavdict:/var/www/slavdict/templates/
[ ! -e .args ] && ( \
echo '--split-by-letters' >.args ; \
echo '--split-nchars=50000' >>.args ; \
echo '--output-pattern=/root/slavdict-indesign-#.xml' >>.args ) \
|| echo "file '.args' exists"
rsync .args slavdict:/root/
ssh slavdict chown -R www-data:www-data /var/www/slavdict/
ssh slavdict rm -f /root/slavdict-indesign-*.xml
ssh slavdict nohup /var/www/slavdict/bin/remote_indesign_xml_dumper.sh
scp slavdict:/root/slavdict-indesign-*.xml .temp/
endif
indesign-after-clean:
rm -fr .temp/*.xml
$(MAKE) indesign
rsync:
rsync -av --delete \
--exclude=csl--*.xml \
--exclude=dictionary--*.xml \
--exclude=slavdict-local-changes-untracked \
slavdict:/var/www/slavdict/.dumps .
rsync -av \
slavdict:/root/slavdict-local-changes-untracked/* \
.dumps/slavdict-local-changes-untracked/
before-remote-update:
test $$(git status -s | wc -l) = 0
git push origin master
remote-restart: before-remote-update
ssh slavdict make -C /var/www/slavdict restart
remote-update: before-remote-update
ssh slavdict make -C /var/www/slavdict update-lite
remote-csl-dump: remote-update
ssh slavdict nohup /var/www/slavdict/bin/csl_dumper.sh
$(MAKE) rsync
remote-refs-dump: remote-update
ssh slavdict nohup /var/www/slavdict/bin/csl_dumper.sh refs
$(MAKE) rsync
remote-slavdict-dump: remote-update
ssh slavdict nohup /var/www/slavdict/bin/dump.sh
$(MAKE) rsync
install:
command -v gem && sudo gem install || echo 'gem is not installed'; false
command -v pipenv && pipenv install || echo 'pipenv is not installed'; false
.PHONY: \
before-remote-update \
checkout \
clean \
collectstatic \
copydiff \
default \
destroy_loc_changes \
fixown \
hash \
indesign \
indesign-listen \
indesign-prepare \
install \
jslibs \
listen-indesign \
migrate \
migrestart \
remote-csl-dump \
remote-restart \
remote-slavdict-dump \
remote-update \
restart \
_revert \
revert \
rsync \
run \
start \
stop \
update \
update-lite \