-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Makefile
197 lines (164 loc) · 5.94 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
.PHONY: clean clean-test clean-pyc clean-build docs help
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-40s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
PYTHON := python
PYTHON_LIB := $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())" )
PLATFORM ?= ubuntu
OS_VERSION ?= jammy
pwd := $(shell pwd)
build_dir = ${pwd}/build
top_dir = ${build_dir}/rpmbuild
version = $(shell python -c 'from twindb_backup import __version__; print(__version__)')
PY_MAJOR = $(shell python -c 'import sys; print(sys.version[:3])')
LOG_LEVEL := info
OMNIBUS_BRANCH := $(shell if test -z "${OMNIBUS_BRANCH}"; then echo "master"; else echo ${OMNIBUS_BRANCH}; fi)
OMNIBUS_SOFTWARE_BRANCH := $(shell if test -z "${OMNIBUS_SOFTWARE_BRANCH}"; then echo "master"; else echo ${OMNIBUS_SOFTWARE_BRANCH}; fi)
DOCKER_IMAGE := $(shell if test -z "${DOCKER_IMAGE}"; then echo "centos:centos7"; else echo ${DOCKER_IMAGE}; fi)
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
.PHONY: virtualenv
virtualenv: ## create virtual environment typically used for development purposes
virtualenv -p python3 --always-copy --prompt='(twindb_backup)' ~/.virtualenvs/twindb-backup/
@printf "To activate run:\n\n. ~/.virtualenvs/twindb-backup/bin/activate\n\n"
.PHONY: pip
pip:
pip install -U "pip ~= 23.0"
.PHONY: pip-tools
pip-tools: pip
pip install -U "pip-tools ~= 7.0"
.PHONY: setuptools
setuptools: pip
pip install -U "setuptools ~= 62.3.2"
.PHONY: upgrade-requirements
upgrade-requirements: pip-tools ## Upgrade requirements
pip-compile --upgrade --verbose --output-file requirements.txt requirements.in
pip-compile --upgrade --verbose --output-file requirements_dev.txt requirements_dev.in
.PHONY: bootstrap
bootstrap: pip pip-tools setuptools ## bootstrap the development environment
pip-sync requirements.txt requirements_dev.txt
pip install --editable .
clean: clean-build clean-pyc clean-test clean-docs ## remove all build, test, coverage and Python artifacts
clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -rf pkg/
rm -rf omnibus/pkg/
rm -rf cache/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage coverage.xml
rm -fr htmlcov/
rm -rf .pytest_cache
clean-docs:
rm -rf docs/_build
.PHONY: black
black: ## Fix code style errors
black twindb_backup tests
.PHONY: isort
isort: ## Fix import order errors
isort twindb_backup tests
lint: ## check style with pylint
yamllint --no-warnings -f parsable .
isort --check-only twindb_backup tests
black --diff --check twindb_backup tests
pycodestyle twindb_backup
pylint twindb_backup
test: ## Run tests quickly with the default Python and generate code coverage report
pytest -xv --cov-report term-missing --cov-report xml --cov=./twindb_backup tests/unit
test-integration: ## Run integration tests. Must be run in vagrant
py.test -xsv tests/integration/
docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/twindb_backup.rst
# rm -f docs/modules.rst
sphinx-apidoc -o docs/ twindb_backup
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html
install: clean ## install the package to the active Python's site-packages
if test -z "${DESTDIR}" ; \
then $(PYTHON) setup.py install \
--prefix /usr \
--install-lib $(PYTHON_LIB); \
else $(PYTHON) setup.py install \
--prefix /usr \
--install-lib $(PYTHON_LIB) \
--root "${DESTDIR}" ; \
mkdir -p "${DESTDIR}/etc/cron.d/" ; \
install -m 644 -o root support/twindb-backup.cron "${DESTDIR}/etc/cron.d/twindb-backup" ; \
mkdir -p "${DESTDIR}/etc/twindb/" ; \
install -m 600 -o root support/twindb-backup.cfg "${DESTDIR}/etc/twindb" ; \
fi
.PHONY: docker-start
docker-start: ## Start a container with /twindb-backup for debugging packaging, etc.
@docker run \
-v ${pwd}:/twindb-backup \
-w /twindb-backup/ \
-it \
--name builder_xtrabackup \
--rm \
--env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
--env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
--env "GC_CREDENTIALS_FILE=${GC_CREDENTIALS_FILE}" \
--env PLATFORM=${PLATFORM} \
--env OS_VERSION=${OS_VERSION} \
"twindb/omnibus-${PLATFORM}:${OS_VERSION}" \
bash -l
ifeq ($(OS_VERSION),focal)
PLATFORM = ubuntu
endif
ifeq ($(OS_VERSION),jammy)
PLATFORM = ubuntu
endif
ifeq ($(OS_VERSION),7)
PLATFORM = centos
endif
ifeq ($(OS_VERSION),8)
PLATFORM = centos
endif
package: ## Build package - OS_VERSION must be one of: jammy, focal.
@docker run \
-v ${pwd}:/twindb-backup \
--name builder_xtrabackup \
--rm \
--env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
--env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
--env PLATFORM=${PLATFORM} \
--env OS_VERSION=${OS_VERSION} \
"twindb/omnibus-${PLATFORM}:${OS_VERSION}" \
bash -l /twindb-backup/omnibus/omnibus_build.sh
install_package:
if [ "${PLATFORM}" == "centos" ]
then
yum install -y $(ls omnibus/pkg/*.rpm)
else
dpkg -i $(ls omnibus/pkg/*.deb) | apt-get install -f
fi
safety: ## check for known security vulnerabilities
docker run --rm -it -v ${pwd}:/twindb-backup pyupio/safety safety check -r /twindb-backup/requirements.txt
docker run --rm -it -v ${pwd}:/twindb-backup pyupio/safety safety check -r /twindb-backup/requirements_dev.txt