-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMakefile
More file actions
278 lines (222 loc) · 9.06 KB
/
Makefile
File metadata and controls
278 lines (222 loc) · 9.06 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
.PHONY: nginx-dev nginx-prod staging deploy all
SOURCE ?= .
STAGING ?= staging
# The targets to deploy a dev build
all: staging remote-staging
sudo make deploy remote-deploy nginx-dev
################################################################################
# assets
################################################################################
$(STAGING)/fonts.target: $(SOURCE)/site/assets/font-awesome-4.3.0/fonts/*
mkdir -p $(STAGING)/site/static
rsync --acls --xattrs --archive --delete \
$(SOURCE)/site/assets/font-awesome-4.3.0/fonts \
$(STAGING)/site/static
touch $(STAGING)/fonts.target
CSS_FILES := \
$(SOURCE)/site/assets/css/normalize.css \
$(SOURCE)/site/assets/font-awesome-4.3.0/css/font-awesome.css \
$(SOURCE)/site/assets/codemirror/codemirror.css \
$(SOURCE)/site/assets/codemirror/bigfix.css \
$(SOURCE)/site/assets/css/site.css
JS_FILES := \
$(SOURCE)/site/assets/underscore.js \
$(SOURCE)/site/assets/site.js \
$(SOURCE)/site/assets/evaluator.js \
$(SOURCE)/site/assets/codemirror/codemirror.js \
$(SOURCE)/site/assets/codemirror/relevance.js \
$(SOURCE)/site/assets/codemirror/matchbrackets.js
$(STAGING)/site/static/site.css: $(CSS_FILES)
mkdir -p $(STAGING)/site/static
cat $^ > $@
$(STAGING)/site/static/site.js: $(JS_FILES)
mkdir -p $(STAGING)/site/static
cat $^ > $@
$(STAGING)/site/favicon.ico: $(SOURCE)/site/assets/favicon.ico
mkdir -p $(STAGING)/site
cp -f $^ $@
$(STAGING)/site/apple-touch-icon.png: $(SOURCE)/site/assets/apple-touch-icon.png
mkdir -p $(STAGING)/site
cp -f $^ $@
$(STAGING)/site/robots.txt: $(SOURCE)/site/assets/robots.txt
mkdir -p $(STAGING)/site
cp -f $^ $@
$(STAGING)/img.target: $(SOURCE)/site/img $(SOURCE)/site/img/*
mkdir -p $(STAGING)/site/static/img
rsync --acls --xattrs --archive --delete \
$(SOURCE)/site/img \
$(STAGING)/site/static
touch $(STAGING)/img.target
STAGING_TARGETS += $(STAGING)/site/static/site.css
STAGING_TARGETS += $(STAGING)/site/static/site.js
STAGING_TARGETS += $(STAGING)/fonts.target
STAGING_TARGETS += $(STAGING)/site/favicon.ico
STAGING_TARGETS += $(STAGING)/site/apple-touch-icon.png
STAGING_TARGETS += $(STAGING)/site/robots.txt
STAGING_TARGETS += $(STAGING)/img.target
################################################################################
# pages
################################################################################
$(STAGING)/build/package.json: $(wildcard $(SOURCE)/site/build/**/*)
mkdir -p $(STAGING)
rsync --acls --xattrs --archive --delete --exclude=node_modules \
$(SOURCE)/site/build/ \
$(STAGING)/build
cd $(STAGING)/build && npm install --unsafe-perm
touch $@
PAGES_DEPS := \
$(STAGING)/build/package.json \
$(wildcard $(SOURCE)/site/data/*) \
$(shell find $(SOURCE)/site/pages -type f) \
$(wildcard $(SOURCE)/site/templates/*)
$(STAGING)/site/index.html: $(PAGES_DEPS)
node $(STAGING)/build $(SOURCE)/site $(STAGING)
STAGING_TARGETS += $(STAGING)/site/index.html
################################################################################
# cache busting
################################################################################
CACHE_BUST_DEPS := \
$(STAGING)/site/static/site.css \
$(STAGING)/site/static/site.js \
$(STAGING)/site/static/fonts \
$(STAGING)/site/index.html \
$(STAGING)/img.target
$(STAGING)/cache-bust-site/index.html: $(CACHE_BUST_DEPS)
mkdir -p $(STAGING)/cache-bust-site
rsync --archive --delete $(STAGING)/site/ $(STAGING)/cache-bust-site
sh $(SOURCE)/scripts/cache-bust.sh \
$(STAGING)/cache-bust-site/static/site.css \
$(STAGING)/cache-bust-site
sh $(SOURCE)/scripts/cache-bust.sh \
$(STAGING)/cache-bust-site/static/site.js \
$(STAGING)/cache-bust-site
touch $@
STAGING_TARGETS += $(STAGING)/cache-bust-site/index.html
/var/www/site/index.html: $(STAGING)/cache-bust-site/index.html
# Preserve any google site verification file
cp /var/www/site/google* $(STAGING)/cache-bust-site/ 2>/dev/null || true
# Set file permissions so nginx can read it.
chmod -R a+rX $(STAGING)
# Tag the files so that selinux allows nginx to read it.
chcon -R -t httpd_sys_content_t $(STAGING)
# Rsync the files to the production directory
mkdir -p /var/www/site
rsync --acls --xattrs --archive --delete \
$(STAGING)/cache-bust-site/ \
/var/www/site
# Ensure modification time is bumped for make dependency tracking.
touch $@
DEPLOY_TARGETS += /var/www/site/index.html
################################################################################
# /api/relevance/search
################################################################################
$(STAGING)/api/relevance/search/language.json: $(SOURCE)/site/data/relevance-language.json
mkdir -p $(STAGING)/api/relevance/search/
cp -f $< $@
$(STAGING)/api/relevance/search/docs.json: $(STAGING)/relevance-docs.json
mkdir -p $(STAGING)/api/relevance/search/
cp -f $< $@
$(STAGING)/api/relevance/search/package.json: $(wildcard $(SOURCE)/site/api/relevance-search/*)
mkdir -p $(STAGING)/api/relevance/search/
rsync --acls --xattrs --archive --delete \
--exclude=node_modules \
--exclude=language.json \
--exclude=docs.json \
$(SOURCE)/site/api/relevance-search/ \
$(STAGING)/api/relevance/search/
cd $(STAGING)/api/relevance/search/ && npm install --production
touch $@
STAGING_TARGETS += $(STAGING)/api/relevance/search/language.json
STAGING_TARGETS += $(STAGING)/api/relevance/search/docs.json
STAGING_TARGETS += $(STAGING)/api/relevance/search/package.json
SEARCH_DEPS := \
$(SOURCE)/conf/systemd/relevance-search.service \
$(STAGING)/api/relevance/search/package.json \
$(STAGING)/api/relevance/search/language.json \
$(STAGING)/api/relevance/search/docs.json
/usr/lib/systemd/system/relevance-search.service: $(SEARCH_DEPS)
systemctl stop relevance-search || true
systemctl disable relevance-search || true
chmod -R a+rX $(STAGING)
mkdir -p /var/www/api/relevance
rsync --acls --xattrs --archive --delete \
$(STAGING)/api/relevance/search/ \
/var/www/api/relevance/search
cp -f $(SOURCE)/conf/systemd/relevance-search.service \
/usr/lib/systemd/system/relevance-search.service
systemctl daemon-reload
systemctl enable relevance-search
systemctl start relevance-search
DEPLOY_TARGETS += /usr/lib/systemd/system/relevance-search.service
################################################################################
# /api/relevance/evaluate
################################################################################
$(STAGING)/evaluate.target: $(wildcard $(SOURCE)/site/api/relevance-evaluate/*)
mkdir -p $(STAGING)
docker build -t relevance/evaluate $(SOURCE)/site/api/relevance-evaluate
touch $@
REMOTE_STAGING_TARGETS += $(STAGING)/evaluate.target
$(STAGING)/evaluate-deploy.target: $(STAGING)/evaluate.target
docker ps -q | xargs -r docker kill
docker run -d -p 5002:5002 --restart=always relevance/evaluate
touch $@
REMOTE_DEPLOY_TARGETS += $(STAGING)/evaluate-deploy.target
################################################################################
# /api/stash
################################################################################
$(STAGING)/api/stash/package.json: $(wildcard $(SOURCE)/site/api/stash/*)
mkdir -p $(STAGING)/api/stash
rsync --acls --xattrs --archive --delete --exclude=node_modules \
$(SOURCE)/site/api/stash/ \
$(STAGING)/api/stash/
cd $(STAGING)/api/stash/ && npm install --production
touch $@
STAGING_TARGETS += $(STAGING)/api/stash/package.json
STASH_DEPS := \
$(SOURCE)/conf/systemd/stash.service \
$(STAGING)/api/stash/package.json
/usr/lib/systemd/system/stash.service: $(STASH_DEPS)
systemctl stop stash || true
systemctl disable stash || true
chmod -R a+rX $(STAGING)
mkdir -p /var/www/api/stash
mkdir -p /var/www/stashes
chmod a+rwX /var/www/stashes
rsync --acls --xattrs --archive --delete \
$(STAGING)/api/stash/ \
/var/www/api/stash
cp -f $(SOURCE)/conf/systemd/stash.service \
/usr/lib/systemd/system/stash.service
systemctl daemon-reload
systemctl enable stash
systemctl start stash
DEPLOY_TARGETS += /usr/lib/systemd/system/stash.service
################################################################################
# nginx
################################################################################
nginx-dev: /etc/nginx/conf.d/dev.conf
nginx-prod: /etc/nginx/conf.d/prod.conf
NGINX_DEPS := \
/etc/nginx/shared.conf \
/etc/nginx/nginx.conf
/etc/nginx/conf.d/dev.conf: $(NGINX_DEPS)
rm -rf /etc/nginx/conf.d/*
cp $(SOURCE)/conf/nginx/dev.conf $@
systemctl reload nginx
/etc/nginx/conf.d/prod.conf: $(NGINX_DEPS)
rm -rf /etc/nginx/conf.d/*
cp $(SOURCE)/conf/nginx/prod.conf $@
systemctl reload nginx
/etc/nginx/shared.conf: $(SOURCE)/conf/nginx/shared.conf
cp -f $< $@
/etc/nginx/nginx.conf: $(SOURCE)/conf/nginx/nginx.conf
cp -f $< $@
################################################################################
# top level targets
################################################################################
# The targets to deploy the web server and web pages
staging: $(STAGING_TARGETS)
deploy: $(DEPLOY_TARGETS)
# The targets to deploy the remote evaluate server
remote-staging: $(REMOTE_STAGING_TARGETS)
remote-deploy: $(REMOTE_DEPLOY_TARGETS)