Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
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 s12v#12 and s12v#13. Missed to include this in those PRs :)
  • Loading branch information
mumoshu committed May 23, 2018
1 parent 05f2dcd commit 3744496
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"

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 <[email protected]>"

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 <[email protected]>"

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

0 comments on commit 3744496

Please sign in to comment.