Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile protobufs in docker #252

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions peerswaprpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.21.0-bookworm

RUN apt-get update && apt-get install -y \
git \
protobuf-compiler='3.21.12*' \
clang-format='1:14.0*'

ARG PROTOC_GEN_VERSION
ARG GRPC_GATEWAY_VERSION

ENV PROTOC_GEN_GO_GRPC_VERSION="v1.1.0"
ENV GOCACHE=/tmp/build/.cache
ENV GOMODCACHE=/tmp/build/.modcache

RUN echo ${PROTOC_GEN_VERSION}

RUN cd /tmp \
&& mkdir -p /tmp/build/.cache \
&& mkdir -p /tmp/build/.modcache \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_VERSION} \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION} \
&& go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@${GRPC_GATEWAY_VERSION} \
&& go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@${GRPC_GATEWAY_VERSION} \
&& chmod -R 777 /tmp/build/

WORKDIR /build

CMD ["/bin/sh", "/build/peerswaprpc/gen_protos.sh"]
4 changes: 4 additions & 0 deletions peerswaprpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ ${DIR}/peerswaprpc.swagger.json:
${DIR}/peerswaprpc_grpc.pb.go ${DIR}/peerswaprpc.pb.go ${DIR}/peerswaprpc.pb.gw.go: ${DIR}/peerswaprpc.proto
protoc ${PROTOC_OPTS} ${DIR}/peerswaprpc.proto
PHONY:

.PHONY: all-rpc-docker
all-rpc-docker:
./gen_protos_docker.sh
16 changes: 16 additions & 0 deletions peerswaprpc/gen_protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

protoc -I. \
--go_out=paths=source_relative:. \
--go-grpc_out=paths=source_relative:. \
--grpc-gateway_out=. \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt grpc_api_configuration=peerswaprpc/peerswap.yaml \
peerswaprpc/peerswaprpc.proto

protoc \
--openapiv2_out=. \
--openapiv2_opt logtostderr=true \
--openapiv2_opt grpc_api_configuration=peerswaprpc/peerswap.yaml \
peerswaprpc/peerswaprpc.protos
23 changes: 23 additions & 0 deletions peerswaprpc/gen_protos_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

# Directory of the script file, independent of where it's called from.
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"

PROTOC_GEN_VERSION=$(go list -f '{{.Version}}' -m google.golang.org/protobuf)
GRPC_GATEWAY_VERSION=$(go list -f '{{.Version}}' -m github.com/grpc-ecosystem/grpc-gateway/v2)

echo "Building protobuf compiler docker image..."
docker build -t protobuf-builder \
--build-arg PROTOC_GEN_VERSION="$PROTOC_GEN_VERSION" \
--build-arg GRPC_GATEWAY_VERSION="$GRPC_GATEWAY_VERSION" \
.

echo "Compiling and formatting *.proto files..."
docker run \
--rm \
--user "$UID:$(id -g)" \
-e UID=$UID \
-v "$DIR/../:/build" \
protobuf-builder
2 changes: 1 addition & 1 deletion peerswaprpc/peerswaprpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions peerswaprpc/peerswaprpc_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading