Does confD or its APIs support alpine

Hello Everyone,

to minimize docker image, i want to use alpine docker image as a base image. Also, it’s trend.
I write a docker file like this:

# Build Stage
FROM alpine as build-env
RUN apk add --no-cache build-base
WORKDIR /build
COPY . .
# Compile the binaries
RUN cc -c -o actions.o actions.c -Wall -g -Iinclude -DCONFD_C_PRODUCT_CONFD -DLinux
RUN cc -o actions actions.o lib/libconfd.a -lpthread -lm

# Run Stage
FROM alpine:latest
COPY --from=build-env /build/actions /run/app
WORKDIR /run
ENTRYPOINT ["/run/app"]

i got error like this:

(.text+0x2960): undefined reference to `__strncpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: lib/libconfd.a(confd_type.o): in function `str_to_ipv6':
(.text+0x2a90): undefined reference to `__strncpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: lib/libconfd.a(confd_type.o): in function `str_to_ipv4':
(.text+0x2b2d): undefined reference to `__strncpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: lib/libconfd.a(confd_type.o): in function `instance_id_val_to_str':
(.text+0x4592): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: lib/libconfd.a(confd_type.o): in function `xpath_to_hkpath':
(.text+0x4965): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0x4b0c): undefined reference to `__strdup'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0x5250): undefined reference to `__strdup'
collect2: error: ld returned 1 exit status
The command '/bin/sh -c cc -o actions actions.o lib/libconfd.a -lpthread -lm' returned a non-zero code: 1

I guess, i need to have libconfd.a which is compiled with musl, right?
Is there a lib like that, or i can build libconfd.a from scratch for alpine.

Many Thanks,
With My Best Regards,

Hi,

You need to rebuild the ConfD C API if you are going to use it with an application that builds with musl.
To do a native rebuild libconfd with Alpine Linux musl you can do something like:

$ ./confd-$CONFD_VERSION.linux.x86_64.installer.bin --force confd-$CONFD_VERSION
$ apk --no-cache add gcc make libc-dev openssl-dev
$ tar xvfz confd-$CONFD_VERSION.libconfd.tar.gz
$ cd confd-$CONFD_VERSION/libconfd
$ make install_crypto && make install

To run ConfD with Alpine you need libc instead of musl. It is possible to get an Alpine libc variant, but it is not the standard option. But at least you can build the libconfd API with musl for use with your application on Alpine.

Hello cohul,

This is a good news, i didin’t think like that. Confd creates lib during the installation ?
i’ll try this. Btw, what do you mean while you’re sayin “it’s not standart option”, it coudln’t be used in production ?
it has a consequences which are unpredictable?

Last but not least, should i force CONFD_VERSION, even i want to use latest version ?
Many Thanks,
With My Best Regards,

ConfD comes with the libconfd C-API, the Python API and Java API prebuilt for a generic, here x86_64, hardware platform and a LInux that has libc support. Hence you need to rebuild the libconfd C-API if you are going to use it with Alpine musl.

I am just saying that you need to add libc to Alpine with your own Alpine build or use something like this one Docker

Hello @cohult

I am just saying that you need to add libc to Alpine with your own Alpine build or use something like this one Docker

Ok, i guess, there is no risk to use alpine with glibc.

Many Thanks,
I will try this.

However, if i use java api , there is no need to rebuild API, right?

Right. The Java API does not need to be rebuilt.

Right. The Java API does not need to be rebuilt.

good, thank you so much Mr. @cohult.

I’ll try and if i got error or realize a changes, I’ll inform

Many thanks,
With My Best Regards.

Hello @cohult

It worked.
Just a update. i changed the installation script in makefile.
i added “/” char at the end of the following line.
cp src/$(XHOST)/libconfd.a $(CONFD_DIR)/lib
cp src/$(XHOST)/libconfd.so $(CONFD_DIR)/lib

1 Like

Hello @cohult

Before this, i build libconfd for alpine and i build confd client application, and i can succesfully execute confd client application (such actions) in alpine.

Nowadays, i’m trying to build confd in alpine. i successfully build but confd cannot be succesffuly executed in alpine.
i got an error like this:

/confd/bin/confd: exec: line 640: /confd/lib/confd/erts/bin/confdexec: not found

Here is the my docker file:

FROM alpine:latest AS Builder

ENV CONFD_VERSION=basic-7.5.1
ENV CONFD_INSTALL_DIR=/confd
RUN apk --no-cache add --update \
    libressl-dev \
    wget unzip openssh-client \
    gcc make libc-dev openssl-dev \
    linux-headers

WORKDIR /build/confd

ADD resource/confd-basic-7.5.1.linux.x86_64.zip ./
RUN unzip confd-basic-7.5.1.linux.x86_64.zip; ./confd-basic-7.5.1.linux.x86_64/confd-basic-7.5.1.linux.x86_64.installer.bin $CONFD_INSTALL_DIR; \
        tar xvfz ./confd-basic-7.5.1.linux.x86_64/confd-$CONFD_VERSION.libconfd.tar.gz; cd confd-$CONFD_VERSION/libconfd; make CONFD_DIR=$CONFD_INSTALL_DIR install && make CONFD_DIR=$CONFD_INSTALL_DIR install_crypto; \
        cd /; rm -rf $CONFD_INSTALL_DIR/doc $CONFD_INSTALL_DIR/examples.confd $CONFD_INSTALL_DIR/man $CONFD_INSTALL_DIR/src /build/confd;

FROM alpine:latest AS Runner
COPY --from=Builder /confd /confd

ENV CONFD_DIR=/confd
ENV LD_LIBRARY_PATH=$CONFD_DIR/lib
ENV PATH=$CONFD_DIR/bin:$PATH
ENV CDB_DIR=${CONFD_DIR}/var/confd/cdb

RUN echo "ls -la -R /confd"; ls -la -R /confd;

EXPOSE 2022
EXPOSE 2023
EXPOSE 2024
EXPOSE 4565
EXPOSE 8008
EXPOSE 8088

# Start init daemon and ConfD
ENTRYPOINT ["confd"]
CMD ["--addloadpath", "/confd/etc/confd", "--foreground", "--verbose"]

I guess, “/confd/bin/confd: exec: line 640: /confd/lib/confd/erts/bin/confdexec: not found” coudn’t be compiled for alpine?

Many thanks,
With My Best Regards

Hi,

As mentioned earlier in this thread:

You can also try and follow the recipe from here:

That demo seems to be a bit old as it states that you must use Alpine 3.8. As ConfD supports libconfd 1.1 nowadays, you can likely use the latest Alpine version.

Hello @cohult

Ooohhh sorry, it’s my mistake, i missed it. Right, for fast experience, i tried /frolvlad/alpine-glibc, it works.

I don’t know the confd backend and its dependencies, but can you explain a little bit more “why i need this, why libc-dev alpine pkg doesn’t work, if i can build everything of confd from scratch, i’l still need to use frolvlad/alpine-glibc image or libc-dev pkg. will be enough ? and so on”.

because i build libconfd from scratch in alpine and i build client application (such as action example) from scratch in alpine, and they work. but confd doesn’t work.
alpine-glibc image makes emulation or translation ?
Do you have suggestion or attention to use alpine-glibc image? Is it safe ?

Many Thanks Again,
Have a nice and healty day,
WIth My Best Regards,