Skip to content

Instantly share code, notes, and snippets.

@rizo
Last active January 19, 2023 20:14
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rizo/513849f35178d19a13adcddf2d045a19 to your computer and use it in GitHub Desktop.
Save rizo/513849f35178d19a13adcddf2d045a19 to your computer and use it in GitHub Desktop.
Alpine (3.6) based docker image with Protocol Buffers compiler supporting Go.
# Protobuf Builder
# ================
#
# This image builds protocol buffers library from source with Go generation
# support. The builder and runner images are produced.
# Builder Image
# -------------
FROM golang:1.8.3-alpine3.6 as builder
# System setup
RUN apk update && apk add git curl build-base autoconf automake libtool
# Install protoc
ENV PROTOBUF_URL https://github.com/google/protobuf/releases/download/v3.3.0/protobuf-cpp-3.3.0.tar.gz
RUN curl -L -o /tmp/protobuf.tar.gz $PROTOBUF_URL
WORKDIR /tmp/
RUN tar xvzf protobuf.tar.gz
WORKDIR /tmp/protobuf-3.3.0
RUN mkdir /export
RUN ./autogen.sh && \
./configure --prefix=/export && \
make -j 3 && \
make check && \
make install
# Install protoc-gen-go
RUN go get github.com/golang/protobuf/protoc-gen-go
RUN cp /go/bin/protoc-gen-go /export/bin/
# Export dependencies
RUN cp /usr/lib/libstdc++* /export/lib/
RUN cp /usr/lib/libgcc_s* /export/lib/
# Runner Image
# ------------
FROM alpine:3.6
RUN apk --no-cache add ca-certificates
RUN mkdir /import
WORKDIR /import
COPY --from=builder /export /usr
ENTRYPOINT ["protoc"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment