douka19950505 2019-01-15 15:53
浏览 695
已采纳

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

I am trying to create a docker image with my go application. The application (which was developed on MacOS) depends on confluent-kafka-go which in turn depends on librdkafka-dev which I install in the Docker image like so:

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"]

I am getting the following error:

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: #error "confluent-kafka-go requires librdkafka v0.11.5 or later. Install the latest version of librdkafka from the Confluent repositories, see http://docs.confluent.io/current/installation.html"

As far as I understand the latest version is installed. How can I fix it?

  • 写回答

2条回答 默认 最新

  • dqs66973 2019-01-15 23:06
    关注

    I had a similar issue a few weeks ago. IIRC confluent-kafka-go requires a recent version of librdkafka-dev, which simply was not yet released to alpine or others. I was able to find it for ubuntu though, so my solution (which was more involved than I hoped for, but it worked), was to start from clean ubuntu, install librdkafka-dev, install Go version that I want and compile inside docker.

    Here's how it looks:

    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"]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog