From ec796c4e02c019c3d92654d0df2db7b06ea38ee1 Mon Sep 17 00:00:00 2001 From: Jason O'Neil Date: Wed, 14 Aug 2024 14:30:23 +0800 Subject: [PATCH] Initial commit of plugin with local Kafka details --- plugins/ca-kafka-local/README.md | 39 +++++++++++++++++++ plugins/ca-kafka-local/bin/kafka-local-readme | 15 +++++++ plugins/ca-kafka-local/plugin.json | 18 +++++++++ plugins/ca-kafka-local/process-compose.yaml | 15 +++++++ 4 files changed, 87 insertions(+) create mode 100644 plugins/ca-kafka-local/README.md create mode 100755 plugins/ca-kafka-local/bin/kafka-local-readme create mode 100644 plugins/ca-kafka-local/plugin.json create mode 100644 plugins/ca-kafka-local/process-compose.yaml diff --git a/plugins/ca-kafka-local/README.md b/plugins/ca-kafka-local/README.md new file mode 100644 index 0000000..30b0181 --- /dev/null +++ b/plugins/ca-kafka-local/README.md @@ -0,0 +1,39 @@ +# CA Kafka Local Devbox Plugin + +At Culture Amp we use Kafka for sharing data between services, and the private [kafka-local](https://github.com/cultureamp/kafka-local) repo is how we run that locally. + +This plugin is added to other services to allow you to interact with `kafka-local` for your service. You still need to launch Kafka on your own, but this plugin provides environment variables and tools to make it easy for your project to connect to `kafka-local`. + +What it provides: + +- Environment variables + - `KAFKA_BROKERS` set to `"localhost:14231"` + - `SCHEMA_REGISTRY_URL` set to `"localhost:14228"` +- Process Compose job + - Will print information to the terminal about Kafka, once `kafka-local` is up and running. + - Allows you to add a `depends_on` clause so other services wait for `kafka-local`. + +## Usage + +To start Kafka + +- Use [Hotel CLI](https://github.com/cultureamp/hotel) +- Run `hotel services up kafka` +- In your repo run `devbox services up` + +Include the plugin in your `devbox.json`: + + { + "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/main/.schema/devbox.schema.json", + "include": [ + "github:cultureamp/devbox-extras?dir=plugins/ca-kafka-local" + ] + } + +You can have another service depend on Kafka in your `process-compose.yaml`: + + projectors_process: + command: "./gradlew run-projectors" + depends_on: + kafka_local: + condition: process_healthy diff --git a/plugins/ca-kafka-local/bin/kafka-local-readme b/plugins/ca-kafka-local/bin/kafka-local-readme new file mode 100755 index 0000000..38e9681 --- /dev/null +++ b/plugins/ca-kafka-local/bin/kafka-local-readme @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +echo +echo "== LOCAL KAFKA ==" +echo "To start Kafka Local (https://github.com/cultureamp/kafka-local):" +echo " hotel services up kafka" +echo +echo "Once all Kafka services are up and running, this step will be considered healthy" +echo +echo "== Environment variables ==" +echo "KAFKA_BROKERS: ${KAFKA_BROKERS}" +echo "SCHEMA_REGISTRY_URL: ${SCHEMA_REGISTRY_URL}" +echo diff --git a/plugins/ca-kafka-local/plugin.json b/plugins/ca-kafka-local/plugin.json new file mode 100644 index 0000000..975743f --- /dev/null +++ b/plugins/ca-kafka-local/plugin.json @@ -0,0 +1,18 @@ +{ + "name": "ca-kafka-local", + "version": "0.0.1", + "readme": "README.md", + "env": { + "KAFKA_BROKERS": "localhost:14231", + "SCHEMA_REGISTRY_URL": "localhost:14228" + }, + "create_files": { + "{{.Virtenv}}/bin/kafka-local-readme": "bin/kafka-local-readme", + "{{ .Virtenv }}/process-compose.yaml": "./process-compose.yaml" + }, + "shell": { + "scripts": { + "kafka-local-readme": "{{.Virtenv}}/bin/kafka-local-readme" + } + } +} diff --git a/plugins/ca-kafka-local/process-compose.yaml b/plugins/ca-kafka-local/process-compose.yaml new file mode 100644 index 0000000..66f37fb --- /dev/null +++ b/plugins/ca-kafka-local/process-compose.yaml @@ -0,0 +1,15 @@ +version: "0.5" + +processes: + kafka_local: + # This doesn't actually start Local Kafka, but it prints information about Kafka running, and allows you to do `depends_on: kafka_local` + command: "devbox run kafka-local-readme; tail -f /dev/null" + readiness_probe: + # This ensures kafka-ui is up and running, which means Kafka and Schema Registry are up and healthy. + # The ports are static and defined in our `local-ops` repo, and it's safe to assume it won't change. + http_get: + host: localhost + port: 12288 + failure_threshold: 999 + availability: + restart: always