Revision 6100721e
Makefile: add versioning
- check for DESTDIR in install target
- add get-versions.sh to get version from git describe
- create/manage version.py for api/v1 to use
- add version to info/ view
- make dpkg build run "set_deb_version" first
Fixes: #7082
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Makefile | ||
---|---|---|
1 |
VERSION=1.0.0 |
|
1 |
VERSION ?= $(shell ./get-versions.sh VERSION) |
|
2 |
REVISION ?= $(shell ./get-versions.sh REVISION) |
|
3 |
DIST ?= unstable |
|
4 |
BPTAG ?= "" |
|
5 |
DEBEMAIL ?= dan.mick@inktank.com |
|
6 |
|
|
7 |
# debian upstream tarballs: {name}_{version}.orig.tar.gz |
|
8 |
# rpm tarball names: apparently whatever you name in Source0, but |
|
9 |
# {name}_{version}.tar.gz will work |
|
2 | 10 |
DISTNAMEVER=calamari_$(VERSION) |
3 | 11 |
PKGDIR=calamari-$(VERSION) |
4 | 12 |
TARNAME = ../$(DISTNAMEVER).tar.gz |
... | ... | |
6 | 14 |
|
7 | 15 |
INSTALL=/usr/bin/install |
8 | 16 |
|
17 |
build: set_deb_version version build-venv |
|
9 | 18 |
|
10 |
|
|
19 |
DATESTR=$(shell /bin/echo -n "built on "; date) |
|
20 |
set_deb_version: |
|
21 |
DEBEMAIL=$(DEBEMAIL) dch \ |
|
22 |
--newversion $(VERSION)-$(REVISION)$(BPTAG) \ |
|
23 |
-D $(DIST) --force-bad-version --force-distribution "$(DATESTR)" |
|
11 | 24 |
|
12 | 25 |
venv: |
13 |
virtualenv --system-site-packages venv; \ |
|
26 |
virtualenv --system-site-packages venv |
|
27 |
|
|
28 |
|
|
29 |
VERSION_PY = rest-api/calamari_rest/version.py |
|
30 |
version: $(VERSION_PY) |
|
31 |
|
|
32 |
$(VERSION_PY): |
|
33 |
echo "VERSION=\"$(VERSION)-$(REVISION)$(BPTAG)\"" > $(VERSION_PY) |
|
14 | 34 |
|
15 | 35 |
build-venv: venv |
16 | 36 |
@echo "build-venv" |
... | ... | |
58 | 78 |
# this source is just not very amenable to building source packages. |
59 | 79 |
# the Javascript directories don't really go back to "clean"; it might |
60 | 80 |
# be possible to change that, but for now, just skip the source build |
61 |
dpkg: |
|
81 |
dpkg: set_deb_version
|
|
62 | 82 |
dpkg-buildpackage -b -us -uc |
63 | 83 |
|
64 | 84 |
install-common: install-conf install-venv install-salt install-alembic install-scripts |
... | ... | |
68 | 88 |
@echo "install-rpm" |
69 | 89 |
|
70 | 90 |
# for deb |
71 |
install: install-common install-deb-conf |
|
72 |
@echo "install" |
|
91 |
install: |
|
92 |
@if [ -z "$(DESTDIR)" ] ; then echo "must set DESTDIR"; exit 1; \ |
|
93 |
else $(MAKE) install_real ; fi |
|
94 |
|
|
95 |
install_real: install-common install-deb-conf |
|
96 |
@echo "install_real" |
|
73 | 97 |
|
74 | 98 |
install-conf: $(CONFFILES) |
75 | 99 |
@echo "install-conf" |
... | ... | |
134 | 158 |
ln -s ../../opt/calamari/venv/bin/calamari-ctl $(DESTDIR)/usr/bin/ |
135 | 159 |
|
136 | 160 |
clean: |
137 |
rm -rf venv |
|
161 |
rm -rf venv $(VERSION_PY)
|
|
138 | 162 |
|
139 | 163 |
dist: |
140 | 164 |
@echo "making dist tarball in $(TARNAME)" |
... | ... | |
182 | 206 |
check: unit-tests lint |
183 | 207 |
|
184 | 208 |
.PHONY: dist clean build-venv dpkg install install-conf |
185 |
.PHONY: build-venv install-venv |
|
209 |
.PHONY: build-venv install-venv set-deb-version version |
get-versions.sh | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
# |
|
3 |
# Output version, revision for package builds derived from git. |
|
4 |
# |
|
5 |
# -r: change revision to be suitable for rpm |
|
6 |
# VERSION: output X only |
|
7 |
# REVISION: output Y only |
|
8 |
# no more args: output VERSION=X REVISION=Y suitable for eval |
|
9 |
# |
|
10 |
|
|
11 |
RPM='n' |
|
12 |
if [ "$1" == "-r" ] ; then RPM='y' ; shift ; fi |
|
13 |
|
|
14 |
# GITVER is the version from the current git branch, less the first char ('v') |
|
15 |
GITVER=$(git describe | cut -c 2-) |
|
16 |
|
|
17 |
# if GITVER contains a '-', separate at the first one into version and revision |
|
18 |
if [[ $GITVER == *-* ]]; then |
|
19 |
VERSION=$(echo $GITVER | sed 's/-.*//') |
|
20 |
REVISION=$(echo $GITVER | sed 's/'${VERSION}'-//') |
|
21 |
if [ $RPM == 'y' ] ; then |
|
22 |
REVISION=$(echo $REVISION | sed 's/-/_/g') |
|
23 |
fi |
|
24 |
else |
|
25 |
VERSION=$GITVER |
|
26 |
REVISION="0" |
|
27 |
fi |
|
28 |
|
|
29 |
case "$1" in |
|
30 |
VERSION) echo $VERSION; exit ;; |
|
31 |
REVISION) echo $REVISION; exit ;; |
|
32 |
*) echo "VERSION=$VERSION REVISION=$REVISION"; exit ;; |
|
33 |
esac |
rest-api/calamari_rest/views/v1.py | ||
---|---|---|
32 | 32 |
from calamari_rest.views.rpc_view import RPCView, DataObject, RPCViewSet |
33 | 33 |
from cthulhu.manager.types import POOL |
34 | 34 |
|
35 |
try: |
|
36 |
from calamari_rest.version import VERSION |
|
37 |
except ImportError: |
|
38 |
# could create version here if we wanted to be fancier |
|
39 |
VERSION = 'dev' |
|
35 | 40 |
|
36 | 41 |
from cthulhu.config import CalamariConfig |
37 | 42 |
config = CalamariConfig() |
... | ... | |
347 | 352 |
BOOTSTRAP_RHEL = "curl {url} | python" |
348 | 353 |
|
349 | 354 |
return Response(self.serializer_class(DataObject({ |
350 |
"version": "2.0", # TODO: populate from build version (ticket #7082)
|
|
355 |
"version": str(VERSION),
|
|
351 | 356 |
"license": "N/A", |
352 | 357 |
"registered": "N/A", |
353 | 358 |
"hostname": grains['host'], |
Also available in: Unified diff