From 86ad47aea1a012bed629fc54c953cf926848ec42 Mon Sep 17 00:00:00 2001 From: Emmanuel Evbuomwan Date: Mon, 9 Dec 2024 13:33:37 +0100 Subject: [PATCH] ci: multi-python docker image for GHA matrix --- .github/workflows/tests.yml | 15 ++++++++++++--- GNUmakefile | 16 +++++++++++++--- container/Dockerfile.dev | 4 +++- container/compose.yml | 1 + 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 60df28286..8bfc1bce6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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=$(make karapace-version); echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV + env: + PYTHON: python3 - - run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV - - run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV + - run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV; 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 }} @@ -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 }} @@ -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 }} diff --git a/GNUmakefile b/GNUmakefile index 032def928..eb3b8b304 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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: @@ -121,20 +125,26 @@ 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 integration-tests-in-docker: export PYTEST_ARGS ?= -integration-tests-in-docker: start-karapace-docker-resources +integration-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/integration/ rm -fr runtime/* +karapace-version: install + $(PYTHON) -c "from karapace import version; print(version.__version__)" + +karapace-version-in-docker: start-karapace-docker-resources + $(KARAPACE-CLI) $(PYTHON) -c "from karapace import version; print(version.__version__)" + .PHONY: type-check-mypy-in-docker type-check-mypy-in-docker: start-karapace-docker-resources $(KARAPACE-CLI) $(PYTHON) -m mypy src diff --git a/container/Dockerfile.dev b/container/Dockerfile.dev index 37a6cb5ab..c5827994c 100644 --- a/container/Dockerfile.dev +++ b/container/Dockerfile.dev @@ -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 diff --git a/container/compose.yml b/container/compose.yml index 4b7d8728b..30d823632 100644 --- a/container/compose.yml +++ b/container/compose.yml @@ -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