Skip to content

Commit c835df1

Browse files
committed
Added Dockerfile suitable for DockerHub Auto-Builds
1 parent 27d47f3 commit c835df1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#############################
2+
# Multi-Stage Build
3+
4+
FROM golang:stretch as builder
5+
6+
# Install system deps
7+
# We need this in order to build oniguruma.
8+
# The debian deb packages for onigurma do not install static libs
9+
RUN apt-get update && apt-get -y install build-essential make autoconf libtool
10+
11+
# Oniguruma: fetch, build, and install static libs
12+
RUN cd /tmp && \
13+
git clone https://github.com/kkos/oniguruma.git && \
14+
cd /tmp/oniguruma && \
15+
autoreconf -vfi && \
16+
./configure && \
17+
make && \
18+
make install
19+
20+
# grok_exporter: fetch source code
21+
RUN mkdir -p /go/src/github.com/fstab && \
22+
cd /go/src/github.com/fstab && \
23+
git clone https://github.com/fstab/grok_exporter.git
24+
25+
# Fetch Golang Dependencies
26+
RUN cd /go/src/github.com/fstab/grok_exporter && \
27+
git submodule update --init --recursive && \
28+
go get
29+
30+
31+
# Build Statically-Linked Binary
32+
RUN cd /go/src/github.com/fstab/grok_exporter && \
33+
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build \
34+
-ldflags "-w -extldflags \"-static\" \
35+
-X github.com/fstab/grok_exporter/exporter.Version=$VERSION \
36+
-X github.com/fstab/grok_exporter/exporter.BuildDate=$(date +%Y-%m-%d) \
37+
-X github.com/fstab/grok_exporter/exporter.Branch=$(git rev-parse --abbrev-ref HEAD) \
38+
-X github.com/fstab/grok_exporter/exporter.Revision=$(git rev-parse --short HEAD) \
39+
"
40+
41+
#############################
42+
# Final-Stage Build
43+
44+
FROM alpine:latest
45+
46+
COPY --from=builder /go/src/github.com/fstab/grok_exporter/grok_exporter \
47+
/bin/grok_exporter
48+
49+
EXPOSE 9144
50+
ENTRYPOINT [ "/bin/grok_exporter" ]

0 commit comments

Comments
 (0)