Skip to content

Commit

Permalink
Merge pull request #1002 from Aiven-Open/nosahama/EC-666/docker-tests…
Browse files Browse the repository at this point in the history
…-multi-python-version

ci: multi-python version docker image for GHA matrix
  • Loading branch information
jjaakola-aiven authored Dec 10, 2024
2 parents d9b5130 + fd25e2a commit 1a4095a
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# Include source directories and files required for building.
!go
!src
!src/karapace
!src/schema_registry
!requirements/*.txt
!README.rst
!LICENSE
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/container-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
smoke-test-container:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12' ]
env:
BUILDKIT_PROGRESS: plain
steps:
Expand All @@ -18,7 +21,7 @@ jobs:
fetch-depth: 0

- name: Install requirements
run: make install
run: make install-dev

- name: Resolve Karapace version
run: |
Expand All @@ -32,6 +35,7 @@ jobs:
- name: Run container
run: make start-karapace-docker-resources
env:
PYTHON_VERSION: ${{ matrix.python-version }}
KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
Expand Down
26 changes: 18 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ jobs:
with:
cache: pip
python-version: '3.12'
- name: Install libsnappy-dev
run: sudo apt install libsnappy-dev
- name: Install requirements and typing requirements

- name: Install requirements
run: make install-dev

- name: Resolve Karapace version
run: |
python -m venv venv
source ./venv/bin/activate
pip --require-virtualenv install .[typing]
- run: |
source ./venv/bin/activate
mypy src
KARAPACE_VERSION=$(python -c "from karapace import version; print(version.__version__)")
echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV
- run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
- run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV

- name: Run mypy
run: make type-check-mypy-in-docker
env:
PYTHON_VERSION: 3.12
KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
11 changes: 10 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ jobs:
with:
go-version: '1.21.0'

- name: Install requirements
run: make install-dev

- name: Resolve Karapace version
run: echo KARAPACE_VERSION=4.1.1.dev44+gac20eeed.d20241205 >> $GITHUB_ENV
run: |
source ./venv/bin/activate
KARAPACE_VERSION=$(python -c "from karapace import version; print(version.__version__)")
echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV
- run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
- run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV

- run: make unit-tests-in-docker
env:
PYTHON_VERSION: ${{ matrix.python-version }}
KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
Expand All @@ -56,6 +63,7 @@ jobs:

- run: make e2e-tests-in-docker
env:
PYTHON_VERSION: ${{ matrix.python-version }}
KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
Expand All @@ -64,6 +72,7 @@ jobs:

- run: make integration-tests-in-docker
env:
PYTHON_VERSION: ${{ matrix.python-version }}
KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
RUNNER_UID: ${{ env.RUNNER_UID }}
RUNNER_GID: ${{ env.RUNNER_GID }}
Expand Down
8 changes: 6 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ schema:
pin-requirements:
docker run -e CUSTOM_COMPILE_COMMAND='make pin-requirements' -it -v .:/karapace --security-opt label=disable python:$(PYTHON_VERSION)-bullseye /bin/bash -c "$(PIN_VERSIONS_COMMAND)"

.PHONY: stop-karapace-docker-resources
stop-karapace-docker-resources:
$(DOCKER_COMPOSE) -f container/compose.yml down -v --remove-orphans

.PHONY: start-karapace-docker-resources
start-karapace-docker-resources: export KARAPACE_VERSION ?= 4.1.1.dev44+gac20eeed.d20241205
start-karapace-docker-resources:
Expand All @@ -121,10 +125,10 @@ unit-tests-in-docker: start-karapace-docker-resources

.PHONY: e2e-tests-in-docker
e2e-tests-in-docker: export PYTEST_ARGS ?=
e2e-tests-in-docker: start-karapace-docker-resources
e2e-tests-in-docker: stop-karapace-docker-resources start-karapace-docker-resources
rm -fr runtime/*
sleep 10
$(KARAPACE-CLI) $(PYTHON) -m pytest -s -vvv $(PYTEST_ARGS) tests/e2e/test_karapace.py
$(KARAPACE-CLI) $(PYTHON) -m pytest -s -vvv $(PYTEST_ARGS) tests/e2e/
rm -fr runtime/*

.PHONY: integration-tests-in-docker
Expand Down
4 changes: 3 additions & 1 deletion container/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG PYTHON_VERSION

# Current versions of avro and zstandard don't yet have wheels for 3.11.
FROM python:3.10.11-bullseye AS builder
FROM python:${PYTHON_VERSION}-bullseye AS builder

ARG KARAPACE_VERSION
ARG RUNNER_UID
Expand Down
1 change: 1 addition & 0 deletions container/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ services:
dockerfile: container/Dockerfile.dev
args:
KARAPACE_VERSION: $KARAPACE_VERSION
PYTHON_VERSION: $PYTHON_VERSION
RUNNER_UID: $RUNNER_UID
RUNNER_GID: $RUNNER_GID
tty: true
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[mypy]
mypy_path = $MYPY_CONFIG_FILE_DIR/stubs
python_version = 3.10
packages = karapace
packages = karapace,schema_registry
show_error_codes = True
pretty = True
warn_redundant_casts = True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ include-package-data = true
version_file = "src/karapace/version.py"

[tool.black]
target-version = ["py39"]
target-version = ["py310", "py311"]
line-length = 125
4 changes: 2 additions & 2 deletions src/karapace/kafka/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_watermark_offsets(
except KafkaException as exc:
raise_from_kafkaexception(exc)

def commit( # type: ignore[override]
def commit(
self,
message: Message | None = None,
offsets: list[TopicPartition] | None = None,
Expand Down Expand Up @@ -103,7 +103,7 @@ def committed(self, partitions: list[TopicPartition], timeout: float | None = No
except KafkaException as exc:
raise_from_kafkaexception(exc)

def subscribe( # type: ignore[override]
def subscribe(
self,
topics: list[str] | None = None,
patterns: list[str] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/karapace/schema_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def consume_messages(self, msgs: list[Message], watch_offsets: bool) -> None:
self.kafka_error_handler.handle_error(location=KafkaErrorLocation.SCHEMA_READER, error=exc)
continue # [non-strict mode]
except JSONDecodeError as exc:
non_bytes_key = msg.key().decode() # type: ignore[union-attr]
non_bytes_key = msg.key().decode()
LOG.warning("Invalid JSON in msg.key(): %s at offset %s", non_bytes_key, msg.offset())
self.offset = msg.offset() # Invalid entry shall also move the offset so Karapace makes progress.
self.kafka_error_handler.handle_error(location=KafkaErrorLocation.SCHEMA_READER, error=exc)
Expand Down

0 comments on commit 1a4095a

Please sign in to comment.