forked from vstconsulting/polemarch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (194 loc) · 6.41 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
PY = python2
PIP = $(PY) -m pip
PY_VERSION = $(shell $(PY) --version 2>&1 | tail -c +8)
PYTHON_BIN = $(shell $(PY) -c 'import sys, os; print(os.path.dirname(sys.executable))')
RELOCATE_BIN = $(PYTHON_BIN)/venvctrl-relocate
LOC_TEST_ENVS = py27-install,py36-install,flake,pylint
ENVS = $(LOC_TEST_ENVS)
ifndef TOX_ARGS
TOX_ARGS =
endif
TESTS =
NAMEBASE = polemarch
USER = $(NAMEBASE)
NAME = $(NAMEBASE)
VER = $(shell $(PY) -c 'import $(NAME); print($(NAME).__version__)')
PROJECT_CTL = $(NAME)ctl
MAIN_APP = main
VSTUTILS_REQ = $(shell cat requirements-doc.txt | grep vstutils | sed 's/\[.*\]/[doc]/')
VSTUTILS = $(VSTUTILS_REQ)
PIPARGS = $(shell echo -n "--cache-dir=$$(pwd)/.pip-cache")
ARCHIVE = $(NAME)-$(VER).tar.gz
LICENSE = AGPL-3+
define DESCRIPTION
Polemarch is service for orchestration infrastructure by ansible.
Simply WEB gui for orchestration infrastructure by ansible playbooks.
endef
export DESCRIPTION
SUMMARY = Infrastructure Heat Service for orchestration infrastructure by ansible.
VENDOR = VST Consulting <[email protected]>
RELEASE = 0
DEFAULT_PREFIX = /opt
INSTALL_PREFIX = $(shell if [[ ! -z "${prefix}" ]]; then echo -n $(prefix); else echo -n $(DEFAULT_PREFIX); fi)
INSTALL_DIR = $(INSTALL_PREFIX)/${NAME}
INSTALL_BINDIR = $(INSTALL_DIR)/bin
INSTALL_PY = $(PY)
REQUIREMENTS = -r requirements.txt -r requirements-doc.txt
TMPDIR := $(shell mktemp -d)
RPM_BUILD = /tmp/rpmbuild_$(NAME)_$(VER)_$(RELEASE)
BUILD_DIR= $(TMPDIR)
PREBUILD_DIR = $(BUILD_DIR)/$(INSTALL_DIR)
PREBUILD_BINDIR = $(BUILD_DIR)/$(INSTALL_BINDIR)
SOURCE_DIR = $(shell pwd)
COMPILE_DIR = $(shell echo -n "$$(pwd)/dist")
COMPOSE = docker-compose-testrun.yml
COMPOSE_ARGS = --abort-on-container-exit
COMPLEX_TESTS_COMPOSE = docker-compose-tests.yml
COMPLEX_TESTS_COMPOSE_ARGS = '--abort-on-container-exit --build'
define VARS_STR
PY=$(PY)
PY_VERSION=$(PY_VERSION)
PIP=$(PIP)
PYTHON_BIN=$(PYTHON_BIN)
RELOCATE_BIN=$(RELOCATE_BIN)
NAMEBASE=$(NAMEBASE)
USER=$(USER)
NAME=$(NAME)
VER=$(VER)
RELEASE=$(RELEASE)
PROJECT_CTL=$(PROJECT_CTL)
MAIN_APP=$(MAIN_APP)
VSTUTILS=$(VSTUTILS)
BUILD_DIR=$(BUILD_DIR)
RPM_BUILD=$(RPM_BUILD)
INSTALL_DIR=$(INSTALL_DIR)
endef
export VARS_STR
include rpm.mk
include deb.mk
all: compile clean_prebuild prebuild
print_vars:
echo "$$VARS_STR"
which $(PY)
docs: print_vars
-rm -rf doc/_build
mkdir -p doc/_static
$(PY) setup.py build_sphinx --build-dir doc/_build -W
test:
tox $(TOX_ARGS) -e $(ENVS) $(TESTS)
flake:
tox -e flake
pylint:
tox -e pylint
build: build-clean print_vars
-rm -rf dist
$(PY) setup.py sdist -v
pre_compile: build-clean print_vars
find ./$(NAME) -name "*.c" -print0 | xargs -0 rm -rf
-rm -rf polemarch/doc/*
$(PIP) install -U $(VSTUTILS)
compile: pre_compile
-rm -rf dist
$(PY) setup.py compile -v
wheel: pre_compile
$(PY) setup.py compile_docs -v
$(PY) setup.py bdist_wheel -v --dist-dir $(COMPILE_DIR) --bdist-dir /tmp/build_$(NAME)/$(PY_VERSION)/
prebuild: print_vars
# Create virtualenv
$(PY) -m virtualenv -p $(INSTALL_PY) --download --no-site-packages $(PREBUILD_DIR)
# Install required packages
$(PREBUILD_BINDIR)/pip install -U pip
$(PREBUILD_BINDIR)/pip install -U dist/$(NAME)-$(VER).tar.gz $(REQUIREMENTS)
$(PREBUILD_BINDIR)/pip install -U -r requirements-git.txt
# RECORD files are used by wheels for checksum. They contain path names which
# match the buildroot and must be removed or the package will fail to build.
# find $(PREBUILD_DIR) -name "RECORD" -exec rm -rf {} \;
# Change the virtualenv path to the target installation direcotry.
$(RELOCATE_BIN) --source=$(PREBUILD_DIR) --destination=$(INSTALL_DIR)
# Remove sources for Clang
find $(PREBUILD_DIR)/lib -type f -name "*.c" -print0 | xargs -0 rm -rf
# Remove broken link
-rm -rf $(PREBUILD_DIR)/local
# Install settings
-install -Dm 755 $(NAME)/$(MAIN_APP)/settings.ini $(BUILD_DIR)/etc/$(USER)/settings.ini.template
# Install systemd services
-install -Dm 755 initbin/$(NAME).service $(BUILD_DIR)/etc/systemd/system/$(NAME).service
# Install tmpdirs config
-install -Dm 755 initbin/$(NAMEBASE).conf $(BUILD_DIR)/etc/tmpfiles.d/$(NAMEBASE).conf
# Create tmpdirs
-mkdir -p $(BUILD_DIR)/var/log/$(NAMEBASE)
-mkdir -p $(BUILD_DIR)/var/run/$(NAMEBASE)
-mkdir -p $(BUILD_DIR)/var/lock/$(NAMEBASE)
localinstall: print_vars
$(PY) -m virtualenv --no-site-packages $(INSTALL_DIR)
$(INSTALL_BINDIR)/pip install -U pip
$(INSTALL_BINDIR)/pip install -U $(VSTUTILS)
$(INSTALL_BINDIR)/pip install -U dist/$(NAME)-$(VER).tar.gz $(REQUIREMENTS)
$(INSTALL_BINDIR)/pip install -U -r requirements-git.txt
find $(INSTALL_DIR)/lib -type f -name "*.c" -print0 | xargs -0 rm -rf
$(MAKE) prebuild_deps BUILD_DIR=$(INSTALL_DIR)
install:
# Change owner for packages
-chown -R $(USER):$(USER) $(PREBUILD_DIR) $(BUILD_DIR)/var/{log,run,lock}/$(NAMEBASE) $(BUILD_DIR)/etc/$(USER)
# Copy build
cp -rf $(BUILD_DIR)/* /
$(MAKE) clean_prebuild
uninstall:
-rm -rf $(INSTALL_DIR)
clean_prebuild:
-rm -rf $(BUILD_DIR)/*
clean: build-clean
-rm -rf htmlcov
-rm -rf .coverage
-rm -rf dist
-rm -rf build
-rm -rf *.egg-info
build-clean:
-rm pylint_* || true
find ./$(NAME) -name '__pycache__' -print0 | xargs -0 rm -rf
find ./$(NAME) -name "*.pyc" -print0 | xargs -0 rm -rf
-rm -rf build
-rm -rf *.egg-info
fclean: clean
find ./$(NAME) -name "*.c" -print0 | xargs -0 rm -rf
-rm -rf .tox
rpm: print_vars
echo "$$RPM_SPEC" > $(NAME).spec
rm -rf $(RPM_BUILD)
mkdir -p $(RPM_BUILD)/SOURCES/
ls -la
rpmbuild --verbose -bb $(NAME).spec --define "_rpmdir ${RPM_BUILD}" --define "_topdir ${RPM_BUILD}"
mkdir -p dist
cp -v $(RPM_BUILD)/x86_64/*.rpm dist/
rm -rf $(NAME).spec $(RPM_BUILD)
deb: print_vars
rm -rf debian
mkdir debian
# create needed files
echo 9 > debian/compat
echo "$$DEBIAN_CONTROL" > debian/control
echo "$$DEBIAN_COPYRIGHT" > debian/copyright
echo "$$DEBIAN_RULES" > debian/rules
echo "$$DEBIAN_PREINST" > debian/preinst
echo "$$DEBIAN_POSTINST" > debian/postinst
echo "$$DEBIAN_PRERM" > debian/prerm
echo "$$DEBIAN_POSTRM" > debian/postrm
echo "$$DEBIAN_CHANGELOG" > debian/changelog
chmod +x debian/rules
chmod +x debian/preinst
chmod +x debian/postinst
chmod +x debian/prerm
chmod +x debian/postrm
# build
dpkg-buildpackage -d -uc -us -j4
mv -v ../$(NAME)_$(VER)*.deb dist/
# cleanup
rm -rf debian
compose_down:
docker-compose -f $(COMPOSE) down
compose:
docker-compose -f $(COMPOSE) build
run:
docker-compose -f $(COMPOSE) up $(COMPOSE_ARGS)
complex_tests:
$(MAKE) run COMPOSE=$(COMPLEX_TESTS_COMPOSE) COMPOSE_ARGS=$(COMPLEX_TESTS_COMPOSE_ARGS)