forked from Aiven-Open/karapace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a basic build system that allows developers to get started with Karapace without the need of figuring out what is required to work with the project on their own. The README documents how to use it, as well as all quirks that are known to me at this time. Closes Aiven-Open#553
- Loading branch information
1 parent
88bee3a
commit 5f2acd7
Showing
9 changed files
with
292 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
VENV_DIR ?= $(CURDIR)/venv | ||
PIP ?= pip3 --disable-pip-version-check --no-input --require-virtualenv | ||
PYTHON ?= python3 | ||
ifdef CI | ||
PYENV ?= $(PYTHON) | ||
else | ||
PYENV ?= pyenv exec python | ||
endif | ||
|
||
export PATH := $(VENV_DIR)/bin:$(PATH) | ||
export PS4 := \e[0m\e[32m==> \e[0m | ||
export LC_ALL := C | ||
MAKEFLAGS += --warn-undefined-variables | ||
MAKEFLAGS += --no-builtin-rules | ||
SHELL := bash | ||
.SHELLFLAGS := -euxo pipefail -O globstar -c | ||
.ONESHELL: | ||
.SILENT: | ||
.SUFFIXES: | ||
|
||
.PHONY: all | ||
all: version | ||
|
||
.PHONY: venv | ||
venv: venv/.make | ||
venv/.make: | ||
rm -fr '$(VENV_DIR)' | ||
$(PYENV) -m venv '$(VENV_DIR)' | ||
$(PIP) install --upgrade pip | ||
touch '$(@)' | ||
|
||
.PHONY: install | ||
install: venv/.deps | ||
venv/.deps: requirements-dev.txt requirements.txt | venv/.make | ||
set +x | ||
source ./bin/get-java | ||
source ./bin/get-protoc | ||
source ./bin/get-snappy | ||
set -x | ||
$(PIP) install -r '$(<)' --use-pep517 | ||
touch '$(@)' | ||
|
||
.PHONY: version | ||
version: karapace/version.py | ||
karapace/version.py: version.py | venv/.make | ||
$(PYTHON) '$(<)' '$(@)' | ||
|
||
.PHONY: test | ||
tests: unit-tests integration-tests | ||
|
||
.PHONY: unit-tests | ||
unit-tests: export PYTEST_ARGS ?= | ||
unit-tests: karapace/version.py venv/.deps | ||
rm -fr runtime/* | ||
$(PYTHON) -m pytest -s -vvv $(PYTEST_ARGS) tests/unit/ | ||
rm -fr runtime/* | ||
|
||
.PHONY: integration-tests | ||
unit-tests: export PYTEST_ARGS ?= | ||
integration-tests: karapace/version.py venv/.deps | ||
rm -fr runtime/* | ||
$(PYTHON) -m pytest -s -vvv $(PYTEST_ARGS) tests/integration/ | ||
rm -fr runtime/* | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -fr ./kafka_* ./*.egg-info/ ./dist/ ./karapace/version.py | ||
|
||
.PHONY: cleaner | ||
cleaner: clean | ||
rm -fr ./.*cache*/ | ||
|
||
.PHONY: cleanest | ||
cleanest: cleaner | ||
rm -fr '$(VENV_DIR)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
if ! command -v java; then | ||
exists() { command -v "$1" &>/dev/null; } | ||
update=() | ||
install=() | ||
java_version=11 | ||
|
||
if exists brew; then | ||
install+=(brew install "openjdk@$java_version") | ||
else | ||
if ((EUID != 0)) && exists sudo; then | ||
update+=(sudo) | ||
install+=(sudo) | ||
fi | ||
|
||
if exists apt-get; then | ||
update+=(apt-get update) | ||
install+=(apt-get install -y "openjdk-$java_version-jdk") | ||
elif exists dnf; then | ||
install+=(dnf install -y "java-$java_version-openjdk") | ||
elif exists apk; then | ||
install+=(apk add "openjdk$java_version") | ||
else | ||
printf '\e[0m\e[31mUnsupported system, install \e[1mjava\e[22m and make sure it is in your \e[1mPATH\e[22m.\e[0m\n' >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ ${CI:-false} != true ]]; then | ||
cmd= | ||
((${#update[@]} < 2)) || cmd="${update[*]} && " | ||
cmd+=${install[*]} | ||
read -ern1 -p "$cmd [Yn] " | ||
if [[ $REPLY == [Nn]* ]]; then | ||
exit 0 | ||
fi | ||
fi | ||
|
||
((${#update[@]} < 2)) || "${update[@]}" | ||
"${install[@]}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
if ! command -v protoc; then | ||
exists() { command -v "$1" &>/dev/null; } | ||
update=() | ||
install=() | ||
|
||
if exists brew; then | ||
install+=(brew install protobuf) | ||
else | ||
if ((EUID != 0)) && exists sudo; then | ||
update+=(sudo) | ||
install+=(sudo) | ||
fi | ||
|
||
if exists apt-get; then | ||
update+=(apt-get update) | ||
install+=(apt-get install -y protobuf-compiler) | ||
elif exists dnf; then | ||
install+=(dnf install -y protobuf-compiler) | ||
elif exists apk; then | ||
install+=(apk add protoc) | ||
else | ||
printf '\e[0m\e[31mUnsupported system, install \e[1mprotoc\e[22m and make sure it is in your \e[1mPATH\e[22m.\e[0m\n' >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ ${CI:-false} != true ]]; then | ||
cmd= | ||
((${#update[@]} < 2)) || cmd="${update[*]} && " | ||
cmd+=${install[*]} | ||
read -ern1 -p "$cmd [Yn] " | ||
if [[ $REPLY == [Nn]* ]]; then | ||
exit 0 | ||
fi | ||
fi | ||
|
||
((${#update[@]} < 2)) || "${update[@]}" | ||
"${install[@]}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
exists() { command -v "$1" &>/dev/null; } | ||
update=() | ||
install=() | ||
|
||
ask() { | ||
if [[ ${CI:-false} != true ]]; then | ||
cmd= | ||
((${#update[@]} < 2)) || cmd="${update[*]} && " | ||
cmd+=${install[*]} | ||
read -ern1 -p "$cmd [Yn] " | ||
if [[ $REPLY == [Nn]* ]]; then | ||
return 1 | ||
fi | ||
fi | ||
} | ||
|
||
if exists brew; then | ||
snappy_prefix() { brew --prefix snappy 2>/dev/null; } | ||
|
||
# brew might return a path even though it does not exist | ||
if ! prefix=$(snappy_prefix) || [[ ! -d $prefix ]]; then | ||
install+=(brew install snappy) | ||
if ask; then | ||
"${install[@]}" | ||
prefix=$(snappy_prefix) | ||
else | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# https://stackoverflow.com/a/41707800/1251219 | ||
export CPPFLAGS="'-I$prefix/include' '-L$prefix/lib'" | ||
elif ! ldconfig -p | grep -F 'libsnappy.so '; then | ||
if ((EUID != 0)) && exists sudo; then | ||
update+=(sudo) | ||
install+=(sudo) | ||
fi | ||
|
||
if exists apt-get; then | ||
update+=(apt-get update -y) | ||
install+=(apt-get install -y libsnappy-dev) | ||
elif exists dnf; then | ||
install+=(dnf install -y csnappy-devel) | ||
elif exists apk; then | ||
install+=(apk add --no-cache snappy-dev g++) | ||
else | ||
printf '\e[0m\e[33mUnsupported system, not installing \e[1msnappy\e[22m but carrying on in case pip is able to find the required libraries.\e[0m\n' >&2 | ||
exit 0 | ||
fi | ||
|
||
if ask; then | ||
((${#update[@]} < 2)) || "${update[@]}" | ||
"${install[@]}" | ||
fi | ||
fi |