在docker内部,由于以下错误,我似乎无法编译我的gRPC微服务:
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
然而,在Docker之外,这件事是运行和编译成功的。
这是我的基本码头形象:
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
这是完成编译的Docker映像:
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"
我的码头和码头-合成和原型版本:
✖ 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
当我在机器上运行make build
时,会发生这样的情况:
➜ 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
我使用Golang 1.15,而Docker图像使用1.14。
发布于 2020-08-31 03:17:29
此错误的要点是用于生成代码的二进制文件版本与当前版本的代码不兼容。一个快速而简单的解决方案是尝试将protoc-gen-go
编译器和gRPC库更新为最新版本。
去找-u github.com/golang/protobuf/protobuf
然后恢复原语
在这里指向讨论此问题的reddit线程的链接
发布于 2020-09-07 10:20:59
发布于 2020-11-18 09:41:17
grpc.SupportPackageIsVersion
用于跟踪protobuf生成的代码的版本,并且与grpc版本不同。
简而言之,生成的GRPC代码结构比google.golang.org/grpc
包更新。因此,您必须将go grpc
包更新为新的包。
SupportPackageIsVersion7
支持1.32.0
版本之后。他们还支持go版本>= 1.12的旧版本
要更新它,您应该
echo $PATH
命令查找该文件的位置。那就把它移开。go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
如果您有任何问题要得到它,请使用下面的命令,
go get -u github.com/golang/protobuf/protoc-gen-go
更新后,必须编辑go.mod
文件。
更改这一行:
google.golang.org/grpc v1.21.1
至
google.golang.org/grpc v1.32.0// or newer
注释:,您可以找到这个URL的最新版本
您可以在rpc_util.go
末尾的常量中找到包的版本支持。
就像这样:
const (
SupportPackageIsVersion3 = true
SupportPackageIsVersion4 = true
SupportPackageIsVersion5 = true
SupportPackageIsVersion6 = true
SupportPackageIsVersion7 = true
)
https://stackoverflow.com/questions/63662787
复制相似问题