When using the 1.4.0 release, the bundled _librdkafka_ fails to work as intended with the latest alpine.
Build an application which uses _github.com/confluentinc/confluent-kafka-go_, in a container, using the alpine:3.11 image (which, at the time of writing, is actually alpine:3.11.5) as a base. Errors such as the following will be displayed:
go: downloading github.com/confluentinc/confluent-kafka-go v1.4.0
# github.com/confluentinc/confluent-kafka-go/kafka
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_fatal_error':
(.text+0x141): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_abortable_error':
(.text+0x64f): undefined reference to `__strdup'
...
Installing a fresh build of _librdkafka_ 1.4.0 into the container and building the application with -tags dynamic resolves the issue.
Could possibly be because the bundled _librdkafka_ was built from a :edge release of alpine, instead of :latest?
Please provide the following information:
LibraryVersion()): 1.4.0, bundled."debug": ".." as necessary): N/Asimilar issue here
from golang:1.14.2 I also can't install librdkafka 1.4.0 from deb using this manual https://docs.confluent.io/current/installation/installing_cp/deb-ubuntu.html#systemd-ubuntu-debian-install
wget -qO - https://packages.confluent.io/deb/5.4/archive.key | apt-key add -
add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.4 stable main"
apt-get update && apt-get install librdkafka-dev -y
Result in:
The following packages have unmet dependencies:
librdkafka-dev : Depends: librdkafka1 (= 1.3.0~1confluent5.4.1-1) but 0.9.3-1 is to be installed
Depends: librdkafka++1 (= 1.3.0~1confluent5.4.1-1) but 0.9.3-1 is to be installed
E: Unable to correct problems, you have held broken packages.
Thank you for reporting this.
The bundled librdkafka alpine builds is built on Alpine 3.8.
@bschofield
Did you build your application with -tags musl? It seems like it is linking the glibc librdkafka (which references __strdup).
@otavioprado Since you are on Debian you should not see the link error, can you provide the full output (including build command) that fails your Go application build?
@edenhill Thanks for the fast response!
I did not use -tags musl. Using -tags musl does indeed fix the issue.
Would it be useful to include a comment about the need to add -tags musl for alpine builds, in https://github.com/confluentinc/confluent-kafka-go/blob/master/README.md#install-the-client? At the moment I see that you do mention it in a separate repo (https://github.com/confluentinc/confluent-kafka-go-example/blob/master/README.md), but you don't mention it in the main repo README.
Along these same lines, I can confirm that this worked with golang:1.13.10-alpine3.10 as my builder_base image with librdkafka v1.3.0.
...
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags static_all,netgo -o /bin/app ./cmd/**/main.go
# final stage
FROM alpine:3.10
COPY --from=builder_base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder_base /bin/app /bin/app
But as soon as I switch to 1.4.0 of confluent-kafka-go, and librdkafka, I get the below error:
BROKERFAIL|rdkafka#consumer-1| [thrd:sasl_ssl://cloud_host:9092/bootstr]: sasl_ssl://cloud_host:9092/bootstrap: failed: err: Local: SSL error: (errno: No error information)
Here's the base image with the updated versions... For the working version, just substitute the docker image to golang:1.13.10-apine3.11, librdkafka v1.3.0.
FROM golang:1.14.2-alpine3.11 AS go_kafka_base
RUN apk update && apk add --no-cache \
bash \
build-base \
coreutils \
gcc \
git \
make \
musl-dev \
openssl-dev \
openssl \
libsasl \
libgss-dev \
rpm \
lz4-dev \
zlib-dev \
ca-certificates \
wget && \
cd $(mktemp -d) && \
wget -nv -O cyrus-sasl-2.1.27.tar.gz https://github.com/cyrusimap/cyrus-sasl/releases/download/cyrus-sasl-2.1.27/cyrus-sasl-2.1.27.tar.gz && \
tar -xz --strip-components=1 -f cyrus-sasl-2.1.27.tar.gz && \
rm -f cyrus-sasl-2.1.27.tar.gz && \
./configure --prefix=/usr --disable-sample --disable-obsolete_cram_attr --disable-obsolete_digest_attr --enable-static --disable-shared \
--disable-checkapop --disable-cram --disable-digest --enable-scram --disable-otp --disable-gssapi --with-dblib=none --with-pic && \
make && \
make install
RUN cd $(mktemp -d) && \
wget -nv -O v1.4.0.tar.gz https://github.com/edenhill/librdkafka/archive/v1.4.0.tar.gz && \
tar -xz --strip-components=1 -f v1.4.0.tar.gz && \
rm -f v1.4.0.tar.gz && \
./configure --prefix=/usr --enable-sasl && \
make -j && \
make install
@blaketastic2 I'm trying to build with yours, and I'm getting multiple errors:
undefined reference to__strdup'`
Full dump:
# github.com/confluentinc/confluent-kafka-go/kafka
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_fatal_error':
(.text+0x141): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_abortable_error':
(.text+0x64f): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_send_offsets_to_transaction':
(.text+0x1a43): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_admin.o): in function `rd_kafka_NewTopic_new':
(.text+0x2f4): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_admin.o): in function `rd_kafka_AlterConfigsResponse_parse':
(.text+0x59dc): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_admin.o):(.text+0x6f64): more undefined references to `__strdup' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_metadata.o): in function `rd_kafka_parse_Metadata':
(.text+0x4478): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_metadata.o): in function `rd_list_string_copy':
(.text+0x6482): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_metadata.o): in function `rd_kafka_metadata_leader_query_tmr_cb':
(.text+0x6ead): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_partition.o): in function `rd_kafka_topic_partition_list_add0':
(.text+0x2f0b): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_partition.o): in function `rd_kafka_toppar_enq_error':
(.text+0x4ff5): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_partition.o): in function `rd_kafka_topic_partition_new':
(.text+0x51c5): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_partition.o): in function `rd_kafka_topic_partition_new_from_rktp':
(.text+0x5258): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_partition.o): in function `rd_kafka_topic_partition_list_get_leaders':
(.text+0x629f): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_partition.o): in function `rd_kafka_topic_partition_list_get_topic_names':
(.text+0x683b): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_pattern.o): in function `rd_kafka_pattern_new':
(.text+0xb1): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_pattern.o): in function `rd_kafka_pattern_list_init':
(.text+0x372): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_pattern.o): in function `rd_kafka_pattern_list_new':
(.text+0x5b9): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `rd_kafka_cgrp_op_serve':
(.text+0xbaa): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `rd_kafka_consumer_group_metadata_new':
(.text+0x65c7): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `rd_kafka_consumer_group_metadata':
(.text+0x6654): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `rd_kafka_consumer_group_metadata_dup':
(.text+0x66f2): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `rd_kafka_consumer_group_metadata_read':
(.text+0x688c): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `unittest_cgrp':
(.text+0x698f): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o):(.text+0x6e65): more undefined references to `__strdup' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_cgrp.o): in function `rd_kafka_cgrp_handle_JoinGroup':
(.text+0xaa26): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_request.o): in function `rd_kafka_handle_OffsetFetch':
(.text+0x39c5): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_request.o): in function `rd_kafka_MetadataRequest':
(.text+0xa19c): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_request.o): in function `rd_list_string_copy':
(.text+0xa7a2): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_op.o): in function `rd_kafka_q_op_err':
(.text+0x82e): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_op.o): in function `rd_kafka_op_throttle_time':
(.text+0xf84): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_offset.o): in function `rd_kafka_commit':
(.text+0x22a): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_offset.o):(.text+0x473): more undefined references to `__strdup' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka.o): in function `rd_kafka_ListGroups_resp_cb':
(.text+0x70c3): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka.o): in function `rd_kafka_DescribeGroups_resp_cb':
(.text+0xb30b): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xb35e): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xb38d): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xb3c9): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xb3fe): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xb81d): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka.o):(.text+0xb84e): more undefined references to `__strndup' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_plugin.o): in function `rd_kafka_plugins_conf_set0':
(.text+0x221): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rddl.o): in function `rd_dl_error':
(.text+0x1af): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0x1df): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdhdrhistogram.o): in function `unittest_rdhdrhistogram':
(.text+0x1b2e): undefined reference to `__isnan'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0x1b4a): undefined reference to `__isnan'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_sasl_oauthbearer.o): in function `rd_kafka_oauthbearer_set_token0':
(.text+0x1e3): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0x208): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_sasl_oauthbearer.o): in function `rd_kafka_oauthbearer_set_token_failure0':
(.text+0x4cb): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_sasl_oauthbearer.o): in function `rd_kafka_oauthbearer_unsecured_token0':
(.text+0x7a8): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0x943): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_sasl_oauthbearer.o):(.text+0x9b3): more undefined references to `__strdup' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_sasl_oauthbearer.o): in function `rd_kafka_sasl_oauthbearer_fsm':
(.text+0x3af9): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock.o): in function `rd_kafka_mock_topic_new':
(.text+0xba9): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock.o): in function `rd_kafka_mock_topic_set_error':
(.text+0x15e3): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock.o): in function `rd_kafka_mock_topic_create':
(.text+0x1677): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock.o): in function `rd_kafka_mock_partition_set_leader':
(.text+0x1717): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock.o): in function `rd_kafka_mock_partition_set_follower':
(.text+0x17a7): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock.o):(.text+0x183d): more undefined references to `__strdup' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mock_cgrp_member_add':
(.text+0x8e5): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mock_cgrp_get':
(.text+0xd1e): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xd46): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../pkg/mod/github.com/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mcgrp_rebalance_timer_cb':
(.text+0x13dd): undefined reference to `__strndup'
Yea, I鈥檓 not able to get 1.4.0 to build. I have it working for 1.3.0 and that can be seen here https://github.com/confluentinc/confluent-kafka-go/issues/461
@blaketastic2 @fals Set -tags musl if you want to use the built-in librdkafka, set -tags dynamic if you want to use your own librdkafka. Closing this now as it wasn't a bug.
@bschofield Building with -tags musl and removing -tags static_all still results in the same broker fail message, but it does build. I'll track the brokerfail on another issue.
BROKERFAIL|rdkafka#consumer-1| [thrd:sasl_ssl://cloud_host:9092/bootstr]: sasl_ssl://cloud_host:9092/bootstrap: failed: err: Local: SSL error: (errno: No error information)
@blaketastic2 Your broker fail message sounds like it's caused by the included librdkafka not having the SSL support you need. Try compiling your own librdkafka (1.4.0) and then building the go app with -tags dynamic. This is what I was doing in production and it was working for me, with SSL enabled.
I ended up getting past this by continuing to copy the ca-certificates into the docker image as I mentioned earlier, and then making sure the consumer set:
ssl.ca.location=/etc/ssl/certs/ca-certificates.crt
Setting this prior to 1.4.0 was not needed, and instead was able to find the ssl ca on its own.
I am getting:
./xxx.go:15:9: undefined: kafka.Producer
when building:
FROM golang:1.14-alpine AS builder
WORKDIR /go/src/app
COPY . .
RUN go get -d -v
RUN CGO_ENABLED=0 GOOS=linux go build -a -v -tags musl
Ok seems like this works:
# builder
FROM golang:1.14-alpine AS builder
RUN set -ex &&\
apk add --no-progress --no-cache \
gcc \
musl-dev
WORKDIR /go/src/app
COPY go.* ./
RUN go mod download
COPY . .
RUN go get -d -v
RUN GOOS=linux GOARCH=amd64 go build -a -v -tags musl
e.g. I think the key points:
CGO_ENABLED flagHi,
Got this issue too, added the -tags musl to fix it. So thank you!
But a question, now my Jenkins builds take twice the previous build time... Anything that could explain that?
To be honest, due to that I'm wondering if I'm not gonna stay with embedding librd on my own 馃槶
The go get download will take more time as the librdkafka blobs need to be downloaded, and static linking will be somewhat slower than dynamic, but not by much.
@edenhill I have 3 steps:
Whereas previously before the Confluent update and -tags musl (with everything else the same) I had:
The detailed commands are the following ones:
go mod tidygo mod vendorgo build -mod=vendor -i -tags musl -o build/main main.gogo test -mod=vendor -race -cover ./...go test -mod=vendor ./...The difference is quite significative 馃
That does seem odd, maybe you can pass -x to the build to get an idea what steps are taking longer with the static builds.
@edenhill , after multiple retries of building the same Git commit, I succeeded lowering build/coverage/test to 2m20s each approximatively (instead of 4 minutes each).
So it could come from the build servers... A bit weird but better to consider this than a big change with embedded Kafka lib.
Thank you for answering 馃憤 ,
After following @lifeofguenter I was able to build but not run the file.
FROM golang:1.14-alpine AS builder
RUN set -ex &&\
apk add --no-progress --no-cache \
gcc \
musl-dev
# Set necessary environmet variables needed for our image
ENV GO111MODULE=on \
# CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
# Move to working directory /build
WORKDIR /build
# Copy and download dependency using go mod
COPY go.mod .
COPY go.sum .
RUN go mod download
# Copy the code into the container
COPY . .
# Build the application
RUN go get -d -v
RUN go build -a -tags musl -o main myproject.go
# Move to /dist directory as the place for resulting binary folder
WORKDIR /dist
# Copy binary from build to main folder
RUN cp /build/main .
# Build a small image
FROM scratch
COPY --from=builder /dist/main /
# Command to run
ENTRYPOINT ["/main"]
I get the following error on running the file.
standard_init_linux.go:211: exec user process caused "no such file or directory"
Fixed by creating a static link
RUN go build -a -tags musl -installsuffix cgo -ldflags '-extldflags "-static"' -o main myproject.go
So I get the error mentioned in the description while running tests for my project via jenkins. (not sure if this is related)
/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xd46): undefined reference to `__strndup'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/[email protected]/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mcgrp_rebalance_timer_cb':
(.text+0x13dd): undefined reference to `__strndup'
Dockerfile
FROM golang:1.14-alpine AS test
WORKDIR /src
# Packages required for project build and test
RUN apk add --no-cache git make
RUN go get \
github.com/AlekSi/gocov-xml \
github.com/axw/gocov \
github.com/tebeka/go2xunit \
github.com/wadey/gocovmerge
COPY go.mod go.sum ./
RUN go mod download
# This layer is rebuilt when a file changes in the project directory
COPY . .
FROM test AS builder
ENV CGO_ENABLED=1
RUN set -ex &&\
apk add --no-progress --no-cache \
gcc \
musl-dev
WORKDIR /src
RUN go install -tags musl ./...
FROM alpine:3.12.0
COPY --from=builder /go/bin/push3 /bin/
USER nobody
ENTRYPOINT ["push3"]
Jenkins snippet
stage("Test") {
agent {
dockerfile {
label 'docker'
additionalBuildArgs '--target builder'
args '-v test:/src/test'
reuseNode true
}
}
steps {
//This is old parallel stages syntax. As of Declarative Pipeline 1.2 it changes
//Declarative Pipeline 1.2 docs https://jenkins.io/blog/2017/09/25/declarative-1/
parallel(
'Unit Test': {
sh "make ${makeArgs} test/unit-test"
},
Coverage: {
sh "make ${makeArgs} test/coverage"
},
Vet: {
sh "make ${makeArgs} test/vet"
}
)
}
post {
always {
junit 'test/*xml'
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'test', reportFiles: 'coverage.html', reportName: 'Code Coverage Report'])
sh "make ${makeArgs} clean"
}
}
}
Can't reproduce with vanilla docker image:
$ docker run -it golang:1.14-alpine /bin/sh
Unable to find image 'golang:1.14-alpine' locally
1.14-alpine: Pulling from library/golang
df20fa9351a1: Already exists
ed8968b2872e: Already exists
a92cc7c5fd73: Already exists
f17c8f1adafb: Pull complete
03954754c53a: Pull complete
Digest: sha256:e9f6373299678506eaa6e632d5a8d7978209c430aa96c785e5edcb1eebf4885e
Status: Downloaded newer image for golang:1.14-alpine
/go # apk add gcc musl-dev make git
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/18) Installing libgcc (9.3.0-r2)
(2/18) Installing libstdc++ (9.3.0-r2)
(3/18) Installing binutils (2.34-r1)
(4/18) Installing gmp (6.2.0-r0)
(5/18) Installing isl (0.18-r0)
(6/18) Installing libgomp (9.3.0-r2)
(7/18) Installing libatomic (9.3.0-r2)
(8/18) Installing libgphobos (9.3.0-r2)
(9/18) Installing mpfr4 (4.0.2-r4)
(10/18) Installing mpc1 (1.1.0-r1)
(11/18) Installing gcc (9.3.0-r2)
(12/18) Installing nghttp2-libs (1.41.0-r0)
(13/18) Installing libcurl (7.69.1-r0)
(14/18) Installing expat (2.2.9-r1)
(15/18) Installing pcre2 (10.35-r0)
(16/18) Installing git (2.26.2-r0)
(17/18) Installing make (4.3-r0)
(18/18) Installing musl-dev (1.1.24-r9)
Executing busybox-1.31.1-r16.trigger
OK: 157 MiB in 33 packages
/go # cd src/
/go/src # mkdir fo
/go/src # cd fo
/go/src/fo # cat > main.go
package main
import (
"github.com/confluentinc/confluent-kafka-go/kafka"
"fmt"
)
func main () {
_, vs := kafka.LibraryVersion()
fmt.Printf("Kafka version %s\n", vs)
}
/go/src/fo # go get -tags musl
/go/src/fo # go build -tags musl
/go/src/fo # ./fo
Kafka version 1.4.2
/go/src/fo # ldd fo
/lib/ld-musl-x86_64.so.1 (0x7f4f65cb7000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f4f65cb7000)
/go/src/fo #
So the build works. When I run tests on it is when I get the error. i.e on running go test ./... or go vet ./...
You might need -tags musl on those commands too.
I am facing the same issue, from the container I can run go build -a -tags musl and it works fine, but go test ./... -tags musl fails just as as @bulletblp4 ...
what I am missing ?
Most helpful comment
You might need
-tags muslon those commands too.