-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
132 lines (104 loc) · 4.27 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
SHORT_VER = $(shell git describe --tags --abbrev=0 | cut -f1-)
LONG_VER = $(shell git describe --long 2>/dev/null || echo $(SHORT_VER)-0-unknown-g`git describe --always`)
PYTHON_SOURCE_DIRS = astacus/
PYTHON_TEST_DIRS = tests/
ALL_PYTHON_DIRS = $(PYTHON_SOURCE_DIRS) $(PYTHON_TEST_DIRS)
# protobuf handling
PROTODIR=astacus/proto
PROTOBUFS = $(wildcard $(PROTODIR)/*.proto)
GENERATED_PROTOBUFS = $(patsubst %.proto,%_pb2.py,$(PROTOBUFS))
GENERATED = $(GENERATED_PROTOBUFS)
ZOOKEEPER_VERSION = 3.8.4
ZOOKEEPER_HASH = 284cb4675adb64794c63d95bf202d265cebddc0cda86ac86fb0ede8049de9187
default: $(GENERATED)
venv: default
python3 -m venv venv && source venv/bin/activate && pip install -U pip && pip install . ".[dev]"
.PHONY: clean
clean:
rm -rf rpm/ $(GENERATED) venv/ .mypy_cache/ astacus.egg-info/
.PHONY: build-dep-fedora
build-dep-fedora:
sudo dnf -y install --best --allowerasing rpm-build
sudo dnf -y install 'dnf-command(builddep)'
sudo dnf -y builddep astacus.spec
.PHONY: build-dep-ubuntu
build-dep-ubuntu:
sudo sh -c 'apt-get update && apt-get install -y git libsnappy-dev python3-pip python3-psycopg2 protobuf-compiler python3-dev'
.PHONY: test-dep-ubuntu
test-dep-ubuntu:
wget --no-verbose https://dlcdn.apache.org/zookeeper/zookeeper-$(ZOOKEEPER_VERSION)/apache-zookeeper-$(ZOOKEEPER_VERSION)-bin.tar.gz
echo "$(ZOOKEEPER_HASH) apache-zookeeper-$(ZOOKEEPER_VERSION)-bin.tar.gz" | sha256sum -c -
tar vxf apache-zookeeper-$(ZOOKEEPER_VERSION)-bin.tar.gz --wildcards apache-zookeeper-$(ZOOKEEPER_VERSION)-bin/lib/*.jar
sudo cp -r apache-zookeeper-$(ZOOKEEPER_VERSION)-bin/lib /usr/share/zookeeper
.PHONY: copyright
copyright:
$(eval MISSING_COPYRIGHT := $(shell git ls-files "*.py" | grep -v __init__.py | xargs grep -EL "Copyright \(c\) 20.* Aiven|Aiven license OK"))
@if [ "$(MISSING_COPYRIGHT)" != "" ]; then echo Missing Copyright statement in files: $(MISSING_COPYRIGHT) ; false; fi
# Normal 'coverage run' sets COVERAGE_RUN; we do the same here
# explicitly to be able to detect if we want to gather coverage, or not.
#
# pytest-cov is not parallel-mode-aware, so pretend its result was just one of many.
.PHONY: unittest
unittest: $(GENERATED)
coverage erase
COVERAGE_RUN=1 \
python3 -m pytest --cov=./ --cov-append -s -vvv -x tests/
mv .coverage .coverage.root
coverage combine
.PHONY: test
test: lint copyright unittest
.PHONY: ruff
ruff: $(GENERATED)
pre-commit run ruff-format --all-files
.PHONY: mypy
mypy: $(GENERATED)
pre-commit run mypy --all-files
.PHONY: pre-commit
pre-commit: $(GENERATED)
pre-commit run --all-files
.PHONY: lint
lint: pre-commit
# Utility targets to ensure that build-dep-X are up to date. These are
# NOT optimized for normal development.
PODMAN_RUN = podman run --rm --security-opt label=disable -v `pwd`:/src
# ^ without label=disable, modern selinux won't be happy
.PHONY: podman-test
podman-test: podman-test-fedora podman-test-ubuntu
.PHONY: podman-test-fedora
podman-test-fedora:
podman build -t astacus-fedora -f Dockerfile.fedora
$(PODMAN_RUN) astacus-fedora
.PHONY: podman-test-ubuntu
podman-test-ubuntu:
podman build -t astacus-ubuntu -f Dockerfile.ubuntu
$(PODMAN_RUN) astacus-ubuntu
.PHONY: pip-outdated
pip-outdated:
pip list --outdated
# For development purposes, run server with the default astacus conf
# and 'something' to be backed up
BACKUPROOT=/tmp/astacus/src
BACKUPSTORAGE=/tmp/astacus/backup
run-server:
rm -rf /tmp/astacus
mkdir -p $(BACKUPROOT)
mkdir -p $(BACKUPSTORAGE)
dd if=/dev/zero of=$(BACKUPROOT)/zeros bs=1000 count=1000
dd if=/dev/urandom of=$(BACKUPROOT)/random bs=1000 count=1000
echo foo > $(BACKUPROOT)/foo
echo foo > $(BACKUPROOT)/foo2
echo bar > $(BACKUPROOT)/bar
astacus server -c examples/astacus-files-local.yaml
.PHONY: rpm
rpm: $(GENERATED) /usr/bin/rpmbuild /usr/lib/rpm/check-buildroot
git archive --output=astacus-rpm-src.tar --prefix=astacus/ HEAD
# add generated files to the tar, they're not in git repository
tar -r -f astacus-rpm-src.tar --transform=s,astacus/,astacus/astacus/, $(GENERATED)
rpmbuild -bb astacus.spec \
--define '_topdir $(PWD)/rpm' \
--define '_sourcedir $(CURDIR)' \
--define 'major_version $(SHORT_VER)' \
--define 'minor_version $(subst -,.,$(subst $(SHORT_VER)-,,$(LONG_VER)))'
$(RM) astacus-rpm-src.tar
%_pb2.py: %.proto
protoc -I $(PROTODIR) $< --python_out=$(PROTODIR)