Skip to content

Commit

Permalink
Upgrade essentia, use dynamic linking only (#10383)
Browse files Browse the repository at this point in the history
Co-authored-by: endline <endline>
  • Loading branch information
endline authored Nov 7, 2024
1 parent 4b742b3 commit 0a8a593
Showing 1 changed file with 21 additions and 44 deletions.
65 changes: 21 additions & 44 deletions cmd/mediorum/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,100 +26,77 @@ RUN apt-get update && apt-get install -y \
libopus-dev \
libvorbis-dev \
libogg-dev \
libflac-dev
libflac-dev \
pkg-config

ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig"
ENV LD_LIBRARY_PATH="/usr/local/lib:/usr/lib"
ENV LD_LIBRARY_PATH="/usr/local/lib"

# build and install libKeyFinder (static)
RUN git clone https://github.com/mixxxdj/libKeyFinder.git /libKeyFinder && \
cd /libKeyFinder && \
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF -S . -B build && \
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -S . -B build && \
cmake --build build --parallel $(nproc) && \
cmake --install build

# build and install Essentia (static)
RUN git clone https://github.com/MTG/essentia.git /essentia && \
# essentia release tags are very old - pin to a more recent commit
ENV ESSENTIA_COMMIT="eaf8ddfd9a603fdda9850731cc39f06e6262afe5"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig"
RUN git clone --depth 1 https://github.com/MTG/essentia.git /essentia && \
cd /essentia && \
git checkout v2.1_beta5 && \
python3 waf configure --build-static --no-msse --pkg-config-path=$PKG_CONFIG_PATH && \
git fetch --depth 1 origin $ESSENTIA_COMMIT && \
git checkout $ESSENTIA_COMMIT && \
python3 waf configure --pkg-config-path=$PKG_CONFIG_PATH && \
python3 waf && \
python3 waf install

# build and install libtag (static)
RUN git clone https://github.com/taglib/taglib.git /taglib && \
cd /taglib && \
git submodule update --init && \
cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local -S . -B build && \
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/local -S . -B build && \
cmake --build build --parallel $(nproc) && \
cmake --install build

# build and install libchromaprint (static)
RUN git clone https://github.com/acoustid/chromaprint.git /chromaprint && \
cd /chromaprint && \
cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local -S . -B build && \
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/local -S . -B build && \
cmake --build build --parallel $(nproc) && \
cmake --install build

WORKDIR /app
COPY ./cmd/mediorum/cpp ./cpp

# build analyze-key cpp (static and dynamic linking)
RUN g++ -o /bin/analyze-key /app/cpp/keyfinder.cpp \
-I/usr/local/include -L/usr/local/lib \
-Wl,-Bstatic -lkeyfinder -lsndfile -lfftw3 -lfftw3f \
-Wl,-Bdynamic -lopus -lFLAC -lvorbis -lvorbisenc -logg -lpthread -lz && \
-lkeyfinder -lsndfile -lfftw3 -lfftw3f -lopus -lFLAC -lvorbis -lvorbisenc -logg -lpthread -lz && \
chmod +x /bin/analyze-key

# build analyze-bpm cpp (static and dynamic linking)
RUN g++ -o /bin/analyze-bpm /app/cpp/bpm-analyzer.cpp \
-I/usr/include/eigen3 -I/usr/local/include/essentia -I/usr/local/include \
-L/usr/local/lib \
-Wl,-Bstatic -lessentia -ltag -lyaml -lfftw3 -lfftw3f \
-Wl,-Bdynamic -lavcodec -lavformat -lavutil -lavfilter -lsamplerate -lavresample -lpthread -lz -lchromaprint && \
-lessentia -ltag -lyaml -lfftw3 -lfftw3f -lavcodec -lavformat -lavutil -lavfilter -lsamplerate -lavresample -lpthread -lz -lchromaprint && \
chmod +x /bin/analyze-bpm

FROM golang:1.22-bullseye AS go-builder

RUN apt-get update && apt-get install -y \
build-essential \
make \
ffmpeg \
libmp3lame-dev

WORKDIR /app

ENV CGO_ENABLED=0

COPY go.mod go.sum ./
RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get

COPY ./pkg ./pkg
COPY ./cmd/mediorum ./cmd/mediorum

RUN go build -o mediorum cmd/mediorum/main.go
RUN go build -o mediorum-cmd pkg/mediorum/cmd/main.go
RUN go build -o /bin/mediorum cmd/mediorum/main.go
RUN go build -o /bin/mediorum-cmd pkg/mediorum/cmd/main.go

FROM cpp-builder

FROM debian:bullseye-slim as final

# some libs still required for dynamic links
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
ffmpeg \
libsamplerate0 \
zlib1g \
&& rm -rf /var/lib/apt/lists/*

COPY --from=cpp-builder /bin/analyze-key /bin/analyze-bpm /bin/
COPY --from=go-builder /app/mediorum /bin/mediorum
COPY --from=go-builder /app/mediorum-cmd /bin/mediorum-cmd
COPY --from=go-builder /bin/mediorum /bin/mediorum
COPY --from=go-builder /bin/mediorum-cmd /bin/mediorum-cmd

ARG git_sha
ENV GIT_SHA=$git_sha

VOLUME ["/mediorum_data"]
EXPOSE 1991

ENTRYPOINT ["mediorum"]
ENTRYPOINT ["/bin/mediorum"]

0 comments on commit 0a8a593

Please sign in to comment.