-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
351 lines (253 loc) · 8.4 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/make -f
#
# Build website with environment
#
#
WWW_SITE = cimage.se
WWW_LOCAL = local.$(WWW_SITE)
SERVER_ADMIN = [email protected] # mos@$(WWW_SITE)
GIT_BASE = git/cimage.se
HTDOCS_BASE = $(HOME)/htdocs
LOCAL_HTDOCS = $(HTDOCS_BASE)/$(WWW_SITE)
ROBOTSTXT = robots.txt
# Certificates for https
SSL_APACHE_CONF = /etc/letsencrypt/options-ssl-apache.conf
SSL_PEM_BASE = /etc/letsencrypt/live/$(WWW_SITE)
# Theme
LESS := theme/style_cimage.less
LESS_OPTIONS := --strict-imports --include-path=theme/modules:theme/modules/vertical-grid/less:theme/modules/typographic-grid/less:theme/modules/responsive-menu/src/less:theme/modules/figure/less:theme/mos-theme/style
FONT_AWESOME := theme/mos-theme/style/font-awesome/fonts/
# target: help - Displays help.
.PHONY: help
help:
@echo "make [target] ..."
@echo "target:"
@egrep "^# target:" Makefile | sed 's/# target: / /g'
# target: update - Update codebase and publish by clearing the cache.
.PHONY: update
update: codebase-update site-build local-publish-clear
# target: production-publish - Publish latest to the production server.
.PHONY: production-publish
production-publish:
ssh mos@$(WWW_SITE) -t "cd $(GIT_BASE) && git pull && make update"
# target: update - Publish website to local host.
.PHONY: local-publish
local-publish:
rsync -av --exclude old --exclude .git --exclude cache --delete "./" $(LOCAL_HTDOCS)
@[ ! -f $(ROBOTSTXT) ] || cp $(ROBOTSTXT) "$(LOCAL_HTDOCS)/htdocs/robots.txt"
# target: local-cache-clear - Clear the cache.
.PHONY: local-cache-clear
local-cache-clear:
-sudo rm -f $(LOCAL_HTDOCS)/cache/anax/*
-sudo rm -f $(LOCAL_HTDOCS)/cache/cimage/*
# target: cache-clear - Clear the cache.
.PHONY: cache-clear
cache-clear:
-sudo rm -f $(LOCAL_HTDOCS)/cache/anax/*
-sudo rm -rf $(LOCAL_HTDOCS)/cache/cimage/*
#
#
# target: local-publish-clear - Publish website to local host and clear the cache.
.PHONY: local-publish-clear
local-publish-clear: local-cache-clear local-publish
#
# Update codebase
#
.PHONY: codebase-update
codebase-update:
git pull
composer update
#
# Update repo with all submodules
#
.PHONY: submodule-init submodule-update
submodule-init:
git submodule update --init --recursive
submodule-update:
git pull --recurse-submodules && git submodule foreach git pull origin master
#
# Build
#
.PHONY: prepare-build
prepare-build:
rm -rf build
install -d build/css build/lint
# target: less-update - Build less and update site.
.PHONY: less-update
less-update: less local-publish
# target: less-update-clear - Build less and update site and clear cache.
.PHONY: less-update-clear
less-update-clear: less local-publish-clear
# target: less - Build less stylesheet and update the site with it.
.PHONY: less
less: prepare-build
#lessc $(LESS_OPTIONS) $(LESS) build/css/style.css
lessc --clean-css $(LESS_OPTIONS) $(LESS) build/css/style.min.css
#cp build/css/style.css htdocs/css/style.css
cp build/css/style.min.css htdocs/css/style.min.css
# Grid images§
install -d htdocs/img/theme/
rsync -av theme/modules/vertical-grid/img/ htdocs/img/theme/vertical-grid/
rsync -av theme/modules/typographic-grid/img/ htdocs/img/theme/typographic-grid/
# Theme js
install -d htdocs/js/theme/
rsync -av theme/js/ htdocs/js/theme/
# Responsive menu
rsync -av theme/modules/responsive-menu/htdocs/js/responsive-menu.min.js htdocs/js/theme
# Font awesome
rsync -av $(FONT_AWESOME) htdocs/fonts/
#
# Lint
#
.PHONY: lint
lint: less
lessc --lint $(LESS) > build/lint/style.less
- csslint build/css/style.css > build/lint/style.css
ls -l build/lint/
# target: site-build - Build site structure from codebase.
.PHONY: site-build
site-build:
# Target dir
install --directory $(LOCAL_HTDOCS)
# Copy from CImage
install -d htdocs/cimage
rsync -av vendor/mos/cimage/webroot/imgd.php htdocs/cimage/imgd.php
rsync -av vendor/mos/cimage/icc/ htdocs/cimage/icc/
rsync -av vendor/mos/cimage/webroot/img/ htdocs/img/example/
# Copy from CImage
install -d htdocs/cimage
bash -c "rsync -av vendor/mos/cimage/webroot/{img,imgd,imgf,imgp,imgs,check_system}.php vendor/mos/cimage/icc htdocs/cimage"
rsync -av vendor/mos/cimage/webroot/img/ htdocs/img/example/
# Make cache parts writable
install --directory --mode 777 cache/cimage cache/anax
rsync -av "./cache/" $(LOCAL_HTDOCS)/cache/
# Sync to virtual host dir
rsync -av --exclude old --exclude .git --exclude cache/ --delete "./" $(LOCAL_HTDOCS)
# target: etc-hosts - Create a entry in the /etc/hosts for local access.
.PHONY: etc-hosts
etc-hosts:
echo "127.0.0.1 $(WWW_LOCAL)" | sudo bash -c 'cat >> /etc/hosts'
@tail -1 /etc/hosts
# target: ssl-cert-create - One way to create the certificates.
.PHONY: ssl-cert-create
ssl-cert-create:
#cd $(HOME)/git/letsencrypt
#./letsencrypt-auto certonly --standalone -d $(WWW_SITE) -d www.$(WWW_SITE)
sudo service apache2 stop
sudo certbot certonly --standalone -d $(WWW_SITE) -d www.$(WWW_SITE)
sudo service apache2 start
# target: ssl-cert-update - Update certificates with new expiray date.
.PHONY: ssl-cert-update
ssl-cert-update:
#cd $(HOME)/git/letsencrypt
#./letsencrypt-auto renew
sudo service apache2 stop
sudo certbot renew
sudo service apache2 start
# target: install-fresh - Do a fresh installation of a new server.
.PHONY: install-fresh
install-fresh: etc-hosts virtual-host update
# target: virtual-host - Create entries for the virtual host http.
.PHONY: virtual-host
define VIRTUAL_HOST_80
Define site $(WWW_SITE)
ServerAdmin $(SERVER_ADMIN)
ServerName $${site}
<VirtualHost *:80>
ServerAlias local.$${site}
ServerAlias do3.$${site}
ServerAlias do4.$${site}
DocumentRoot $(HTDOCS_BASE)/$${site}/htdocs
ServerSignature Off
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
<FilesMatch "\.(jpe?g|png|gif|js|css|svg)$">
ExpiresActive On
ExpiresDefault "access plus 1 week"
</FilesMatch>
ErrorLog $(HTDOCS_BASE)/$${site}/error.log
CustomLog $(HTDOCS_BASE)/$${site}/access.log combined
</VirtualHost>
endef
export VIRTUAL_HOST_80
define VIRTUAL_HOST_80_WWW
Define site $(WWW_SITE)
ServerAdmin $(SERVER_ADMIN)
<VirtualHost *:80>
ServerName www.$${site}
Redirect "/" "http://$${site}/"
</VirtualHost>
endef
export VIRTUAL_HOST_80_WWW
virtual-host:
install --directory $(HOME)/htdocs/$(WWW_SITE)/htdocs
echo "$$VIRTUAL_HOST_80" | sudo bash -c 'cat > /etc/apache2/sites-available/$(WWW_SITE).conf'
echo "$$VIRTUAL_HOST_80_WWW" | sudo bash -c 'cat > /etc/apache2/sites-available/www.$(WWW_SITE).conf'
sudo a2ensite $(WWW_SITE) www.$(WWW_SITE)
sudo a2enmod rewrite
sudo apachectl configtest
sudo service apache2 reload
# target: virtual-host-https - Create entries for the virtual host https.
.PHONY: virtual-host-https
define VIRTUAL_HOST_443
Define site $(WWW_SITE)
ServerAdmin $(SERVER_ADMIN)
<VirtualHost *:80>
ServerName $${site}
ServerAlias do3.$${site}
ServerAlias do4.$${site}
Redirect "/" "https://$${site}/"
</VirtualHost>
<VirtualHost *:443>
Include $(SSL_APACHE_CONF)
SSLCertificateFile $(SSL_PEM_BASE)/cert.pem
SSLCertificateKeyFile $(SSL_PEM_BASE)/privkey.pem
SSLCertificateChainFile $(SSL_PEM_BASE)/chain.pem
ServerName $${site}
ServerAlias do3.$${site}
ServerAlias do4.$${site}
DocumentRoot $(HTDOCS_BASE)/$${site}/htdocs
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
<FilesMatch "\.(jpe?g|png|gif|js|css|svg)$">
ExpiresActive On
ExpiresDefault "access plus 1 week"
</FilesMatch>
ErrorLog $(HTDOCS_BASE)/$${site}/error.log
CustomLog $(HTDOCS_BASE)/$${site}/access.log combined
</VirtualHost>
endef
export VIRTUAL_HOST_443
define VIRTUAL_HOST_443_WWW
Define site $(WWW_SITE)
ServerAdmin $(SERVER_ADMIN)
<VirtualHost *:80>
ServerName www.$${site}
Redirect "/" "https://www.$${site}/"
</VirtualHost>
<VirtualHost *:443>
Include $(SSL_APACHE_CONF)
SSLCertificateFile $(SSL_PEM_BASE)/cert.pem
SSLCertificateKeyFile $(SSL_PEM_BASE)/privkey.pem
SSLCertificateChainFile $(SSL_PEM_BASE)/chain.pem
ServerName www.$${site}
Redirect "/" "https://$${site}/"
</VirtualHost>
endef
export VIRTUAL_HOST_443_WWW
virtual-host-https:
echo "$$VIRTUAL_HOST_443" | sudo bash -c 'cat > /etc/apache2/sites-available/$(WWW_SITE).conf'
echo "$$VIRTUAL_HOST_443_WWW" | sudo bash -c 'cat > /etc/apache2/sites-available/www.$(WWW_SITE).conf'
sudo a2enmod ssl
sudo apachectl configtest
sudo service apache2 reload