Skip to content

Commit

Permalink
Merge pull request #25 from grishagavrin/master
Browse files Browse the repository at this point in the history
#20 codegen inside docker
  • Loading branch information
asmyasnikov authored Feb 19, 2024
2 parents 1623f57 + bf5ad05 commit bae9c4e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
proto:
protoc --go_out=. --go_opt=module=github.com/ydb-platform/ydb-go-genproto --go-grpc_out=. --go-grpc_opt=module=github.com/ydb-platform/ydb-go-genproto -Iapi -Iapi/protos -Iapi/protos/annotations -Iapi/draft -Iapi/draft/protos api/{*.proto,protos/*.proto,protos/annotations/*.proto,draft/*.proto,draft/protos/*.proto}
proto: protobuf-3

protobuf-3:
docker build -f generate-protobuf.Dockerfile . -t ydb-go-sdk-proto-generator-env-3 --build-arg PROTOC_VER=25.3 --build-arg PTOCOC_GEN_GO=1.32.0 --build-arg PROTOC_GEN_GO_GRPC=1.3.0
docker run -v ${PWD}:/github.com/ydb-platform/ydb-go-genproto/volumes -it ydb-go-sdk-proto-generator-env-3:latest bash generate_proto.sh
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

`ydb-go-genproto` includes code generation from YDB protos

## Installation `protoc-gen-go` and `protoc-gen-go-grpc`

The protocol buffer compiler requires a plugin to generate Go code. Install it using Go 1.16 or higher by running:
```
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```
This will install a `protoc-gen-go` and `protoc-gen-go-grpc` binaries in `$GOBIN`. Set the `$GOBIN` environment variable to change the installation location. It must be in your `$PATH` for the protocol buffer compiler to find it.

## Re-generation `*.pb.go` code

1. First you must get latest YDB proto files which includes into this project as git submodule:
Expand Down
22 changes: 22 additions & 0 deletions generate-protobuf.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.16-alpine

ARG PROTOC_VER=25.3
ARG PTOCOC_GEN_GO=1.32.0
ARG PROTOC_GEN_GO_GRPC=1.3.0
ENV GOBIN=/github.com/ydb-platform/ydb-go-genproto/
ENV PATH="${PATH}:/github.com/ydb-platform/ydb-go-genproto/"

COPY . /github.com/ydb-platform/ydb-go-genproto/
RUN mkdir /github.com/ydb-platform/ydb-go-genproto/volumes
WORKDIR /github.com/ydb-platform/ydb-go-genproto/

RUN \
wget https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-x86_64.zip &&\
unzip -o protoc-*.zip -d /usr/local bin/protoc &&\
unzip -o protoc-*.zip -d /usr/local 'include/*' &&\
rm -f protoc-*.zip

RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PTOCOC_GEN_GO}
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${PROTOC_GEN_GO_GRPC}
RUN apk add bash

6 changes: 6 additions & 0 deletions generate_proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
protoc --go_out=volumes --go_opt=module=github.com/ydb-platform/ydb-go-genproto --go-grpc_out=volumes --go-grpc_opt=module=github.com/ydb-platform/ydb-go-genproto --proto_path=/github.com/ydb-platform/ydb-go-genproto/api/ /github.com/ydb-platform/ydb-go-genproto/api/*.proto
protoc --go_out=volumes --go_opt=module=github.com/ydb-platform/ydb-go-genproto --go-grpc_out=volumes --go-grpc_opt=module=github.com/ydb-platform/ydb-go-genproto --proto_path=/github.com/ydb-platform/ydb-go-genproto/api/ /github.com/ydb-platform/ydb-go-genproto/api/protos/*.proto --experimental_allow_proto3_optional
protoc --go_out=volumes --go_opt=module=github.com/ydb-platform/ydb-go-genproto --go-grpc_out=volumes --go-grpc_opt=module=github.com/ydb-platform/ydb-go-genproto --proto_path=/github.com/ydb-platform/ydb-go-genproto/api/ /github.com/ydb-platform/ydb-go-genproto/api/protos/annotations/*.proto
protoc --go_out=volumes --go_opt=module=github.com/ydb-platform/ydb-go-genproto --go-grpc_out=volumes --go-grpc_opt=module=github.com/ydb-platform/ydb-go-genproto --proto_path=/github.com/ydb-platform/ydb-go-genproto/api/ /github.com/ydb-platform/ydb-go-genproto/api/draft/protos/*.proto --experimental_allow_proto3_optional
protoc --go_out=volumes --go_opt=module=github.com/ydb-platform/ydb-go-genproto --go-grpc_out=volumes --go-grpc_opt=module=github.com/ydb-platform/ydb-go-genproto --proto_path=/github.com/ydb-platform/ydb-go-genproto/api/ /github.com/ydb-platform/ydb-go-genproto/api/draft/*.proto

0 comments on commit bae9c4e

Please sign in to comment.