ARG GOVER

FROM golang:$GOVER

ARG PROTOC
ARG PROTOGO
ARG TWIRP
ARG LINT

RUN apt-get update && apt-get install -y unzip
RUN mkdir -p /lib/protoc && cd /lib/protoc && wget "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC}/protoc-${PROTOC}-linux-x86_64.zip" && unzip protoc-${PROTOC}-linux-x86_64.zip
RUN ln -s /lib/protoc/bin/protoc /bin/protoc

# install protoc-gen-go
RUN mkdir -p $GOPATH/src/github.com/golang
RUN cd $GOPATH/src/github.com/golang && git clone https://github.com/golang/protobuf.git && cd protobuf && git reset --hard v${PROTOGO}
RUN go install github.com/golang/protobuf/protoc-gen-go

# Install twirp
RUN mkdir -p $GOPATH/src/github.com/twitchtv
RUN cd $GOPATH/src/github.com/twitchtv && git clone https://github.com/twitchtv/twirp.git && cd twirp && git reset --hard v${TWIRP}
RUN go install github.com/twitchtv/twirp/protoc-gen-twirp

# Install proto linter
RUN mkdir -p $GOPATH/src/github.com/ckaznocha/protoc-gen-lint
RUN cd $GOPATH/src/github.com/ckaznocha && git clone https://github.com/ckaznocha/protoc-gen-lint.git && cd protoc-gen-lint && git reset --hard v${LINT}
RUN go install github.com/ckaznocha/protoc-gen-lint
RUN /bin/protoc

ENTRYPOINT ["/bin/protoc"]
