From 5631bba11793e645e00d92882c543904426b098a Mon Sep 17 00:00:00 2001 From: Joshua Humphries Date: Wed, 3 Jul 2019 15:57:24 -0400 Subject: [PATCH] add official Dockerfile (#104) --- .gitignore | 1 + Dockerfile | 33 +++++++++++++++++++++++++++++++++ Makefile | 6 ++++++ cmd/grpcurl/grpcurl.go | 3 ++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index 849ddff..53fe3b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ dist/ +VERSION diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f71406 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM golang:1.11.10-alpine as builder +MAINTAINER FullStory Engineering + +# currently, a module build requires gcc (so Go tool can build +# module-aware versions of std library; it ships only w/ the +# non-module versions) +RUN apk update && apk add --no-cache ca-certificates git gcc g++ libc-dev +# create non-privileged group and user +RUN addgroup -S grpcurl && adduser -S grpcurl -G grpcurl + +WORKDIR /tmp/fullstorydev/grpcurl +# copy just the files/sources we need to build grpcurl +COPY VERSION *.go go.* /tmp/fullstorydev/grpcurl/ +COPY cmd /tmp/fullstorydev/grpcurl/cmd +# and build a completely static binary (so we can use +# scratch as basis for the final image) +ENV CGO_ENABLED=0 +ENV GOOS=linux +ENV GOARCH=amd64 +ENV GO111MODULE=on +RUN go build -o /grpcurl \ + -ldflags "-w -extldflags \"-static\" -X \"main.version=$(cat VERSION)\"" \ + ./cmd/grpcurl + +# New FROM so we have a nice'n'tiny image +FROM scratch +WORKDIR / +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /grpcurl /bin/grpcurl +USER grpcurl + +ENTRYPOINT ["/bin/grpcurl"] diff --git a/Makefile b/Makefile index 982d043..8c34d31 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,12 @@ release: @GO111MODULE=off go get github.com/goreleaser/goreleaser goreleaser --rm-dist +.PHONY: docker +docker: + @echo $(dev_build_version) > VERSION + docker build -t fullstorydev/grpcurl:$(dev_build_version) . + @rm VERSION + .PHONY: checkgofmt checkgofmt: gofmt -s -l . diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index b97d74d..013e2e1 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os" + "path/filepath" "strings" "time" @@ -161,7 +162,7 @@ func main() { os.Exit(0) } if *printVersion { - fmt.Fprintf(os.Stderr, "%s %s\n", os.Args[0], version) + fmt.Fprintf(os.Stderr, "%s %s\n", filepath.Base(os.Args[0]), version) os.Exit(0) }