diff --git a/Dockerfile b/Dockerfile index 53cb032..7633f2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,23 @@ +FROM golang:1.18.1-alpine3.15 as builder ARG ELASTICSTACK_VERSION=8.1.2 -FROM docker.elastic.co/beats/filebeat:${ELASTICSTACK_VERSION} + +WORKDIR /build + +ENV GOMAXPROCS="4" + +RUN apk update +RUN apk add git bash make gcc musl-dev binutils-gold +RUN git clone --single-branch --branch="v${ELASTICSTACK_VERSION}" --depth=1 https://github.com/elastic/beats.git +RUN cd beats/filebeat/ && \ + make + + +FROM alpine:3.15 COPY --chown=root:filebeat filebeat.yml /usr/share/filebeat/filebeat.yml +COPY --chmod=750 --from=builder /build/beats/filebeat/filebeat /usr/local/bin/filebeat +COPY --chmod=750 entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["filebeat", "-e", "--strict.perms=false", "-c", "/usr/share/filebeat/filebeat.yml"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..8b6b431 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +if [ -n "$ELASTICSEARCH_PASSWORD_FILE" ]; then + ELASTICSEARCH_PASSWORD=$(cat "$ELASTICSEARCH_PASSWORD_FILE"); + export ELASTICSEARCH_PASSWORD; +fi + +# Initialize kibana stuff related to metric and filebeat +filebeat setup --dashboards --index-management -e \ + -E output.elasticsearch.hosts=["$ELASTICSEARCH_HOSTS"] \ + -E output.elasticsearch.username="$ELASTICSEARCH_USERNAME" \ + -E output.elasticsearch.password="$ELASTICSEARCH_PASSWORD" \ + -E output.elasticsearch.ssl.verification_mode=none \ + -E setup.kibana.host="$KIBANA_HOSTS" \ + -E setup.kibana.ssl.verification_mode=none \ + -c /usr/share/filebeat/filebeat.yml + +exec "$@" \ No newline at end of file diff --git a/filebeat.yml b/filebeat.yml index 7c5adb8..299d97e 100644 --- a/filebeat.yml +++ b/filebeat.yml @@ -12,9 +12,11 @@ processors: - add_cloud_metadata: ~ output.elasticsearch: - hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}' + hosts: '[${ELASTICSEARCH_HOSTS:elasticsearch:9200}]' username: '${ELASTICSEARCH_USERNAME:}' password: '${ELASTICSEARCH_PASSWORD:}' + ssl: + verification_mode: none #filebeat.inputs: # - type: container