Hi all
Please see attached. if I compile my code directly on system, it works, when I compile/build into a docker images I get errors as per the attached.
Anyone seen this, I’m also attaching my docker file.
G
Dockerfile
FROM golang:alpine as build-env
RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev
WORKDIR /scrubber
COPY . .
RUN go build -o scrubber .
CMD ./scrubber
Err.log → Output from above build.
Sending build context to Docker daemon 41.54MB
Step 1/6 : FROM golang:alpine as build-env
---> 14ee78639386
Step 2/6 : RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev
---> Using cache
---> 159487736117
Step 3/6 : WORKDIR /scrubber
---> Using cache
---> 04f9d5590771
Step 4/6 : COPY . .
---> Using cache
---> 313c9ab381f8
Step 5/6 : RUN go build -o scrubber .
---> Running in 19c14cb0cbd2
e[91m# github.com/confluentinc/confluent-kafka-go/kafka
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: vendor/github.com/confluentinc/confluent-kafka-go/kafka/librdkafka_vendor/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_fatal_error':
(.text+0x149): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: vendor/github.com/confluentinc/confluent-kafka-go/kafka/librdkafka_vendor/librdkafka_glibc_linux.a(rdkafka_txnmgr.o): in function `rd_kafka_txn_set_abortable_error':
(.text+0x683): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: vendor/github.com/confluentinc/confluent-kafka-go/kafka/librdkafka_vendor/librdkafka_glibc_linux.a(rdkafka_admin.o): in function `rd_kafka_NewTopic_new':
and this above message is repeated probably 50+ times
update,
I’ve added “librdkafka-dev pkgconf” to the docker file as modules to pull in, still getting same errors.
G
rick
16 April 2021 11:58
3
@georgelza maybe this GH issue has some clues to your compilation issue?
opened 09:58PM - 10 Apr 20 UTC
closed 10:30AM - 19 Apr 20 UTC
Description
===========
When using the 1.4.0 release, the bundled _librdkafk… a_ fails to work as intended with the latest alpine.
How to reproduce
================
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/confluent-kafka-go@v1.4.0/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/confluent-kafka-go@v1.4.0/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?
Checklist
=========
Please provide the following information:
- [x] confluent-kafka-go and librdkafka version (`LibraryVersion()`): 1.4.0, bundled.
- [ ] Apache Kafka broker version: N/A
- [ ] Client configuration: N/A
- [x] Operating system: Alpine Linux
- [ ] Provide client logs (with `"debug": ".."` as necessary): N/A
- [ ] Provide broker log excerpts: N/A
- [ ] Critical issue: No
so being the noob at this. where do I add the “-tags dynamic” tags.
looking at some dogs it implies with the go build command, but with us doing a docker build, using a docker file, i never issue a go build command.
G
rick
16 April 2021 15:14
5
I think next I might try the golang docs, in particular the Docker information. Maybe start here?
https://hub.docker.com/_/golang
don’t think this is golang related, this is more docker and have feeling the combination of docker/golang and kafka.
surely someone else have deployed a go app accessing CP Kafka in K8s. be keen to see their docker file.
G
… let me add, my other client → receiving app is also golang and inside docker.
App 1, read text file, do some logic, drop onto Kafka topic.
App 2, consume topic (This app that I have problem with) more logic, and then send via gRPC to App 3, some more logic and then into a unstructured DB ( This app in docker works)
App 2, if just direct compiled/executed, it works, when attempting to build into docker image then have these problems.
G
checking, but looks like i got it build.
changed
RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev
to
RUN apk update && apk add bash ca-certificates git gcc g++ libc-dev librdkafka-dev pkgconf
change
RUN go build -o scrubber .
to
RUN go build -tags musl -o scrubber .
G
2 Likes
God you saved my life georgelza. Thank you so much!
1 Like
I took this a bit further, since Go requires disk space, and created multistage.Dockerfile
# syntax=docker/dockerfile:1
## Build
FROM golang:1.19.3-alpine AS build
RUN apk update && apk add gcc g++ libc-dev librdkafka-dev pkgconf
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN go build -tags musl -o myapp .
## Deploy
FROM alpine:latest
RUN apk update && apk add gcc g++ libc-dev librdkafka-dev pkgconf
COPY --from=build /app/myapp /
ENTRYPOINT ["/myapp"]
Image size ~250Mb + “myapp” size.
Open question: is it possible to avoid loading gcc, g++, etc in Deploy section of multistage Dockerfile?
1 Like
Thank you all, you saved me a lot of time)
1 Like
Also note there are other go native libraries like franz and (now deprecated) sarama.