From 68423d94376dbadfcb82bc716052b88b4d6df6b3 Mon Sep 17 00:00:00 2001 From: Lauri Gates Date: Mon, 18 Sep 2023 13:43:12 +0300 Subject: [PATCH 1/2] Fix Kafka configuration in test workflow The bitnami/kafka image version 3.4.1 introduced some breaking changes and some new environment variables have to be defined. https://github.com/bitnami/containers/blob/main/bitnami/kafka/README.md#351-debian-11-r4-341-debian-11-r50-332-debian-11-r176-and-323-debian-11-r161 --- .github/workflows/test-endpoint.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-endpoint.yml b/.github/workflows/test-endpoint.yml index 79d1b98..b0cd84d 100644 --- a/.github/workflows/test-endpoint.yml +++ b/.github/workflows/test-endpoint.yml @@ -12,7 +12,7 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: - # A workflow run is made up of one or more jobs that can run sequentially or in parallel +# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" tests: @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11" ] + python-version: ["3.9", "3.10", "3.11"] services: # Label used to access the service container kafka: @@ -28,11 +28,23 @@ jobs: image: bitnami/kafka:3.4 # Provide the password for postgres env: - ALLOW_PLAINTEXT_LISTENER: "yes" KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "true" + # Kafka KRaft settings + KAFKA_CFG_NODE_ID: 0 + KAFKA_CFG_PROCESS_ROLES: "controller,broker" + KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@kafka:9093" + # Listeners + KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093" + KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://:9092" + KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT" + KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER" + KAFKA_CFG_INTER_BROKER_LISTENER_NAME: "PLAINTEXT" # Set health checks to wait until postgres has started options: >- - --health-cmd "kafka-topics.sh --bootstrap-server kafka:9092 --topic hc --create --if-not-exists && kafka-topics.sh --bootstrap-server kafka:9092 --topic hc --describe" --health-interval 10s --health-timeout 5s --health-retries 5 + --health-cmd "kafka-topics.sh --bootstrap-server kafka:9092 --topic hc --create --if-not-exists && kafka-topics.sh --bootstrap-server kafka:9092 --topic hc --describe" + --health-interval 10s + --health-timeout 5s + --health-retries 5 ports: # Tests run directly on the runner so we have to map the port - 9092:9092 From 4dc1e9d4a8df7b04e73ce41452d73c5408ae79c7 Mon Sep 17 00:00:00 2001 From: Lauri Gates Date: Mon, 18 Sep 2023 14:26:46 +0300 Subject: [PATCH 2/2] Remove test workflow sleep Remove sleep command that was used to see if tests fail because Kafka wasn't ready yet. --- .github/workflows/test-endpoint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-endpoint.yml b/.github/workflows/test-endpoint.yml index b0cd84d..a17a8f9 100644 --- a/.github/workflows/test-endpoint.yml +++ b/.github/workflows/test-endpoint.yml @@ -83,6 +83,5 @@ jobs: LOG_LEVEL: "DEBUG" DEBUG: 1 run: | - uvicorn app:app --host 0.0.0.0 --port 8000 --proxy-headers & - sleep 10 && + uvicorn app:app --host 0.0.0.0 --port 8000 --proxy-headers && pytest -v tests/test_api.py