Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dockerfile suitable for DockerHub Auto-Builds #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#############################
# 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

WORKDIR /app

COPY --from=builder /go/src/github.com/fstab/grok_exporter/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 [ "/app/grok_exporter" ]