I am trying to turn my golang grpc application into a docker container, however i keep getting an error when trying to build.
The error is
messagepb/stickynote.pb.go:16:8: cannot find package "github.com/golang/protobuf/proto" in any of:
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/go/src/github.com/golang/protobuf/proto (from $GOPATH)
sticky.go:6:2: cannot find package "github.com/llgcode/draw2d" in any of:
/usr/local/go/src/github.com/llgcode/draw2d (from $GOROOT)
/go/src/github.com/llgcode/draw2d (from $GOPATH)
sticky.go:7:2: cannot find package "github.com/llgcode/draw2d/draw2dimg" in any of:
/usr/local/go/src/github.com/llgcode/draw2d/draw2dimg (from $GOROOT)
/go/src/github.com/llgcode/draw2d/draw2dimg (from $GOPATH)
messagepb/stickynote.pb.go:21:2: cannot find package "golang.org/x/net/context" in any of:
/usr/local/go/src/golang.org/x/net/context (from $GOROOT)
/go/src/golang.org/x/net/context (from $GOPATH)
messagepb/stickynote.pb.go:22:2: cannot find package "google.golang.org/grpc" in any of:
/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
/go/src/google.golang.org/grpc (from $GOPATH)
main.go:7:2: cannot find package "google.golang.org/grpc/credentials" in any of:
/usr/local/go/src/google.golang.org/grpc/credentials (from $GOROOT)
/go/src/google.golang.org/grpc/credentials (from $GOPATH)
The Dockerfile is
FROM golang:latest
RUN mkdir -p /go/src/github.com/alhennessey92/mygoapp
ADD . /go/src/github.com/alhennessey92/mygoapp
WORKDIR /go/src/github.com/alhennessey92/mygoapp
EXPOSE 8080
RUN go install github.com/alhennessey92/mygoapp
ENTRYPOINT ["/go/bin/mygoapp"]
The file structure is as follows
go
-- src
---- github.com
------ alhennessey92
-------- mygoapp
---------- Dockerfile
---------- main.go
---------- sticky.go
---------- messagepb
------------ stickynote.pb.go
------------ stickynote.proto
This is the code for main.go
package main
import (
"io"
"net"
"log"
"google.golang.org/grpc/credentials"
"golang.org/x/net/context"
pb "github.com/alhennessey92/mygoapp/messagepb"
"google.golang.org/grpc"
)
const (
useSSL = false
)
type StickyNoteServer struct{}
var stickyNoteServer StickyNoteServer
func (s *StickyNoteServer) Get(ctx context.Context, r *pb.StickyNoteRequest) (*pb.StickyNoteResponse, error) {
var sticky Sticky
sticky.Message = r.Message
sticky.Centered = false
resp := &pb.StickyNoteResponse{}
stickyBytes, err := sticky.DrawPNG(512, 512)
resp.Image = *stickyBytes
return resp, err
}
func (s *StickyNoteServer) Update(stream pb.StickyNote_UpdateServer) error {
for {
in, err := stream.Recv()
if err == io.EOF {
return nil
}
if err != nil {
return err
}
var sticky Sticky
sticky.Message = in.Message
sticky.Centered = false
resp := &pb.StickyNoteResponse{}
stickyBytes, err := sticky.DrawPNG(512, 512)
resp.Image = *stickyBytes
if err := stream.Send(resp); err != nil {
return err
}
}
return nil
}
//[START main]
func main() {
var err error
var lis net.Listener
var grpcServer *grpc.Server
if !useSSL {
lis, err = net.Listen("tcp", ":8080")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
grpcServer = grpc.NewServer()
} else {
certFile := "ssl.crt"
keyFile := "ssl.key"
creds, err := credentials.NewServerTLSFromFile(certFile, keyFile)
lis, err = net.Listen("tcp", ":443")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
grpcServer = grpc.NewServer(grpc.Creds(creds))
}
pb.RegisterStickyNoteServer(grpcServer, &stickyNoteServer)
grpcServer.Serve(lis)
}
This is the code i am running in the terminal to build the docker container
docker build -t alhennessey92/mygoapptest .
The go code i am using is from the google cloud grpc demo stickynote - https://cloud.google.com/solutions/mobile/mobile-compute-engine-grpc
I think the error has something to do with using the command go get
, however i am not sure
Thanks for your help