在 Debian Docker 映像中使用 librdkafka 构建 Golang 应用程序? [英] Build Golang Application with librdkafka in a Debian Docker Image?

查看:42
本文介绍了在 Debian Docker 映像中使用 librdkafka 构建 Golang 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Alpine,Alpine 完全支持最新版本的 librdkafka,我可以在我的 Dockerfile 中执行 apk add,并且可以进行以下操作:

With Alpine, Alpine fully supports recent versions of librdkafka, I can just do apk add in my Dockerfile, and the following works:

FROM golang:1.13-alpine3.10 as builder

WORKDIR /app
COPY go.mod go.sum ./
COPY src ./src/

RUN set -eux; 
  apk add --no-cache gcc git libc-dev librdkafka-dev; 
  go build -o ./ ./...

现在,对于一个特定的项目,我需要制作 Debian 友好的二进制文件,它将在 Debian/Ubuntu 服务器上运行.

Now, for a particular project, I need to make Debian friendly binaries, that will run on Debian/Ubuntu servers.

问题是:

  • 官方 Debian 存储库仅支持非常旧的 0.11.x 版本的 librdkafka.即使对于包括 backports repos 在内的伸展和破坏者也是如此.他们没有更新的版本.
  • 官方 Confluent 存储库仅支持 Debian 8 (jessie) 上的 librdkafka.由于 libssl 版本不兼容,它们在 Debian 9 (stretch) 或 10 (buster) 上根本不支持 librdkafka.
  • 官方的 golang 镜像只支持 Debian 9 (stretch) 和 10 (buster).他们不支持 Debian 8 (Jessie).

我的选择:

  • 使用不需要在系统级别安装 librdkafka 的 Golang Kafka 客户端的开发分支.如果它稳定且值得推荐,那就太棒了.
  • 在 Debian 9/10 上手动安装/构建 librdkafka.
  • 获取 Debian 8 golang 映像?
  • 我可以从 Alpine 进行 Debian 目标构建吗?我怀疑不是,但值得一问.

推荐的解决方案是什么?

What is the recommended solution?

推荐答案

这是对我有用的解决方案.我必须从源代码下载它,它提供了最新版本

Here is the solution which worked for me. I had to download it from source and it gives the latest version

示例 Dockerfile 如下所示:

Sample Dockerfile looks like this:

FROM golang:1.12.9-alpine AS build-stage

LABEL app="application_name"

ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin

# Because of https://github.com/docker/docker/issues/14914
# required by go get
RUN apk add --update --no-cache alpine-sdk bash python ca-certificates 
      libressl 
      tar 
      git openssh openssl yajl-dev zlib-dev cyrus-sasl-dev openssl-dev coreutils

WORKDIR /src/application_name

RUN git clone https://github.com/edenhill/librdkafka.git
WORKDIR /src/application_name/librdkafka
RUN /src/application_name/librdkafka/configure --prefix /usr
RUN make
RUN make install

WORKDIR /src/application_name
COPY . .
# build the application
RUN GOOS=linux go build -a -o image-name .

这篇关于在 Debian Docker 映像中使用 librdkafka 构建 Golang 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