-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static binary on Alpine – cannot find -lsasl2 #151
Comments
Maybe alpine does not provided static builds of libsdasl2? If you can find a package that does you might also need to link the Go application with some additional linker flags, see here: As for disabling libsasl support when building librdkafka, there is a bug that prevents --disable-sasl to disable it, which will be fixed after the next release. |
Well, sorry for jumping the gun on this issue. I've actually managed to solve the second question by sifting through the librdkafka repository, and using After that the build went fine, and it looks like the binary is now statically linked:
The problem obviously still remains, but it's less of an issue for me right now. I'll see if I can get it to work with SASL support on Alpine and report back when I do, until then, I'll close this issue. edit: was posting while you responded @edenhill, thank you for the pointers, appreciated 👍. |
This is useful for many people, would you mind blogging a small tutorial or outlining it here? |
I can at least put the # First build phase (of two), this part uses Alpine to install all required
# dependencies required to build a project that requires librdkafka. It will
# then build a static binary that can be used in a smaller "scratch" image.
FROM golang:1.10-alpine
# The default librdkafka version is the latest stable release on GitHub. You can
# use the `--build-arg` argument for `docker build` to specify a different
# version to be installed.
#
# e.g.: docker build --build-arg LIBRDKAFKA_VERSION=4e7a46701ecce7297b2298885da980be7856e5f9
#
ARG LIBRDKAFKA_VERSION=v0.11.3
# Set the workdir to the full GOPATH of your project.
WORKDIR $GOPATH/src/PATH/TO/PROJECT
# Install all dependencies required to build the project as a static binary.
RUN apk add -U \
bash \
build-base \
coreutils \
curl \
cyrus-sasl-dev \
git \
libevent \
libressl2.6-libcrypto \
libressl2.6-libssl \
libsasl \
lz4-dev \
openssh \
openssl \
openssl-dev \
python \
yajl-dev \
zlib-dev
# Install `dep`, the official Golang package manager to install dependencies.
RUN apk add -U -X http://nl.alpinelinux.org/alpine/edge/testing dep
# SASL support is disabled for now, due to issues when compiling a static
# binary. See: https://git.io/vAFFm
RUN cd $(mktemp -d) \
&& curl -sL "https://github.com/edenhill/librdkafka/archive/$LIBRDKAFKA_VERSION.tar.gz" | \
tar -xz --strip-components=1 -f - \
&& ./configure --disable-sasl \
&& make -j \
&& make install
# Copy the entire project tree into the container, so we can build the binary.
COPY . .
# Install any defined project dependencies using `dep`.
RUN dep ensure -vendor-only
# Build a completely static binary, able to be used in a `scratch` container.
RUN go build -o /tmp/run -tags static_all
# Second build phase, copy the generated binary from the first build phase into
# a "scratch" image, and set the entrypoint to run the binary.
FROM scratch
ENTRYPOINT ["/run"]
COPY --from=0 /tmp/run . I then build the image as follows: $ docker build \
--build-arg LIBRDKAFKA_VERSION=4e7a46701ecce7297b2298885da980be7856e5f9 \
--tag static-test . It succeeds, and I can see the relatively small container size as a result: $ docker images | grep static-test
static-test, latest, 8cd387b3607e, About a minute ago, 33.4MB And finally, I can run it as expected: $ docker run static-test
hello world! |
https://pkgs.alpinelinux.org/package/v3.7/main/x86_64/cyrus-sasl-dev It would appear it doesn't bundle the static version as noted previously. My problem is I do need SASL in librdkafka. I tried building cyrus-sasl-dev to get my own static library built but then I run into all manner of conflicts between libressl and openssl. I still haven't resolved the issue :( [edit] Docker multi-step builds appeared to sort me. I defined a build step just for the Cyrus SASL library (as a static build) and on the next step used COPY --from=previous-step the libsasl2.a (and all the plugin .a files) into the correct place. Seems to work but was a faff to say the least. |
libsasl2 is tricky with all its dynamic library plugins, I have not yet been able to create proper static builds with libsasl2. With docker you don't really need static builds since you can include whatever dynamic libraries dependencies you have. |
FYI, Alpine now provides a static library for libsasl2. |
cyrus-sasl-dev indeed includes the statically linked libraries.
and while
i got the same result with a stretch image, as well as alpine. |
I don't think there is a current solution to linking libsasl2 statically, it depends on runtime loaded plugins which require dynamic linking. (Yes, it is a mess from our perspective) |
yeah i figured it was something like that. thanks for the confirmation! |
The plugins are being compiled into the static libsasl2. The problem is that some plugins depend on libraries (e.g. Berkeley db, Kerberos 5) that are not available as static libraries in Alpine. If you don't need those plugins, then you can compile the SASL library statically without them, then compile librdkafka, then compile your Go program. I only have need for SCRAM support in SASL, so this worked for me to create an imagine that can then be used to compile the Go program: FROM golang:1.12.0-alpine3.9
RUN apk add --no-cache \
bash \
build-base \
coreutils \
gcc \
git \
make \
musl-dev \
openssl-dev \
rpm \
lz4-dev \
zlib-dev \
wget && \
#
# Build Cyrus SASL from source.
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 && \
#
# Build librdkafka from source.
cd $(mktemp -d) && \
wget -nv -O v0.11.6.tar.gz https://github.com/edenhill/librdkafka/archive/v0.11.6.tar.gz && \
tar -xz --strip-components=1 -f v0.11.6.tar.gz && \
rm -f v0.11.6.tar.gz && \
./configure --prefix=/usr --enable-sasl && \
make -j && \
make install After that you can use |
Thanks for the instructions @eliaslevy ! |
Doh! 🤦♂️ I was not aware of that. Oh well, duly noted. |
Do we have any updates on getting librdkafka to work with gssapi (kerberos authentication) inside alpine? |
@PanagiotisFytas It should work as long as librdkafka (and libsasl2) are linked dynamically and not statically. |
I have an issue with the kerberos authentication of the librdkafka from an alpine docker. Thought that it was an issue with the libraries, maybe I am wrong though. I should start another thread on librdkafka |
I'm trying to create a static binary on Alpine, but can't figure out how to solve the problem of a missing sasl2 library.
Here's a list of packages that I install on Alpine:
I also built librdkafka from source using HEAD (the build output showed support for sasl was found, and enabled).
go build -tags static main.go
works as expected:You can see the pointer to
/usr/lib/libsasl2.so.3
.But
go build -tags static_all main.go
won't work:Here's the full `go build -x -tags static_all main.go` output
And here's the output of `find / -name *sasl*`
Two questions:
The text was updated successfully, but these errors were encountered: