From b4581449056741d50931250791ded6b9fc966a45 Mon Sep 17 00:00:00 2001 From: Manabu Date: Sat, 24 Aug 2019 13:56:14 +0900 Subject: [PATCH] fix entrypoint.sh --- .circleci/config.yml | 4 +-- Dockerfile | 40 +++++++++++++++++++--- entrypoint.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 entrypoint.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d33b59..4bf0cf2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2 jobs: - deploy: + build: environment: GOPATH: /home/circleci/go CGO_ENABLED: 0 @@ -33,7 +33,7 @@ workflows: - test deploy: jobs: - - deploy: + - build: filters: branches: ignore: /.*/ diff --git a/Dockerfile b/Dockerfile index d300b9e..f7256da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,39 @@ -FROM golang:1.12 as builder +FROM golang:1.12-alpine3.10 as builder COPY . /build -RUN cd /build/cmd/dtap && go build +RUN apk --update --no-cache add git gcc musl-dev \ +&& cd /build/cmd/dtap \ +&& go build -FROM alpine:latest +FROM alpine:3.10 + +ENV DTAP_INPUT_UNIX_SOCKET "/dtap/dnstap.sock" +ENV DTAP_INPUT_UNIX_SOCKET_USER "daemon" +ENV DTAP_INPUT_TCP_LISTEN_ADDR "" +ENV DTAP_INPUT_TCP_LISTEN_PORT "10053" +ENV DTAP_OUTPUT_TCP_HOST "" +ENV DTAP_OUTPUT_TCP_PORT "10053" +ENV DTAP_OUTPUT_UNIX_SOCKET "" +ENV DTAP_OUTPUT_FLUENT_HOSTS "" +ENV DTAP_OUTPUT_FLUENT_PORT "24224" +ENV DTAP_OUTPUT_FLUENT_TAG "dnstap" +ENV DTAP_OUTPUT_KAFKA_HOSTS "" +ENV DTAP_OUTPUT_KAFKA_TOPIC "dnstap_message" +ENV DTAP_OUTPUT_NATS_HOST "" +ENV DTAP_OUTPUT_NATS_SUBJECT "dnstap_message" +ENV DTAP_OUTPUT_NATS_USER "" +ENV DTAP_OUTPUT_NATS_PASS "" +ENV DTAP_OUTPUT_NATS_TOKEN "" +ENV DTAP_IPV4_MASK 24 +ENV DTAP_IPV6_MASK 48 +ENV DTAP_ENABLE_ECS "false" +ENV DTAP_ENABLE_HASH_IP "false" +ENV DTAP_ENABLE_HASH_SALT "" + +COPY entrypoint.sh / COPY --from=builder /build/cmd/dtap/dtap /usr/bin/dtap -COPY misc/dtap.toml /config.toml -CMD ["/usr/bin/dtap"] +RUN mkdir /etc/dtap \ +&& chmod 755 /entrypoint.sh + +ENTRYPOINT [ "/entrypoint.sh" ] +CMD ["/usr/bin/dtap", "-c", "/etc/dtap/dtap.conf"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..1809e13 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,80 @@ +#!/bin/ash + +if [ ! -e "/etc/dtap/dtap.conf" ] ; then + if [ "${DTAP_INPUT_UNIX_SOCKET}" != "" ] ; then + cat <<- EOS >> /etc/dtap/dtap.conf +[[InputUnix]] + Path="${DTAP_INPUT_UNIX_SOCKET}" + User="${DTAP_INPUT_UNIX_SOCKET_USER}" +EOS + fi + if [ "${DTAP_INPUT_TCP_LISTEN_ADDR}" != "" ] ; then + cat <<- EOS >> /etc/dtap/dtap.conf +[[InputTCP]] + Address="${DTAP_INPUT_TCP_LISTEN_ADDR}" + Port=${DTAP_INPUT_TCP_LISTEN_PORT} +EOS + fi + if [ "${DTAP_OUTPUT_TCP_HOST}" != "" ] ; then + cat <<- EOS >> /etc/dtap/dtap.conf +[[OutputTCP]] + Host="${DTAP_OUTPUT_TCP_HOST}" + Port=${DTAP_OUTPUT_TCP_PORT} +EOS + fi + if [ "$DTAP_OUTPUT_UNIX_SOCKET" != "" ] ; then + cat <<- EOS >> /etc/dtap/dtap.conf +[[OutputUnix]] + Path="${DTAP_OUTPUT_UNIX_SOCKET}" +EOS + fi + if [ "${DTAP_OUTPUT_FLUENT_HOST}"] ; then + cat <<- EOS >> /etc/dtap/dtap.conf +[[OutputFluent]] + Host = "${DTAP_OUTPUT_FLUENT_HOST}" + Port = ${DTAP_OUTPUT_FLUENT_PORT} + Tag = "${DTAP_OUTPUT_FLUENT_TAG}" + [OutputKafka.flat] + IPv4Mask = ${DTAP_IPV4_MASK} + IPv6Mask = ${DTAP_IPV6_MASK} + EnableECS = ${DTAP_ENABLE_ECS} + EnableHashIP = ${DTAP_ENABLE_HASH_IP} + IPHashSaltPath = "${DTAP_ENABLE_HASH_SALT}" +EOS + + fi + if [ "${DTAP_OUTPUT_KAFKA_HOSTS}" != "" ] ; then + host=$(echo ${DTAP_OUTPUT_KAFKA_HOSTS} | sed 's/,/","/g') + cat <<- EOS >> /etc/dtap/dtap.conf +[[OutputKafka]] + Hosts = ["${host}"] + Topic = "${DTAP_OUTPUT_KAFKA_TOPIC}" + [OutputKafka.flat] + IPv4Mask = ${DTAP_IPV4_MASK} + IPv6Mask = ${DTAP_IPV6_MASK} + EnableECS = ${DTAP_ENABLE_ECS} + EnableHashIP = ${DTAP_ENABLE_HASH_IP} + IPHashSaltPath = "${DTAP_ENABLE_HASH_SALT}" +EOS + fi + if [ "${DTAP_OUTPUT_NATS_HOST}" != "" ] ; then + cat <<- EOS >> /etc/dtap/dtap.conf +[[OutputNats]] + Hosts = "${DTAP_OUTPUT_NATS_HOST}" + User = "${DTAP_OUTPUT_NATS_USER}" + Password = "${DTAP_OUTPUT_NATS_PASS}" + Token = "${DTAP_OUTPUT_NATS_TOKEN}" + Subject = "${DTAP_OUTPUT_NATS_SUBJECT}" + [OutputNats.flat] + IPv4Mask = ${DTAP_IPV4_MASK} + IPv6Mask = ${DTAP_IPV6_MASK} + EnableECS = ${DTAP_ENABLE_ECS} + EnableHashIP = ${DTAP_ENABLE_HASH_IP} + IPHashSaltPath = "${DTAP_ENABLE_HASH_SALT}" +EOS + fi +fi + +cat /etc/dtap/dtap.conf + +exec "$@" \ No newline at end of file