From 3744496f3f3da93f184e52e25a47d6a76d4a7aba Mon Sep 17 00:00:00 2001 From: Yusuke KUOKA Date: Wed, 23 May 2018 17:13:29 +0900 Subject: [PATCH] Add Dockerfile This is the Dockerfile referenced in README, which is verified to work to build filebeat. Probably this can be enhanced to also support building other beats. Follow up for #12 and #13. Missed to include this in those PRs :) --- Dockerfile | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44dd62e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +# See https://stackoverflow.com/a/48324849 for how ARG before FROM works +# Used from within the first FROM +ARG GO_VERSION=${GO_VERSION:-1.10.2} +# Used from within the second FROM +ARG BEATS_VERSION=${BEATS_VERSION:-6.1.2} + +FROM golang:${GO_VERSION} AS awsbeats + +LABEL maintainr "Yusuke KUOKA " + +ADD . /go/src/github.com/s12v/awsbeats + +WORKDIR /go/src/github.com/s12v/awsbeats + +ARG BEATS_VERSION=${BEATS_VERSION:-6.1.2} +ARG GO_PLATFORM=${GO_PLATFORM:-linux-amd64} +ARG AWSBEATS_VERSION=${AWSBEATS_VERSION:-1-snapshot} +RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh +RUN go get github.com/elastic/beats || true +RUN /go/bin/dep ensure +# You need to enable CGO on both the plugin and the beat. +# Otherwise, for example, filebeat w/ CGO fails to load the plugin w/o CGO, emitting an error like: +# Exiting: plugin.Open("kinesis"): plugin was built with a different version of package net +RUN CGO_ENABLED=1 GOOS=linux make build + +FROM golang:${GO_VERSION} AS beats + +LABEL maintainr "Yusuke KUOKA " + +ADD Makefile /build/Makefile + +WORKDIR /build + +ARG BEATS_VERSION=${BEATS_VERSION:-6.1.2} +ARG GO_VERSION=${GO_VERSION:-1.10.2} +ARG GO_PLATFORM=${GO_PLATFORM:-linux-amd64} + +RUN go get github.com/elastic/beats || true +# Beats requires CGO for plugin support as per https://github.com/elastic/beats/commit/d21decb720e7fdeb986f4ebac413cc816353aa55 +RUN CGO_ENABLED=1 make beats && \ + pwd && find ./target + +FROM docker.elastic.co/beats/filebeat:${BEATS_VERSION} + +LABEL maintainr "Yusuke KUOKA " + +ARG AWSBEATS_VERSION=${AWSBEATS_VERSION:-1-snapshot} +ARG BEATS_VERSION=${BEATS_VERSION:-6.1.2} +ARG GO_VERSION=${GO_VERSION:-1.10.2} +ARG GO_PLATFORM=${GO_PLATFORM:-linux-amd64} +ARG BEAT=${BEAT:-filebeat} + +COPY --from=awsbeats /go/src/github.com/s12v/awsbeats/target/kinesis-${AWSBEATS_VERSION}-${BEATS_VERSION}-go${GO_VERSION}-linux-amd64.so /usr/share/${BEAT}/kinesis.so +COPY --from=beats /build/target/${BEAT}-${BEATS_VERSION}-go${GO_VERSION}-linux-amd64 /usr/share/${BEAT}/${BEAT} + +# Usage: +# docker run --rm s12v/awsbeats:canary cat filebeat.yml > filebeat.yml +# cat outputs.yml >> filebeat.yml +# docker run --rm -v $(pwd)/filebeat.yml:/etc/filebeat/filebeat.yml s12v/awsbeats:canary filebeat --plugin kinesis.so -e -v