ZhangZhihui's Blog  

 

 => ERROR [build 13/14] RUN go mod tidy                                                                                                                    29.3s
------
 > [build 13/14] RUN go mod tidy:
0.270 go: finding module for package github.com/ZhangZhihuiAAA/zgrpc-go-professionals/proto/todo/v2
0.270 go: finding module for package google.golang.org/grpc/metadata
0.270 go: finding module for package golang.org/x/exp/slices
0.270 go: finding module for package google.golang.org/grpc
0.270 go: finding module for package google.golang.org/grpc/codes
0.270 go: finding module for package google.golang.org/grpc/credentials
2.130 go: finding module for package google.golang.org/grpc/status
2.130 go: finding module for package google.golang.org/protobuf/proto
2.130 go: finding module for package google.golang.org/protobuf/reflect/protoreflect
2.130 go: finding module for package google.golang.org/protobuf/types/known/fieldmaskpb
2.495 go: finding module for package google.golang.org/protobuf/types/known/timestamppb
6.105 go: downloading golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
8.520 go: found golang.org/x/exp/slices in golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
8.520 go: found google.golang.org/grpc in google.golang.org/grpc v1.63.2
8.520 go: found google.golang.org/grpc/codes in google.golang.org/grpc v1.63.2
8.520 go: found google.golang.org/grpc/credentials in google.golang.org/grpc v1.63.2
8.520 go: found google.golang.org/grpc/metadata in google.golang.org/grpc v1.63.2
8.520 go: found google.golang.org/grpc/status in google.golang.org/grpc v1.63.2
8.520 go: found google.golang.org/protobuf/proto in google.golang.org/protobuf v1.34.0
8.520 go: found google.golang.org/protobuf/reflect/protoreflect in google.golang.org/protobuf v1.34.0
8.520 go: found google.golang.org/protobuf/types/known/fieldmaskpb in google.golang.org/protobuf v1.34.0
8.520 go: found google.golang.org/protobuf/types/known/timestamppb in google.golang.org/protobuf v1.34.0
8.521 go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de
8.522 go: downloading github.com/google/go-cmp v0.6.0
8.525 go: downloading golang.org/x/sys v0.17.0
11.16 go: downloading google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de
11.31 go: downloading golang.org/x/net v0.21.0
17.77 go: downloading golang.org/x/text v0.14.0
29.12 go: finding module for package github.com/ZhangZhihuiAAA/zgrpc-go-professionals/proto/todo/v2
29.12 go: github.com/ZhangZhihuiAAA/zgrpc-go-professionals/server imports
29.12   github.com/ZhangZhihuiAAA/zgrpc-go-professionals/proto/todo/v2: git init --bare in /go/pkg/mod/cache/vcs/3e7b41384ed07d6c9f48613653b73654841a8f230ac8fa3d767fa321c5d8198d: exec: "git": executable file not found in $PATH
------
Dockerfile:48
--------------------
  46 |     # download dependencies and build
  47 |     # RUN go mod download
  48 | >>> RUN go mod tidy
  49 |     RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" -o /go/bin/app
  50 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c go mod tidy" did not complete successfully: exit code: 1

 

Module "github.com/ZhangZhihuiAAA/zgrpc-go-professionals/proto" doesn't exist in Github.

 

Solution: 

Step 1: Change the import statements, using local packages instead of remote github packages.

Step 2: Merge the three modules server, client and proto into one module.

Step 3: 

In todo.proto:

package todo.v2;

......

option go_package = "zgrpc-go-professionals/pb/todo/v2";

 

In go files:

pb "zgrpc-go-professionals/pb/todo/v2"

 

In Dockerfile:

# generate code out of proto files
WORKDIR /go
ENV MODULE=zgrpc-go-professionals
RUN protoc --go_out=src \
           --go_opt=module=$MODULE \
           --go-grpc_out=src \
           --go-grpc_opt=module=$MODULE \
           src/proto/todo/v2/*.proto

 

posted on 2024-05-04 20:29  ZhangZhihuiAAA  阅读(84)  评论(0编辑  收藏  举报