diff --git a/docker-compose-scale.yaml b/docker-compose-scale.yaml new file mode 100644 index 00000000..c610e30f --- /dev/null +++ b/docker-compose-scale.yaml @@ -0,0 +1,21 @@ +version: '2' +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + kafka: + build: . + ports: + - "9094" + environment: + INSIDE_HOSTNAME_COMMAND: "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' `hostname`" + HOSTNAME_COMMAND: "docker info | grep ^Name: | cut -d' ' -f 2" + PORT_COMMAND: "docker port `hostname` 9094 | cut -d: -f 2" + KAFKA_ADVERTISED_LISTENERS: INSIDE://_{INSIDE_HOSTNAME_COMMAND}:9092,OUTSIDE://_{HOSTNAME_COMMAND}:_{PORT_COMMAND} + KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9094 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + volumes: + - /var/run/docker.sock:/var/run/docker.sock diff --git a/start-kafka.sh b/start-kafka.sh index 51567abf..e7c89818 100755 --- a/start-kafka.sh +++ b/start-kafka.sh @@ -50,31 +50,19 @@ if [[ -n "$KAFKA_HEAP_OPTS" ]]; then unset KAFKA_HEAP_OPTS fi -if [[ -n "$HOSTNAME_COMMAND" ]]; then - HOSTNAME_VALUE=$(eval "$HOSTNAME_COMMAND") - - # Replace any occurences of _{HOSTNAME_COMMAND} with the value - IFS=$'\n' - for VAR in $(env); do - if [[ $VAR =~ ^KAFKA_ && "$VAR" =~ "_{HOSTNAME_COMMAND}" ]]; then - eval "export ${VAR//_\{HOSTNAME_COMMAND\}/$HOSTNAME_VALUE}" - fi - done - IFS=$ORIG_IFS -fi - -if [[ -n "$PORT_COMMAND" ]]; then - PORT_VALUE=$(eval "$PORT_COMMAND") - - # Replace any occurences of _{PORT_COMMAND} with the value - IFS=$'\n' - for VAR in $(env); do - if [[ $VAR =~ ^KAFKA_ && "$VAR" =~ "_{PORT_COMMAND}" ]]; then - eval "export ${VAR//_\{PORT_COMMAND\}/$PORT_VALUE}" - fi - done - IFS=$ORIG_IFS -fi +IFS=$'\n' +for COMMAND in $(env); do + if [[ $COMMAND =~ _COMMAND= ]]; then + COMMAND_KEY=${COMMAND%=*} + COMMAND_VALUE=$(eval "${COMMAND#*=}") + for VAR in $(env); do + if [[ $VAR =~ ^KAFKA_ && "$VAR" =~ _{$COMMAND_KEY} ]]; then + eval "export ${VAR//_\{$COMMAND_KEY\}/$COMMAND_VALUE}" + fi + done + fi +done +IFS=$ORIG_IFS if [[ -n "$RACK_COMMAND" && -z "$KAFKA_BROKER_RACK" ]]; then KAFKA_BROKER_RACK=$(eval "$RACK_COMMAND")