From 279724e35ac7d7463fa8f187aea23f65088e4bf9 Mon Sep 17 00:00:00 2001 From: Maciej Mensfeld Date: Fri, 22 Sep 2023 11:05:02 +0200 Subject: [PATCH] Replace Docker and use Bundler cache (#144) * Replace Docker and use Bundler cache * remarks --- .github/workflows/ci.yml | 5 +++++ bin/wait_for_kafka | 24 ++++++++++++++++++++++++ docker-compose.yml | 30 ++++++++++++++++-------------- 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100755 bin/wait_for_kafka diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fa428a3..6c77875a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} + bundler-cache: true - name: Install latest bundler run: | @@ -51,6 +52,10 @@ jobs: bundle config set without development bundle install --jobs 4 --retry 3 + - name: Wait for Kafka + run: | + bundle exec bin/wait_for_kafka + - name: Run all tests env: GITHUB_COVERAGE: ${{matrix.coverage}} diff --git a/bin/wait_for_kafka b/bin/wait_for_kafka new file mode 100755 index 00000000..3caf56ab --- /dev/null +++ b/bin/wait_for_kafka @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +# Waits for Kafka to be ready +# Useful in CI where Kafka needs to be fully started before we run any tests + +require 'karafka' + +Karafka::App.setup do |config| + config.kafka[:'bootstrap.servers'] = '127.0.0.1:9092' +end + +60.times do + begin + # Stop if we can connect to the cluster and get info + exit if Karafka::Admin.cluster_info + rescue Rdkafka::RdkafkaError + puts "Kafka not available, retrying..." + sleep(1) + end +end + +puts 'Kafka not available!' + +exit 1 diff --git a/docker-compose.yml b/docker-compose.yml index ef9f6da6..cf1d3711 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,24 @@ version: '2' + services: zookeeper: - container_name: karafka_web_21_zookeeper - image: wurstmeister/zookeeper - restart: on-failure - ports: - - '2181:2181' + container_name: karafka_web_zookeeper + image: confluentinc/cp-zookeeper:7.5.0 + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 100 kafka: - container_name: karafka_web_21_kafka - image: wurstmeister/kafka + container_name: karafka_web_kafka + image: confluentinc/cp-kafka:7.5.0 + depends_on: + - zookeeper ports: - - '9092:9092' + - 9092:9092 environment: - KAFKA_ADVERTISED_HOST_NAME: localhost - KAFKA_ADVERTISED_PORT: 9092 + KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true' - volumes: - - /var/run/docker.sock:/var/run/docker.sock - restart: on-failure + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092,PLAINTEXT_HOST://localhost:9092 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1