在Linux上使用confluent-kafka-go构建Go应用程序

shy*_*lon 3 go apache-kafka docker

我正在尝试使用go应用程序创建一个docker镜像.该应用程序(在MacOS上开发)取决于confluent-kafka-go哪个依赖于librdkafka-dev我在Docker镜像中安装的应用程序,如下所示:

FROM golang:1.1
RUN apt-get update
RUN apt-get -y install librdkafka-dev

VOLUME /workspace
WORKDIR /workspace/src/my/app/folder
ENTRYPOINT ["/bin/sh", "-c"]
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

my/app/folder/vendor/github.com/confluentinc/confluent -kafka-go/kafka ../folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:44:2:错误:#error"confluent-kafka-go需要librdkafka v0.11.5或更高版本.从Confluent存储库安装最新版本的librdkafka,请参阅http://docs.confluent.io/current/installation.html "

据我了解的最新版本安装.我该如何解决?

Ran*_*Ran 7

几个星期前,我有类似的问题.IIRC confluent-kafka-go需要最新版本librdkafka-dev,但尚未向阿尔卑斯山或其他人发布.我能够为ubuntu找到它,所以我的解决方案(比我希望的更多,但它有效),是从干净的ubuntu开始,安装librdkafka-dev,安装我想要的Go版本并在docker中编译.

以下是它的外观:

FROM ubuntu

# Install the C lib for kafka
RUN apt-get update
RUN apt-get install -y --no-install-recommends apt-utils wget gnupg software-properties-common
RUN apt-get install -y apt-transport-https ca-certificates
RUN wget -qO - https://packages.confluent.io/deb/5.1/archive.key | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"
RUN apt-get update
RUN apt-get install -y librdkafka-dev

# Install Go
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get install -y golang-1.11-go

# build the library
WORKDIR /go/src/gitlab.appsflyer.com/rantav/kafka-mirror-tester
COPY *.go ./
COPY // the rest of your go files. You may copy recursive if you want
COPY vendor vendor

RUN GOPATH=/go GOOS=linux /usr/lib/go-1.11/bin/go build -a -o main .

EXPOSE 8000

ENTRYPOINT ["./main"]
Run Code Online (Sandbox Code Playgroud)