Skip to content

Commit

Permalink
strip binaries and move to scratch for base image
Browse files Browse the repository at this point in the history
  • Loading branch information
nrvnrvn committed Dec 15, 2018
1 parent 335c9d4 commit d0f8ccf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# build container
#
FROM golang:1.10
FROM golang:1-alpine
WORKDIR /go/src/github.com/oliver006/redis_exporter/

ADD main.go /go/src/github.com/oliver006/redis_exporter/
Expand All @@ -15,18 +15,20 @@ ENV TAG=$TAG
ARG DATE
ENV DATE=$DATE

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags " -X main.VERSION=$TAG -X main.COMMIT_SHA1=$SHA1 -X main.BUILD_DATE=$DATE " -a -installsuffix cgo -o redis_exporter .
RUN apk --no-cache add ca-certificates
RUN CGO_ENABLED=0 GOOS=linux go build -o /redis_exporter \
-ldflags "-s -w -extldflags \"-static\" -X main.VERSION=$TAG -X main.COMMIT_SHA1=$SHA1 -X main.BUILD_DATE=$DATE" .




#
# release container
#
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /bin/
COPY --from=0 /go/src/github.com/oliver006/redis_exporter/ .
FROM scratch

COPY --from=0 /redis_exporter /redis_exporter
COPY --from=0 /etc/ssl/certs /etc/ssl/certs

EXPOSE 9121
ENTRYPOINT [ "/bin/redis_exporter" ]
ENTRYPOINT [ "/redis_exporter" ]
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ docker push "oliver006/redis_exporter:latest"
echo "Building binaries for Github"
echo ""
export CGO_ENABLED=0
export GO_LDFLAGS="-extldflags \"-static\" -X main.VERSION=$CIRCLE_TAG -X main.COMMIT_SHA1=$CIRCLE_SHA1 -X main.BUILD_DATE=$(date +%F-%T)"
export GO_LDFLAGS="-s -w -extldflags \"-static\" -X main.VERSION=$CIRCLE_TAG -X main.COMMIT_SHA1=$CIRCLE_SHA1 -X main.BUILD_DATE=$(date +%F-%T)"
echo "GO_LDFLAGS: $GO_LDFLAGS"

go get github.com/mitchellh/gox
Expand Down

0 comments on commit d0f8ccf

Please sign in to comment.