forked from ceph/calamari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
269 lines (228 loc) · 8.82 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
VERSION ?= $(shell ./get-versions.sh VERSION)
REVISION ?= $(shell ./get-versions.sh REVISION)
DIST ?= unstable
BPTAG ?= ""
DEBEMAIL ?= [email protected]
FLAVOR ?= $(shell ./get-flavor.sh)
# debian upstream tarballs: {name}_{version}.orig.tar.gz
# rpm tarball names: apparently whatever you name in Source0, but
# {name}_{version}.tar.gz will work
DISTNAMEVER=calamari-server_$(VERSION)
# PKGDIR is the directory the tarball is made from/unpacks to, and needs
# - before version
PKGDIR=calamari-server-$(VERSION)
TARNAME = ../$(DISTNAMEVER).tar.gz
SRC := $(shell pwd)
INSTALL=/usr/bin/install
all: build
build: version build-venv
DATESTR=$(shell /bin/echo -n "built on "; date)
set_deb_version:
@echo "target: $@"
DEBEMAIL=$(DEBEMAIL) dch \
--newversion $(VERSION)-$(REVISION)$(BPTAG) \
-D $(DIST) --force-bad-version --force-distribution "$(DATESTR)"
venv:
if [ ! -d $(SRC)/venv ] ; then \
virtualenv --system-site-packages $(SRC)/venv ; \
fi
VERSION_PY = rest-api/calamari_rest/version.py
version: $(VERSION_PY)
$(VERSION_PY):
@echo "target: $@"
echo "VERSION = \"$(VERSION)-$(REVISION)$(BPTAG)\"" > $(VERSION_PY)
# separate targets exist below for debugging; the expected order is
# "venv -> build-venv-carbon/build-venv-reqs -> fixup-venv"
build-venv: fixup-venv
# try for idempotency with pip freeze | grep carbon
build-venv-carbon: venv
@echo "target: $@"
set -ex; \
(export PYTHONDONTWRITEBYTECODE=1; \
cd venv; \
pyver=$$(./bin/python -c 'import sys; print "{0}.{1}".format(sys.version_info[0], sys.version_info[1])') ; \
if ! ./bin/python ./bin/pip freeze | grep -s -q carbon ; then \
./bin/python ./bin/pip install --no-install carbon; \
sed -i 's/== .redhat./== "DONTDOTHISredhat"/' \
build/carbon/setup.py; \
./bin/python ./bin/pip install --no-download \
--install-option="--prefix=$(SRC)/venv" \
--install-option="--install-lib=$(SRC)/venv/lib/python$${pyver}/site-packages" carbon; \
fi \
)
build-venv-reqs: venv
@echo "target: $@"
set -ex; \
(export PYTHONDONTWRITEBYTECODE=1; \
cd venv; \
pyver=$$(./bin/python -c 'import sys; print "{0}.{1}".format(sys.version_info[0], sys.version_info[1])') ; \
./bin/python ./bin/pip install \
--install-option="--zmq=bundled" \
'pyzmq==14.2.0' && \
./bin/python ./bin/pip install \
https://github.com/graphite-project/whisper/tarball/a6e2176e && \
./bin/python ./bin/pip install -r \
$(SRC)/requirements/$${pyver}/requirements.production.txt && \
./bin/python ./bin/pip install -I -r \
$(SRC)/requirements/$${pyver}/requirements.production.force.txt && \
./bin/python ./bin/pip install \
--install-option="--prefix=$(SRC)/venv" \
--install-option="--install-lib=$(SRC)/venv/lib/python$${pyver}/site-packages" \
https://github.com/ceph/graphite-web/tarball/calamari && \
cd ../calamari-common ; \
../venv/bin/python ./setup.py install && \
cd ../rest-api ; \
../venv/bin/python ./setup.py install && \
cd ../calamari-web ; \
../venv/bin/python ./setup.py install && \
cd ../cthulhu ; \
../venv/bin/python ./setup.py install && \
cd ../venv ; )
fixup-venv: build-venv-carbon build-venv-reqs
@echo "target: $@"
set -x; \
cd venv; \
fixfiles=$$(find -type f -not -name *.py[cox] -exec grep -Il \#!.*$(SRC) {} \;) ; \
echo "fixfiles: $$fixfiles" ; \
fixfiles="$$fixfiles bin/activate*" ; \
echo "fixfiles: $$fixfiles" ; \
for f in $$fixfiles; do \
echo -n "fixing path in $$f: "; \
grep $(SRC) "$$f"; \
sed -i -e 's;'$(SRC)';/opt/calamari;' "$$f"; \
done; \
if [ -h local/bin ] ; then \
for p in bin include lib; do \
rm local/$$p; \
ln -s /opt/calamari/venv/$$p local/$$p; \
done; \
fi
# when this repo contained the Javascript code, it was difficult to make
# source packages work right; it might be easier now
dpkg: set_deb_version
@echo "target: $@"
dpkg-buildpackage -b -us -uc
install-common: install-conf install-venv install-salt install-alembic install-scripts
@echo "target: $@"
install-rpm: build install-common install-rh-conf
@echo "target: $@"
# for deb
install: build
@echo "target: $@"
@if [ -z "$(DESTDIR)" ] ; then echo "must set DESTDIR"; exit 1; \
else $(MAKE) install_real ; fi
install_real: build install-common install-deb-conf
@echo "target: $@"
install-conf: $(CONFFILES)
@echo "target: $@"
@$(INSTALL) -D -m 0644 conf/calamari.wsgi \
$(DESTDIR)/opt/calamari/conf/calamari.wsgi
@$(INSTALL) -d $(DESTDIR)/etc/supervisor/conf.d
@$(INSTALL) -D -m 0644 conf/supervisord.production.conf \
$(DESTDIR)/etc/supervisor/conf.d/calamari.conf
@$(INSTALL) -d $(DESTDIR)/etc/salt/master.d
@$(INSTALL) -D -m 0644 conf/salt.master.conf \
$(DESTDIR)/etc/salt/master.d/calamari.conf
@$(INSTALL) -d $(DESTDIR)/etc/graphite
@$(INSTALL) -D -m 0644 conf/carbon/carbon.conf \
$(DESTDIR)/etc/graphite/carbon.conf
@$(INSTALL) -D -m 0644 conf/carbon/storage-schemas.conf \
$(DESTDIR)/etc/graphite/storage-schemas.conf
# wsgi conf for graphite constructed in postinst
# log dirs for Django apps
@$(INSTALL) -d $(DESTDIR)/var/log/graphite
@$(INSTALL) -d $(DESTDIR)/var/log/calamari
@$(INSTALL) -d $(DESTDIR)/var/lib/graphite/log/webapp
@$(INSTALL) -d $(DESTDIR)/var/lib/graphite/whisper
@$(INSTALL) -d $(DESTDIR)/var/lib/calamari
@$(INSTALL) -d $(DESTDIR)/var/lib/cthulhu
@$(INSTALL) -d $(DESTDIR)/etc/calamari
@$(INSTALL) -D -m 0644 conf/calamari/$(FLAVOR)/calamari.conf \
$(DESTDIR)/etc/calamari/calamari.conf
@$(INSTALL) -D -m 0644 conf/alembic.ini \
$(DESTDIR)/etc/calamari/alembic.ini
@$(INSTALL) -d $(DESTDIR)/etc/logrotate.d
@$(INSTALL) -D -m 0644 conf/logrotate.d/calamari \
$(DESTDIR)/etc/logrotate.d/calamari
install-salt:
@echo "target: $@"
@$(INSTALL) -d $(DESTDIR)/opt/calamari/salt
cp -rp salt/srv/* $(DESTDIR)/opt/calamari/salt/
@$(INSTALL) -d $(DESTDIR)/opt/calamari/salt-local
cp -rp salt/local/*.sls $(DESTDIR)/opt/calamari/salt-local
install-alembic:
@echo "target: $@"
@$(INSTALL) -d $(DESTDIR)/opt/calamari/alembic
cp -rp alembic/* $(DESTDIR)/opt/calamari/alembic
install-deb-conf:
@echo "target: $@"
@$(INSTALL) -D conf/httpd/calamari.conf \
$(DESTDIR)/etc/apache2/sites-available/calamari.conf
install-rh-conf:
@echo "target: $@"
# add WSGISocketPrefix, see:
# http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGISocketPrefix
@$(INSTALL) -D conf/httpd/calamari.conf \
$(DESTDIR)/etc/httpd/conf.d/calamari.conf
@sed -i '1iWSGISocketPrefix run/wsgi' $(DESTDIR)/etc/httpd/conf.d/calamari.conf
install-venv:
@echo "target: $@"
# copy calamari webapp files into place
$(INSTALL) -d -m 755 $(DESTDIR)/opt/calamari/webapp
cp -rp webapp/calamari $(DESTDIR)/opt/calamari/webapp
cp -rp venv $(DESTDIR)/opt/calamari
install-scripts: install-venv
@echo "target: $@"
# Link our scripts from the virtualenv into the global PATH
$(INSTALL) -d $(DESTDIR)/usr/bin
ln -s ../../opt/calamari/venv/bin/calamari-ctl $(DESTDIR)/usr/bin/
clean:
@echo "target: $@"
rm -rf venv $(VERSION_PY)
# Strategy for building dist tarball: find what we know is source
# want in sources.
FIND_TOPLEVEL = "find . -maxdepth 1 -type f -not -name .gitignore -print0"
FIND_RECURSE = "find alembic calamari-common calamari-web conf cthulhu doc requirements repobuild rest-api salt tests webapp -print0"
dist:
@echo "target: $@"
@echo "making dist tarball in $(TARNAME)"
@rm -rf $(PKGDIR)
@eval "$(FIND_TOPLEVEL); $(FIND_RECURSE)" | cpio --null -p -d $(PKGDIR)
@tar -zcf $(TARNAME) $(PKGDIR)
@rm -rf $(PKGDIR)
@echo "tar file made in $(TARNAME)"
dev/calamari.conf:
@echo "target: $@"
cd dev/ && python configure.py
# prefer the local version of nosetests, but allow system version
rest-api-integration: dev/calamari.conf
@echo "target: $@"
if [ -n "$$VIRTUAL_ENV" ] && [ -x $$VIRTUAL_ENV/bin/nosetests ] ; then \
CALAMARI_CONFIG=dev/calamari.conf nosetests tests/test_rest_api.py:TestApi.test_touch_urls; \
else \
CALAMARI_CONFIG=dev/calamari.conf python $$(which nosetests) tests/test_rest_api.py ; \
fi
doc/calamari_rest/resources/api_examples.json: rest-api-integration
@echo "target: $@"
cp api_examples.json doc/calamari_rest/resources
rest-api-generated: doc/calamari_rest/resources/api_examples.json dev/calamari.conf
@echo "target: $@"
cd doc/calamari_rest/resources && CALAMARI_CONFIG=../../../dev/calamari.conf python ../../../webapp/calamari/manage.py api_docs
docs: rest-api-generated
cd doc && make html
unit-tests: dev/calamari.conf
@echo "target: $@"
CALAMARI_CONFIG=dev/calamari.conf python webapp/calamari/manage.py test rest-api/tests cthulhu/tests
lint:
@echo "target: $@"
echo "Checking code style:" && \
flake8 cthulhu/ --ignore=E501 &&\
flake8 rest-api/ --ignore=E501 &&\
flake8 calamari-common/ --ignore=E501 &&\
flake8 calamari-web/ --ignore=E501 &&\
flake8 tests/ --ignore=E501 &&\
flake8 salt/srv/salt/_modules/ --ignore=E501 &&\
echo "OK"
check: unit-tests lint
.PHONY: dist clean build-venv dpkg install install-conf
.PHONY: install-venv set-deb-version version