À l'intérieur de docker, il semble que je ne puisse pas compiler mon micro-service gRPC à cause de cette erreur:
â make build protoc --version libprotoc 3.12.4 protoc --proto_path=pkg/proto/notify/ --go_out=pkg/proto/notify/ --go-grpc_out=pkg/proto/notify/ --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative notify.proto plugin versions reported in *.pb.go files: ./pkg/proto/notify/notify.pb.go:// protoc-gen-go v1.25.0 ./pkg/proto/notify/notify.pb.go:// protoc v3.12.4 go build -o notify-service *.go
Cependant, en dehors de Docker, la chose est exécutée et compilée avec succès.
Voici mon image Docker de base:
â docker --version && docker-compose --version Docker version 19.03.12-ce, build 48a66213fe docker-compose version 1.26.2, build unknown â protoc --version libprotoc 3.12.4
Voici l'image Docker où la compilation est effectuée:
FROM registry.gitlab.com/kuecr/devops/go-protobuf-base:1.14 as base WORKDIR /app COPY . . RUN make build FROM base as testing ENTRYPOINT ["make", "test"] FROM base as production RUN make build ENTRYPOINT CompileDaemon -log-prefix=false -build="go build -o notify-service" -command="./notify-service"
Mes versions de docker et docker-compose et protoc:
RG go_version FROM golang:${go_version}-buster ARG pb_version RUN apt-get update && apt-get install -y build-essential curl git wget unzip && rm -rf /var/lib/apt/lists/* RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${pb_version}/protobuf-cpp-${pb_version}.zip && \ unzip protobuf-cpp-${pb_version}.zip && \ cd protobuf-${pb_version} && \ ./configure && \ make && \ make check && \ make install && \ ldconfig && \ cd ../ && \ rm -rf protobuf-* RUN go get github.com/githubnemo/CompileDaemon && \ go get github.com/golang/protobuf/protoc-gen-go && \ go get github.com/grpc/grpc-go/cmd/protoc-gen-go-grpc && \ go install github.com/golang/protobuf/protoc-gen-go && \ go install github.com/grpc/grpc-go/cmd/protoc-gen-go-grpc
Voici ce qui se passe lorsque j'ai exécuté make build
sur ma machine:
Step 4/9 : RUN make build ---> Running in ceb6e4d0e19b protoc --version libprotoc 3.12.4 protoc --proto_path=pkg/proto/notify/ --go_out=pkg/proto/notify/ --go-grpc_out=pkg/proto/notify/ --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative notify.proto plugin versions reported in *.pb.go files: ./pkg/proto/notify/notify.pb.go:// protoc-gen-go v1.25.0-devel ./pkg/proto/notify/notify.pb.go:// protoc v3.12.4 go build -o notify-service *.go go: downloading github.com/lib/pq v1.7.0 go: downloading google.golang.org/grpc v1.27.0 go: downloading github.com/jinzhu/gorm v1.9.14 go: downloading github.com/aws/aws-sdk-go v1.33.7 go: downloading github.com/go-kit/kit v0.10.0 go: downloading google.golang.org/protobuf v1.25.0 go: downloading github.com/go-co-op/gocron v0.2.1 go: downloading github.com/sirupsen/logrus v1.6.0 go: downloading github.com/golang/protobuf v1.4.2 go: downloading github.com/matcornic/hermes/v2 v2.1.0 go: downloading github.com/jhillyerd/enmime v0.8.1 go: downloading golang.org/x/sys v0.0.0-20200523222454-059865788121 go: downloading github.com/jaytaylor/html2text v0.0.0-20190408195923-01ec452cbe43 go: downloading github.com/vanng822/go-premailer v0.0.0-20191214114701-be27abe028fe go: downloading github.com/imdario/mergo v0.3.9 go: downloading github.com/russross/blackfriday/v2 v2.0.1 go: downloading github.com/jinzhu/inflection v1.0.0 go: downloading github.com/Masterminds/sprig v2.16.0+incompatible go: downloading golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 go: downloading github.com/PuerkitoBio/goquery v1.5.1 go: downloading github.com/pkg/errors v0.9.1 go: downloading golang.org/x/text v0.3.2 go: downloading github.com/vanng822/css v0.0.0-20190504095207-a21e860bcd04 go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0 go: downloading github.com/aokoli/goutils v1.0.1 go: downloading google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 go: downloading gopkg.in/gormigrate.v1 v1.6.0 go: downloading github.com/gorilla/css v1.0.0 go: downloading github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf go: downloading github.com/andybalholm/cascadia v1.1.0 go: downloading github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561 go: downloading golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 go: downloading github.com/olekukonko/tablewriter v0.0.1 go: downloading github.com/cention-sany/utf7 v0.0.0-20170124080048-26cad61bd60a go: downloading github.com/huandu/xstrings v1.2.0 go: downloading github.com/Masterminds/semver v1.4.2 go: downloading github.com/google/uuid v1.1.1 go: downloading github.com/mattn/go-runewidth v0.0.4 go: downloading github.com/go-logfmt/logfmt v0.5.0 go: downloading github.com/jmespath/go-jmespath v0.3.0 # gitlab.com/kuecr/fero/backend/notify/pkg/proto/notify pkg/proto/notify/notify_grpc.pb.go:14:11: undefined: grpc.SupportPackageIsVersion7 pkg/proto/notify/notify_grpc.pb.go:71:30: undefined: grpc.ServiceRegistrar make: *** [Makefile:14: build] Error 2 ERROR: Service 'notify' failed to build: The command '/bin/sh -c make build' returned a non-zero code: 2 make: *** [Makefile:64: build/notify] Error 1
J'utilise Golang 1.15 tandis que l'image Docker utilise 1.14.
5 Réponses :
L'essentiel de cette erreur est que la version du binaire utilisée pour générer le code n'est pas compatible avec la version actuelle du code. Une solution simple et rapide serait d'essayer de mettre à jour le protoc-gen-go
et la bibliothèque gRPC vers la dernière version.
allez chercher -u github.com/golang/protobuf/protoc-gen-go
puis régénérer le proto
voici un lien vers un fil de discussion reddit qui traite du problème
J'ai résolu ce problème en spécifiant la version de grpc-go à v1.33.0-dev
, mais cette version n'est pas incluse dans la version v1.31.1
.
vous voulez dire définir une version pour github.com/grpc/grpc-go/cmd/protoc-gen-go-grpc
?
non, définissez la version pour google.golang.org/grpc
, comme ceci: google.golang.org/grpc v1.33.0-dev
(une ligne dans go.mod)
est-ce bien d'utiliser une version qui n'est pas officielle?
@MeiLie Il est une version dev mais non pas officiel. De plus, je viens de vérifier la dernière version (grpc-go-1.34.0) [ github.com/grpc/grpc-go/releases/tag/v1.34. 0] et j'ai trouvé que SupportPackageIsVersion7
a été ajouté.
En complément de la réponse @Jay Lane, je souhaite partager la configuration Dockerfile que j'ai mise en place:
GO_VERSION=1.14 PROTOBUF_VERSION=3.12.4 GEN_VERSION=1.25.0 GRPC_VERSION=1.31.1 COMPILE_DAEMON_VERSION=1.2.1 DLV_VERSION=1.5.0 push: build docker push registry.gitlab.com/kuecr/devops/go-protobuf-base:$(GO_VERSION) build: docker build \ --build-arg pb_version=$(PROTOBUF_VERSION) \ --build-arg go_version=$(GO_VERSION) \ --build-arg gen_version=$(GEN_VERSION) \ --build-arg grpc_version=$(GRPC_VERSION) \ --build-arg compile_daemon_version=$(COMPILE_DAEMON_VERSION) \ --build-arg dlv_version=$(DLV_VERSION) \ -t registry.gitlab.com/kuecr/devops/go-protobuf-base:$(GO_VERSION) . history: docker image history registry.gitlab.com/kuecr/devops/go-protobuf-base:$(GO_VERSION) sh: docker run --rm --interactive --tty --entrypoint /bin/sh registry.gitlab.com/kuecr/devops/go-protobuf-base:$(GO_VERSION)
et j'ai également mis à jour google.golang.org/grpc
vers la v1.31.1
.
ÉDITER:
C'est le Makefile que j'utilise pour m'aider à construire cette image, est inclus dans un souci d'exhaustivité:
ARG go_version FROM golang:${go_version}-buster ARG pb_version ARG grpc_version ARG gen_version ARG compile_daemon_version ARG dlv_version RUN apt-get update && apt-get install -y build-essential curl git wget unzip && rm -rf /var/lib/apt/lists/* RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${pb_version}/protobuf-cpp-${pb_version}.zip && \ unzip protobuf-cpp-${pb_version}.zip && \ cd protobuf-${pb_version} && \ ./configure && \ make && \ make check && \ make install && \ ldconfig && \ cd ../ && \ rm -rf protobuf-* WORKDIR /tmp RUN GO111MODULE=on go get google.golang.org/protobuf/cmd/protoc-gen-go@v${gen_version} && \ GO111MODULE=on go get google.golang.org/grpc@v${grpc_version} && \ GO111MODULE=on go get github.com/githubnemo/CompileDaemon@v${compile_daemon_version} && \ GO111MODULE=on go get github.com/go-delve/delve/cmd/dlv@v${dlv_version} RUN git clone https://github.com/grpc/grpc-go.git && \ cd grpc-go/cmd/protoc-gen-go-grpc && \ git checkout v${grpc_version} && go install . && \ cd /tmp && rm -rf grpc-go WORKDIR /go
Ils ont déjà fourni cette solution dans leur documentation ici . J'ai eu le même problème et voici ma solution:
go get -u github.com/golang/protobuf/{proto,protoc-gen-go} go get -u google.golang.org/grpc protoc --go_out=plugins=grpc:. *.proto
Voici l'explication si vous n'utilisez pas de modules Go :
grpc.SupportPackageIsVersion
est utilisé pour suivre la version du code généré par protobuf et est différent de la version de sortie de grpc.
En bref, la structure de votre code GRPC généré est plus récente que votre package google.golang.org/grpc
. Vous devez donc mettre à jour votre package go grpc
vers le nouveau.
SupportPackageIsVersion7
prise en charge après les versions 1.32.0
. et ils prennent en charge les anciennes versions avec la version go> = 1.12
pour le mettre à jour, vous devriez
tout d'abord, supprimez le fichier actuel, pour trouver où il est stocké, vous pouvez utiliser la commande echo $PATH
pour savoir où se trouve ce fichier. puis retirez-le.
deuxièmement, installez le nouveau, pour l'installer, vous pouvez exécuter cette commande.
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
Remarque Si vous rencontrez un problème pour l'obtenir, utilisez plutôt cette commande,
go get -u github.com/golang/protobuf/protoc-gen-go
après la mise à jour, vous devez éditer votre fichier go.mod
.
changez cette ligne:
const ( SupportPackageIsVersion3 = true SupportPackageIsVersion4 = true SupportPackageIsVersion5 = true SupportPackageIsVersion6 = true SupportPackageIsVersion7 = true )
à
google.golang.org/grpc v1.32.0// or newer
Remarque: vous pouvez trouver les dernières versions à partir de cette URL
Vous pouvez trouver les versions rpc_util.go
en charge du package à la fin de rpc_util.go
dans les constantes.
quelque chose comme ça:
google.golang.org/grpc v1.21.1