liftbridge-io / liftbridge

Lightweight, fault-tolerant message streams.
https://liftbridge.io
Apache License 2.0
2.57k stars 107 forks source link

How to build a docker image? #83

Closed laszbalo closed 5 years ago

laszbalo commented 5 years ago

I tried to build a Docker image based on the latest code. I did the following:

go get github.com/liftbridge-io/liftbridge
cd $(go env GOPATH)/src/github.com/liftbridge-io/liftbridge
docker build -t liftbridge:latest .

But I got the following error:

Sending build context to Docker daemon  5.889MB
Step 1/11 : FROM golang:1.9-alpine as build-base
 ---> b0260be938c6
Step 2/11 : RUN apk update && apk upgrade &&     apk add --no-cache bash git openssh make
 ---> Using cache
 ---> 84c05703df2d
Step 3/11 : ADD . /go/src/github.com/liftbridge-io/liftbridge
 ---> 0f6471c8f6ec
Step 4/11 : WORKDIR /go/src/github.com/liftbridge-io/liftbridge
 ---> Running in 71cb62433619
Removing intermediate container 71cb62433619
 ---> 0d5ff66e07c8
Step 5/11 : RUN go get golang.org/x/net/...
 ---> Running in 0636c8d79030
Removing intermediate container 0636c8d79030
 ---> 683c9c0f8a8d
Step 6/11 : RUN GOOS=linux GOARCH=amd64 go build
 ---> Running in 1c9c7fe77623
server/stream.go:11:2: cannot find package "github.com/Workiva/go-datastructures/queue" in any of:
    /usr/local/go/src/github.com/Workiva/go-datastructures/queue (from $GOROOT)
    /go/src/github.com/Workiva/go-datastructures/queue (from $GOPATH)
server/config.go:10:2: cannot find package "github.com/dustin/go-humanize" in any of:
    /usr/local/go/src/github.com/dustin/go-humanize (from $GOROOT)
    /go/src/github.com/dustin/go-humanize (from $GOPATH)
server/fsm.go:10:2: cannot find package "github.com/dustin/go-humanize/english" in any of:
    /usr/local/go/src/github.com/dustin/go-humanize/english (from $GOROOT)
    /go/src/github.com/dustin/go-humanize/english (from $GOPATH)
server/proto/internal.pb.go:35: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)
server/config.go:11:2: cannot find package "github.com/hako/durafmt" in any of:
    /usr/local/go/src/github.com/hako/durafmt (from $GOROOT)
    /go/src/github.com/hako/durafmt (from $GOPATH)
server/fsm.go:11:2: cannot find package "github.com/hashicorp/raft" in any of:
    /usr/local/go/src/github.com/hashicorp/raft (from $GOROOT)
    /go/src/github.com/hashicorp/raft (from $GOPATH)
server/raft.go:13:2: cannot find package "github.com/hashicorp/raft-boltdb" in any of:
    /usr/local/go/src/github.com/hashicorp/raft-boltdb (from $GOROOT)
    /go/src/github.com/hashicorp/raft-boltdb (from $GOPATH)
server/api.go:7:2: cannot find package "github.com/liftbridge-io/go-liftbridge/liftbridge-grpc" in any of:
    /usr/local/go/src/github.com/liftbridge-io/go-liftbridge/liftbridge-grpc (from $GOROOT)
    /go/src/github.com/liftbridge-io/go-liftbridge/liftbridge-grpc (from $GOPATH)
server/raft.go:16:2: cannot find package "github.com/liftbridge-io/nats-on-a-log" in any of:
    /usr/local/go/src/github.com/liftbridge-io/nats-on-a-log (from $GOROOT)
    /go/src/github.com/liftbridge-io/nats-on-a-log (from $GOPATH)
server/commitlog/commitlog.go:17:2: cannot find package "github.com/natefinch/atomic" in any of:
    /usr/local/go/src/github.com/natefinch/atomic (from $GOROOT)
    /go/src/github.com/natefinch/atomic (from $GOPATH)
