diff --git a/modules/mod/infra/factorioEvents.Dockerfile b/modules/mod/infra/factorioEvents.Dockerfile new file mode 100644 index 0000000..32676b8 --- /dev/null +++ b/modules/mod/infra/factorioEvents.Dockerfile @@ -0,0 +1,23 @@ +ARG factorioVersion=1.1.42 + + +FROM factoriotools/factorio:$factorioVersion + + + +#RUN apk add --update \ +# curl \ +# kafkacat \ +# ; + +ENV KCAT_CONFIG="/kcat.conf" + + +RUN apt-get update && apt-get install -y \ + kafkacat \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR / +COPY kafka-pipe.sh kafka-pipe.sh + + diff --git a/modules/mod/infra/kafka-pipe.sh b/modules/mod/infra/kafka-pipe.sh new file mode 100644 index 0000000..75dace3 --- /dev/null +++ b/modules/mod/infra/kafka-pipe.sh @@ -0,0 +1,24 @@ +#!/usr/bin/bash + +# Pipe Docker logs from a Factorio server to a Kafka topic + +echo "Piping logs from $FACTORIO_SERVER_CONTAINER_NAME to $KAFKA_HOST" + +# generate some distinctive key for messages from this server +SERVER_HASH=openssl dgst -sha3-512 "$CONFIG/server-settings.json" + +trap endProcess SIGINT +endProcess() { + echo "Exiting Factorio Events Kafka Pipe" + exit +} + +while :; do + + sed -n -e 's/^FactorioEvent: //p' | + kafkacat -F "$KCAT_PROP_FILE" + + echo "Error - retrying in 10 seconds" + + sleep 10 +done diff --git a/modules/mod/infra/kcat.conf b/modules/mod/infra/kcat.conf new file mode 100644 index 0000000..998c885 --- /dev/null +++ b/modules/mod/infra/kcat.conf @@ -0,0 +1 @@ +enable.idempotence=true