forked from yandex/ch-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
240 lines (172 loc) · 7.03 KB
/
Makefile
File metadata and controls
240 lines (172 loc) · 7.03 KB
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
SHELL := bash
export PYTHONIOENCODING ?= utf8
export COMPOSE_HTTP_TIMEOUT ?= 300
export CLICKHOUSE_VERSION ?= latest
export PROJECT_NAME ?= ch-backup
export DEV_MODE ?= false
export BUILD_PYTHON_OUTPUT_DIR ?= dist
export BUILD_DEB_OUTPUT_DIR ?= out
# Different ways of passing signing key for building debian package
export DEB_SIGN_KEY_ID ?=
export DEB_SIGN_KEY ?=
export DEB_SIGN_KEY_PATH ?=
# Platform of image for building debian package according to
# https://docs.docker.com/build/building/multi-platform/#building-multi-platform-images
# E.g. linux/amd64, linux/arm64, etc.
# If platform is not provided Docker uses platform of the host performing the build
export DEB_TARGET_PLATFORM ?=
# Name of image (with tag) for building deb package.
# E.g. ubuntu:22.04, ubuntu:jammy, ubuntu:bionic, etc.
# If it is not provided, default value in Dockerfile is used
export DEB_BUILD_DISTRIBUTION ?=
SRC_DIR = ch_backup
TESTS_DIR = tests
VENV = .venv
SESSION_FILE = .session_conf.sav
INSTALL_DIR = $(DESTDIR)/opt/yandex/ch-backup
INTEGRATION_TEST_TOOL=uv run python -m tests.integration.env_control
.PHONY: build
build: setup
uv build
.PHONY: setup
setup: check-uv ch_backup/version.txt
.PHONY: all
all: lint test-unit build test-integration
.PHONY: lint
lint: setup isort black codespell ruff pylint mypy
.PHONY: isort
isort: setup
uv run isort --check --diff $(SRC_DIR) $(TESTS_DIR)
.PHONY: black
black: setup
uv run black --check --diff $(SRC_DIR) $(TESTS_DIR)
.PHONY: codespell
codespell: setup
uv run codespell $(SRC_DIR) $(TESTS_DIR) *.md
.PHONY: fix-codespell-errors
fix-codespell-errors: setup
uv run codespell -w $(SRC_DIR) $(TESTS_DIR) *.md
.PHONY: ruff
ruff: setup
uv run ruff check $(SRC_DIR) $(TESTS_DIR)
.PHONY: pylint
pylint: setup
uv run pylint $(SRC_DIR)
uv run pylint --disable=missing-docstring,invalid-name $(TESTS_DIR)
.PHONY: mypy
mypy: setup
uv run mypy $(SRC_DIR) $(TESTS_DIR)
.PHONY: format
format: setup
uv run isort .
uv run black .
.PHONY: test-unit
test-unit: setup
uv run py.test $(PYTEST_ARGS) tests
.PHONY: test-integration
test-integration: create-test-env
rm -rf staging/logs
uv run behave --show-timings --stop -D skip_setup $(BEHAVE_ARGS) @tests/integration/ch_backup.featureset
.PHONY: clean
clean: clean-test-env clean-pycache clean-debuild
rm -rf ${VENV} *.egg-info htmlcov .coverage* .hypothesis .mypy_cache .pytest_cache \
.ruff_cache ch_backup/version.txt dist
.PHONY: clean-pycache
clean-pycache:
find . -name __pycache__ -type d -exec rm -rf {} +
.PHONY: install
install:
@echo "Installing into $(INSTALL_DIR)"
python3 -m venv $(INSTALL_DIR)
$(INSTALL_DIR)/bin/pip install --no-compile $(BUILD_PYTHON_OUTPUT_DIR)/ch_backup-*.whl
mkdir -p $(DESTDIR)/usr/bin/
ln -s /opt/yandex/ch-backup/bin/ch-backup $(DESTDIR)/usr/bin/
mkdir -p $(DESTDIR)/etc/bash_completion.d/
env LC_ALL=C.UTF-8 LANG=C.UTF-8 \
_CH_BACKUP_COMPLETE=bash_source $(INSTALL_DIR)/bin/ch-backup > $(DESTDIR)/etc/bash_completion.d/ch-backup || \
test -s $(DESTDIR)/etc/bash_completion.d/ch-backup
rm -rf $(INSTALL_DIR)/bin/activate*
find $(INSTALL_DIR) -name __pycache__ -type d -exec rm -rf {} +
test -n '$(DESTDIR)' \
&& grep -l -r -F '#!$(INSTALL_DIR)' $(INSTALL_DIR) \
| xargs sed -i -e 's|$(INSTALL_DIR)|/opt/yandex/ch-backup|' \
|| true
.PHONY: uninstall
uninstall:
@echo "Uninstalling from $(INSTALL_DIR)"
rm -rf $(INSTALL_DIR) $(DESTDIR)/usr/bin/ch-backup $(DESTDIR)/etc/bash_completion.d/ch-backup
.PHONY: build-deb-package
build-deb-package: check-docker setup
./build_deb_in_docker.sh
.PHONY: build-deb-package-local
build-deb-package-local: prepare-changelog
./build_deb.sh
.PHONY: prepare-changelog
prepare-changelog: setup
@rm -f debian/changelog
dch --create --package ch-backup --distribution stable \
-v `cat ch_backup/version.txt` \
"Yandex autobuild"
.PHONY: clean-debuild
clean-debuild:
rm -rf debian/{changelog,files,ch-backup,.debhelper}
rm -f ../ch-backup_*{build,changes,deb,dsc,tar.gz}
.PHONY: create-test-env
create-test-env: check-docker-compose build ${SESSION_FILE}
${SESSION_FILE}:
${INTEGRATION_TEST_TOOL} create
.PHONY: start-test-env
start-test-env: create-test-env
${INTEGRATION_TEST_TOOL} start
.PHONY: stop-test-env
stop-test-env:
test -f ${SESSION_FILE} && ${INTEGRATION_TEST_TOOL} stop || true
.PHONY: clean-test-env
clean-test-env: stop-test-env
rm -rf staging ${SESSION_FILE}
ch_backup/version.txt:
@echo "2.$$(git rev-list HEAD --count).$$(git rev-parse --short HEAD | perl -ne 'print hex $$_')" > ch_backup/version.txt
.PHONY: check-uv
check-uv:
@if ! command -v "uv" &>/dev/null; then \
echo 'Python project manager tool "uv" not found. Please follow installation instructions at https://docs.astral.sh/uv/getting-started/installation.' >&2; exit 1; \
fi
.PHONY: check-docker
check-docker:
@if ! command -v "docker" &>/dev/null; then \
echo 'Docker not found. Please follow installation instructions at https://docs.docker.com/engine/install.' >&2; exit 1; \
fi
.PHONY: check-docker-compose
check-docker-compose: check-docker
@if ! (docker compose version || docker-compose version) &>/dev/null; then \
echo 'Docker Compose not found. Please follow installation instructions at https://docs.docker.com/compose/install.' >&2; exit 1; \
fi
.PHONY: help
help:
@echo "Targets:"
@echo " build (default) Build Python packages (sdist and wheel)."
@echo " all Alias for \"lint test-unit build test-integration\"."
@echo " lint Run all linter tools. Alias for \"isort black codespell ruff pylint mypy\"."
@echo " test-unit Run unit tests."
@echo " test-integration Run integration tests."
@echo " isort Perform isort checks."
@echo " black Perform black checks."
@echo " codespell Perform codespell checks."
@echo " ruff Perform ruff checks."
@echo " pylint Perform pylint checks."
@echo " mypy Perform mypy checks."
@echo " create-test-env Create test environment."
@echo " start-test-env Start test environment runtime."
@echo " stop-test-env Stop test environment runtime."
@echo " clean-test-env Clean up test environment."
@echo " build-deb-package Build Debian package."
@echo " format Re-format source code to conform style settings enforced by"
@echo " isort and black tools."
@echo " clean Clean up build and test artifacts."
@echo " help Show this help message."
@echo
@echo "Environment Variables:"
@echo " UV_PYTHON Python version to use (default: \"$(shell cat .python-version)\")."
@echo " PYTEST_ARGS Arguments to pass to pytest (unit tests)."
@echo " BEHAVE_ARGS Arguments to pass to behave (integration tests)."
@echo " CLICKHOUSE_VERSION ClickHouse version to use in integration tests (default: \"$(CLICKHOUSE_VERSION)\")."