Open rogaha opened 4 years ago
You should not need to install librdkafka since it is bundled with the Go client since v1.4.0.
Can you try to reproduce this with go test -v -x ./...
so we can see what is going on?
Do you have example of the docker image where I don't need to install librdkafka ?
You don't need to install librdkafka in or outside of docker at all.
Check CGO_ENABLED
env var, it must not be 0
I'm seeing this error from our build system (GitLab), and I've confirmed the CGO_ENABLED
env var is 0. I'm using v1.5.2 according to go.mod. I'm able to build locally on Ubuntu (via WSL), but I'm seeing the cannot find module for path github.com/confluentinc/confluent-kafka-go/kafka/librdkafka
error in the gitlab build logs. I noticed this note from the readme:
If you are building for Alpine Linux (musl), -tags musl must be specified.
go build -tags musl ./...
Our build system is using golang:1.13-alpine
as the base image, but the build script isn't using the command line parameter listed above (-tags musl
). Would omitting those tags lead to this error specifically somehow? I'm investigating ways I can pass in flags through our CI configuration, but was hoping someone here could confirm/deny this.
EDIT: I just tried adding the -tags musl
parameter and no luck there, still seeing this error.
I created a github repo to reproduce this issue:
https://github.com/newcarrotgames/confluent-kafka-test
If you clone that repo, and run docker build -t conkafkatest .
in the same folder you cloned the repo in, you should see this error.
EDIT - If something happens to the repo, here's the files you need to reproduce the issue (you need to run go mod init && go mod tidy
before the docker build):
Dockerfile:
FROM golang:1.13-alpine AS builder
ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 0
RUN apk update && apk upgrade && \
apk add --no-cache git
WORKDIR /build
COPY . ./
# confluent-kafka-go recommends musl tags for alpine linux builds
RUN go build -tags musl
main.go (just needed for the import):
package main
import (
"fmt"
"github.com/confluentinc/confluent-kafka-go/kafka"
)
func main() {
fmt.Printf("%+v", kafka.ConfigMap{})
}
It seems like the internal import of librdkafka_vendor/ (previously librdkafka/) is unversioned, which makes sense but is annoying. We'd really just like to have a relative import, but that doesn't seem to be supported.
Could a workaround be to add the librdkafka_vendor/ directory as a go mod import? cc @KJTsanaktsidis
Was able to get this to work using this dockerfile:
FROM golang:1.13-alpine AS builder
ENV GOOS linux
ENV GOARCH amd64
# missed this very obvious change
ENV CGO_ENABLED 1
RUN apk update && apk upgrade && \
apk add --no-cache git
# needed for gcc
RUN apk add --no-cache git build-base
WORKDIR /build
COPY . ./
# confluent-kafka-go recommends musl tags for alpine linux builds
RUN go build -tags musl
Heya, just got back from holidays and stared at it a bit until the answer hit me in the face 😄 Of course, you can't compile a confluent-kafka-go app without cgo enabled because it links against the librdkafka C library.
I suppose this is the error message you were trying to improve on in https://github.com/confluentinc/confluent-kafka-go/commit/d2e0d83bd58738501f8c98a6785e2e0de07b5f3d and had to revert because of https://github.com/confluentinc/confluent-kafka-go/issues/581 .
I definitely see how this is a very annoying slipup for everyone to keep making and a better error message would be nice. Unfortunately I can't think of any good way to do this....
Description
I'm not able to run
go test ./...
onubuntu
(GitHub Actions
).Error msg:
go get ./...
works.How to reproduce
$ go test ./...
librdkafka installed