server/api.go:8:2: cannot find package "github.com/nats-io/nats.go" in any of:
    /usr/local/go/src/github.com/nats-io/nats.go (from $GOROOT)
    /go/src/github.com/nats-io/nats.go (from $GOPATH)
server/api.go:9:2: cannot find package "github.com/nats-io/nuid" in any of:
    /usr/local/go/src/github.com/nats-io/nuid (from $GOROOT)
    /go/src/github.com/nats-io/nuid (from $GOPATH)
server/commitlog/index.go:11:2: cannot find package "github.com/nsip/gommap" in any of:
    /usr/local/go/src/github.com/nsip/gommap (from $GOROOT)
    /go/src/github.com/nsip/gommap (from $GOPATH)
server/commitlog/commitlog.go:18:2: cannot find package "github.com/pkg/errors" in any of:
    /usr/local/go/src/github.com/pkg/errors (from $GOROOT)
    /go/src/github.com/pkg/errors (from $GOPATH)
server/logger/logger.go:6:2: cannot find package "github.com/sirupsen/logrus" in any of:
    /usr/local/go/src/github.com/sirupsen/logrus (from $GOROOT)
    /go/src/github.com/sirupsen/logrus (from $GOPATH)
main.go:12:2: cannot find package "github.com/urfave/cli" in any of:
    /usr/local/go/src/github.com/urfave/cli (from $GOROOT)
    /go/src/github.com/urfave/cli (from $GOPATH)
server/server.go:21: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)
server/api.go:11:2: cannot find package "google.golang.org/grpc/codes" in any of:
    /usr/local/go/src/google.golang.org/grpc/codes (from $GOROOT)
    /go/src/google.golang.org/grpc/codes (from $GOPATH)
server/server.go:22: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)
server/api.go:12:2: cannot find package "google.golang.org/grpc/status" in any of:
    /usr/local/go/src/google.golang.org/grpc/status (from $GOROOT)
    /go/src/google.golang.org/grpc/status (from $GOPATH)
The command '/bin/sh -c GOOS=linux GOARCH=amd64 go build' returned a non-zero code: 1

The strange thing that I used the same steps to successfully build the image with an earlier version of Liftbridge.

Also, what is the benefit of having go.mod and go.sum files in the project when the Dockerfile does not seem to use the new module feature of golang?

EDIT:

Upon go getting Liftbridge

go get -v github.com/liftbridge-io/liftbridge

I am prompted with the following warnings/errors:

github.com/liftbridge-io/liftbridge/server
# github.com/liftbridge-io/liftbridge/server
liftbridge/server/api.go:112:55: undefined: "github.com/liftbridge-io/go-liftbridge/liftbridge-grpc".PublishRequest
liftbridge/server/api.go:113:3: undefined: "github.com/liftbridge-io/go-liftbridge/liftbridge-grpc".PublishResponse
liftbridge/server/api.go:137:24: undefined: "github.com/liftbridge-io/go-liftbridge/liftbridge-grpc".PublishResponse
laszbalo commented 5 years ago

I was able to build it with the following Dockerfile:

FROM golang:1.12-alpine as build-base
RUN apk update && apk upgrade && \
    apk add --no-cache bash git openssh make bzr
ADD . /go/src/github.com/liftbridge-io/liftbridge
WORKDIR /go/src/github.com/liftbridge-io/liftbridge
ENV GO111MODULE on
RUN go get
RUN GOOS=linux GOARCH=amd64 go build

FROM alpine:latest
COPY --from=build-base /go/src/github.com/liftbridge-io/liftbridge/liftbridge /usr/local/bin/liftbridge
EXPOSE 9292
VOLUME "/tmp/liftbridge/liftbridge-default"
ENTRYPOINT ["liftbridge"]
tylertreat commented 5 years ago

Yeah, it looks like the Dockerfile needs to be updated since switching to Go modules. I will get that fixed up or if you'd like feel free to make a PR. Sorry for the inconvenience.

tylertreat commented 5 years ago

I'm going to reopen this issue just so I can use it to track the work for fixing the Dockerfile.