Scott Baker | 4a35a70 | 2019-11-26 08:17:33 -0800 | [diff] [blame] | 1 | FROM golang:1.11.10-alpine as builder |
| 2 | MAINTAINER FullStory Engineering |
| 3 | |
| 4 | # currently, a module build requires gcc (so Go tool can build |
| 5 | # module-aware versions of std library; it ships only w/ the |
| 6 | # non-module versions) |
| 7 | RUN apk update && apk add --no-cache ca-certificates git gcc g++ libc-dev |
| 8 | # create non-privileged group and user |
| 9 | RUN addgroup -S grpcurl && adduser -S grpcurl -G grpcurl |
| 10 | |
| 11 | WORKDIR /tmp/fullstorydev/grpcurl |
| 12 | # copy just the files/sources we need to build grpcurl |
| 13 | COPY VERSION *.go go.* /tmp/fullstorydev/grpcurl/ |
| 14 | COPY cmd /tmp/fullstorydev/grpcurl/cmd |
| 15 | # and build a completely static binary (so we can use |
| 16 | # scratch as basis for the final image) |
| 17 | ENV CGO_ENABLED=0 |
| 18 | ENV GOOS=linux |
| 19 | ENV GOARCH=amd64 |
| 20 | ENV GO111MODULE=on |
| 21 | RUN go build -o /grpcurl \ |
| 22 | -ldflags "-w -extldflags \"-static\" -X \"main.version=$(cat VERSION)\"" \ |
| 23 | ./cmd/grpcurl |
| 24 | |
| 25 | # New FROM so we have a nice'n'tiny image |
| 26 | FROM scratch |
| 27 | WORKDIR / |
| 28 | COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt |
| 29 | COPY --from=builder /etc/passwd /etc/passwd |
| 30 | COPY --from=builder /grpcurl /bin/grpcurl |
| 31 | USER grpcurl |
| 32 | |
| 33 | ENTRYPOINT ["/bin/grpcurl"] |