From c835df16cc6a16cdf5ad73967a361dca3d6a2e23 Mon Sep 17 00:00:00 2001 From: David C Wang Date: Sun, 12 May 2019 18:53:31 +0000 Subject: [PATCH 1/2] Added Dockerfile suitable for DockerHub Auto-Builds --- Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b7ca8df8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +############################# +# Multi-Stage Build + +FROM golang:stretch as builder + +# Install system deps +# We need this in order to build oniguruma. +# The debian deb packages for onigurma do not install static libs +RUN apt-get update && apt-get -y install build-essential make autoconf libtool + +# Oniguruma: fetch, build, and install static libs +RUN cd /tmp && \ + git clone https://github.com/kkos/oniguruma.git && \ + cd /tmp/oniguruma && \ + autoreconf -vfi && \ + ./configure && \ + make && \ + make install + +# grok_exporter: fetch source code +RUN mkdir -p /go/src/github.com/fstab && \ + cd /go/src/github.com/fstab && \ + git clone https://github.com/fstab/grok_exporter.git + +# Fetch Golang Dependencies +RUN cd /go/src/github.com/fstab/grok_exporter && \ + git submodule update --init --recursive && \ + go get + + +# Build Statically-Linked Binary +RUN cd /go/src/github.com/fstab/grok_exporter && \ + GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build \ + -ldflags "-w -extldflags \"-static\" \ + -X github.com/fstab/grok_exporter/exporter.Version=$VERSION \ + -X github.com/fstab/grok_exporter/exporter.BuildDate=$(date +%Y-%m-%d) \ + -X github.com/fstab/grok_exporter/exporter.Branch=$(git rev-parse --abbrev-ref HEAD) \ + -X github.com/fstab/grok_exporter/exporter.Revision=$(git rev-parse --short HEAD) \ + " + +############################# +# Final-Stage Build + +FROM alpine:latest + +COPY --from=builder /go/src/github.com/fstab/grok_exporter/grok_exporter \ + /bin/grok_exporter + +EXPOSE 9144 +ENTRYPOINT [ "/bin/grok_exporter" ] From 1f0ddb19ea64e407ee5450733b882b055bb745ef Mon Sep 17 00:00:00 2001 From: David C Wang Date: Sun, 12 May 2019 21:01:25 +0000 Subject: [PATCH 2/2] Added Logstash Patterns to Dockerfile --- Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7ca8df8..33215475 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,8 +43,12 @@ RUN cd /go/src/github.com/fstab/grok_exporter && \ FROM alpine:latest +WORKDIR /app + COPY --from=builder /go/src/github.com/fstab/grok_exporter/grok_exporter \ - /bin/grok_exporter + /app/grok_exporter +COPY --from=builder /go/src/github.com/fstab/grok_exporter/logstash-patterns-core \ + /app/logstash-patterns-core EXPOSE 9144 -ENTRYPOINT [ "/bin/grok_exporter" ] +ENTRYPOINT [ "/app/grok_exporter" ]