generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
It is somewhat difficult to build and run bpftune in a containerized environment.
Below is my first attempt, if it's of any help to others, though it is quite flawed.
# syntax=docker/dockerfile:1
FROM alpine:3.21 AS builder
RUN echo "http://dl-cdn.alpinelinux.org/alpine/v3.21/main" > /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/v3.21/community" >> /etc/apk/repositories
RUN apk update
RUN apk add libbpf-dev libcap-dev linux-tools linux-headers libnl3-dev clang llvm git binutils-dev
RUN apk add make bpftool gcompat coreutils py3-docutils musl-utils
## bpftune build
RUN git clone https://github.com/oracle/bpftune.git /bpftune
WORKDIR /bpftune
RUN git checkout b0f6187c6d0b9993f5c14d47831b18511dfcf388
# Patch for musl
COPY ./bpftune-0001-sigval.patch .
RUN git apply bpftune-0001-sigval.patch
RUN mkdir out && make -j16 && make srcinstall DESTDIR=/bpftune/out
## actual image
FROM alpine:3.21 AS base
COPY --from=builder /bpftune/out /bpftune
COPY ./bpftune.sh /bpftune/bpftune.sh
RUN chmod +x /bpftune/bpftune.sh
RUN echo "http://dl-cdn.alpinelinux.org/alpine/v3.21/main" > /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/v3.21/community" >> /etc/apk/repositories
RUN apk update
RUN apk add bash
CMD /bin/bash -c "mount -t debugfs none /sys/kernel/debug && /bin/bash"
The musl patch is as follows:
diff --git a/src/Makefile b/src/Makefile
index cdb7f65..ed24ed5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -124,7 +124,7 @@ $(OPATH):
mkdir $(OPATH)
analyze: $(BPF_SKELS) $(LEGACY_BPF_SKELS) $(NOBTF_BPF_SKELS)
- $(CLANG) --analyze $(INCLUDES) libbpftune.c bpftune.c $(TUNER_SRCS)
+ $(CLANG) --analyze $(INCLUDES) -Wno-incompatible-pointer-types libbpftune.c bpftune.c $(TUNER_SRCS)
clean:
$(call QUIET_CLEAN, bpftune)
$(Q)$(RM) $(OPATH)*.o *.d $(OPATH)*.so*
diff --git a/src/libbpftune.c b/src/libbpftune.c
index f4bec2f..3c0c28e 100644
--- a/src/libbpftune.c
+++ b/src/libbpftune.c
@@ -50,6 +50,13 @@
#include <time.h>
#include <pthread.h>
+#ifdef __MUSL__
+typedef union {
+ int sival_int;
+ void *sival_ptr;
+} sigval_t;
+#endif
+
unsigned short bpftune_learning_rate;
#include <bpftune/libbpftune.h>
@@ -1838,7 +1845,7 @@ static void bpftuner_strategy_update(struct bpftuner *tuner)
bpftuner_strategy_set(tuner, max_strategy);
}
-static void bpftuner_strategy_timeout(sigval_t sigval)
+static void bpftuner_strategy_timeout(union sigval sigval)
{
struct bpftuner *tuner = sigval.sival_ptr;
@@ -2092,7 +2099,7 @@ void *bpftune_server_thread(void *arg)
if (port == 0) {
len = sizeof(saddr);
- if (!getsockname(fd, &saddr, &len))
+ if (!getsockname(fd, (struct sockaddr *)&saddr, &len))
port = ntohs(saddr.sin_port);
}
if (port != 0) {
@@ -2113,7 +2120,7 @@ void *bpftune_server_thread(void *arg)
char buf[BPFTUNE_SERVER_MSG_MAX];
char req[80];
struct sockaddr_in caddr;
- int cfd = accept(fd, (struct sockaddr_in *)&caddr, &len);
+ int cfd = accept(fd, (struct sockaddr *)&caddr, &len);
unsigned long i;
if (cfd < 0) {
bpftune.sh:
#!/bin/bash
LD_LIBRARY_PATH=/bpftune/usr/lib:/bpftune/usr/lib64:$LD_LIBRARY_PATH exec /bpftune/usr/sbin/bpftune $@
Even after all this effort, bpftune still expects /usr/lib64/bpftune to exist so you have to symlink /bpftune/usr/lib64/bpftune there yourself.
All this is to say, I'd really appreciate an official image :)
Metadata
Metadata
Assignees
Labels
No labels