mirror of
https://github.com/navidrome/navidrome.git
synced 2026-06-19 07:37:15 +00:00
c466f6b612
* fix(artwork): avoid WebP segfault on 32-bit ARM On 32-bit ARM, the gen2brain/webp native libwebp path uses ebitengine/purego reverse callbacks, which purego does not support on that architecture. Selecting it crashes the process with a SIGSEGV when encoding or decoding WebP cover art, taking down the whole server on the first web UI artwork request (issue #5597). Force the safe WASM path on armv7/v6 in two layers: build the Docker arm binary with the gen2brain/webp "nodynamic" tag so purego is never linked, and add a runtime GOARCH guard in the init hook so source builds on 32-bit ARM are also protected. arm64 keeps the native libwebp path. * fix(artwork): also disable native WebP on 32-bit x86 purego's callback implementation is built with the constraint !386 && !arm, so 32-bit x86 (386) crashes with the same SIGSEGV as 32-bit ARM when the native libwebp path is used. Navidrome ships linux/386 and windows/386 builds, so guard 386 alongside arm: extend the runtime GOARCH check and the Docker nodynamic build tag to cover both. 64-bit arches keep the native libwebp path. * fix(artwork): rely on nodynamic build tag, drop ineffective runtime guard The previous runtime GOARCH guard did not actually prevent the crash: gen2brain/webp selects the native (purego) vs WASM backend in its own package init() and registers the purego write callback at import time, before any Navidrome hook runs. webp.Dynamic() is only a status getter, and Decode/Encode branch on the library's unexported flag, so the guard merely skipped a log line while the native path stayed active. The effective fix is the nodynamic build tag (applied for 32-bit ARM and x86 in the Dockerfile), which compiles gen2brain/webp WASM-only so purego is never linked. Drop the misleading guard and document that source builds on 32-bit architectures must be built with -tags nodynamic. * fix(artwork): don't enable WebP encoding by default in Docker The Docker image set ND_ENABLEWEBPENCODING=true, which (a) forced cover-art thumbnails through WebP for every install and (b) overrode any EnableWebPEncoding=false set in the user's navidrome.toml, since env vars take precedence over the config file in Viper. On 32-bit platforms the only available WebP backend is the WASM encoder, which is slow on the underpowered hardware those builds typically run on, so enabling it by default is the wrong tradeoff there. Remove the env default and leave EnableWebPEncoding off unless the user opts in. Combined with the nodynamic build tag, 32-bit images neither crash nor pay the WASM cost out of the box. A smarter automatic policy (use WebP only when native libwebp is available) can be revisited separately.
178 lines
6.2 KiB
Docker
178 lines
6.2 KiB
Docker
FROM --platform=$BUILDPLATFORM ghcr.io/crazy-max/osxcross:14.5-debian AS osxcross
|
|
|
|
########################################################################################################################
|
|
### Build xx (original image: tonistiigi/xx)
|
|
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/alpine:3.20 AS xx-build
|
|
|
|
# v1.9.0
|
|
ENV XX_VERSION=a5592eab7a57895e8d385394ff12241bc65ecd50
|
|
|
|
RUN apk add -U --no-cache git
|
|
RUN git clone https://github.com/tonistiigi/xx && \
|
|
cd xx && \
|
|
git checkout ${XX_VERSION} && \
|
|
mkdir -p /out && \
|
|
cp src/xx-* /out/
|
|
|
|
RUN cd /out && \
|
|
ln -s xx-cc /out/xx-clang && \
|
|
ln -s xx-cc /out/xx-clang++ && \
|
|
ln -s xx-cc /out/xx-c++ && \
|
|
ln -s xx-apt /out/xx-apt-get
|
|
|
|
# xx mimics the original tonistiigi/xx image
|
|
FROM scratch AS xx
|
|
COPY --from=xx-build /out/ /usr/bin/
|
|
|
|
########################################################################################################################
|
|
### Build Navidrome UI
|
|
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/node:lts-alpine AS ui
|
|
WORKDIR /app
|
|
|
|
# Install node dependencies
|
|
COPY ui/package.json ui/package-lock.json ./
|
|
COPY ui/bin/ ./bin/
|
|
RUN npm ci
|
|
|
|
# Build bundle
|
|
COPY ui/ ./
|
|
RUN npm run build -- --outDir=/build
|
|
|
|
FROM scratch AS ui-bundle
|
|
COPY --from=ui /build /build
|
|
|
|
########################################################################################################################
|
|
### Build Navidrome binary for Docker image (dynamic musl, enables native libwebp via dlopen)
|
|
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/golang:1.26-alpine AS build-alpine
|
|
COPY --from=xx / /
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
RUN apk add --no-cache clang lld file git
|
|
RUN xx-apk add --no-cache gcc musl-dev zlib-dev
|
|
RUN xx-verify --setup
|
|
|
|
WORKDIR /workspace
|
|
|
|
RUN --mount=type=bind,source=. \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
go mod download
|
|
|
|
ARG GIT_SHA
|
|
ARG GIT_TAG
|
|
|
|
RUN --mount=type=bind,source=. \
|
|
--mount=from=ui,source=/build,target=./ui/build,ro \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod <<EOT
|
|
set -e
|
|
xx-go --wrap
|
|
export CGO_ENABLED=1
|
|
# Native libwebp (gen2brain/webp) uses ebitengine/purego reverse callbacks,
|
|
# which purego does not support on 32-bit ARM or x86 and crash with a SIGSEGV
|
|
# (issue #5597). Build those arches with the "nodynamic" tag so gen2brain/webp
|
|
# is WASM-only and never links the purego path. 64-bit arches keep native libwebp.
|
|
BUILD_TAGS=netgo,sqlite_fts5
|
|
if [ "$(xx-info arch)" = "arm" ] || [ "$(xx-info arch)" = "386" ]; then
|
|
BUILD_TAGS=${BUILD_TAGS},nodynamic
|
|
fi
|
|
# -latomic is required on 32-bit arm (arm/v6, arm/v7) so SQLite's 64-bit atomics resolve.
|
|
go build -tags=${BUILD_TAGS} -ldflags="-w -s \
|
|
-linkmode=external -extldflags '-latomic' \
|
|
-X github.com/navidrome/navidrome/consts.gitSha=${GIT_SHA} \
|
|
-X github.com/navidrome/navidrome/consts.gitTag=${GIT_TAG}" \
|
|
-o /out/navidrome .
|
|
# Fail the build if the binary is accidentally statically linked: dlopen (and
|
|
# therefore native libwebp detection) only works with a dynamic interpreter.
|
|
file /out/navidrome | grep -q "dynamically linked" || { echo "ERROR: /out/navidrome is not dynamically linked"; file /out/navidrome; exit 1; }
|
|
EOT
|
|
|
|
########################################################################################################################
|
|
### Build Navidrome binary for standalone distribution (static glibc, cross-compiled)
|
|
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/golang:1.26-trixie AS base
|
|
RUN apt-get update && apt-get install -y clang lld
|
|
COPY --from=xx / /
|
|
WORKDIR /workspace
|
|
|
|
FROM --platform=$BUILDPLATFORM base AS build
|
|
|
|
# Install build dependencies for the target platform
|
|
ARG TARGETPLATFORM
|
|
|
|
RUN xx-apt install -y binutils gcc g++ libc6-dev zlib1g-dev
|
|
RUN xx-verify --setup
|
|
|
|
RUN --mount=type=bind,source=. \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
go mod download
|
|
|
|
ARG GIT_SHA
|
|
ARG GIT_TAG
|
|
|
|
RUN --mount=type=bind,source=. \
|
|
--mount=from=ui,source=/build,target=./ui/build,ro \
|
|
--mount=from=osxcross,src=/osxcross/SDK,target=/xx-sdk,ro \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod <<EOT
|
|
|
|
# Setup CGO cross-compilation environment
|
|
xx-go --wrap
|
|
export CGO_ENABLED=1
|
|
cat $(go env GOENV)
|
|
|
|
# Only Darwin (macOS) requires clang (default), Windows requires gcc, everything else can use any compiler.
|
|
# So let's use gcc for everything except Darwin.
|
|
if [ "$(xx-info os)" != "darwin" ]; then
|
|
export CC=$(xx-info)-gcc
|
|
export CXX=$(xx-info)-g++
|
|
export LD_EXTRA="-extldflags '-static -latomic'"
|
|
fi
|
|
if [ "$(xx-info os)" = "windows" ]; then
|
|
export EXT=".exe"
|
|
fi
|
|
|
|
go build -tags=netgo,sqlite_fts5 -ldflags="${LD_EXTRA} -w -s \
|
|
-X github.com/navidrome/navidrome/consts.gitSha=${GIT_SHA} \
|
|
-X github.com/navidrome/navidrome/consts.gitTag=${GIT_TAG}" \
|
|
-o /out/navidrome${EXT} .
|
|
EOT
|
|
|
|
# Verify if the binary was built for the correct platform and it is statically linked
|
|
RUN xx-verify --static /out/navidrome*
|
|
|
|
FROM scratch AS binary
|
|
COPY --from=build /out /
|
|
|
|
########################################################################################################################
|
|
### Build Final Image
|
|
FROM public.ecr.aws/docker/library/alpine:3.20 AS final
|
|
LABEL maintainer="deluan@navidrome.org"
|
|
LABEL org.opencontainers.image.source="https://github.com/navidrome/navidrome"
|
|
|
|
# Install runtime dependencies
|
|
# - libwebp + symlinks: enables native WebP encoding via purego/dlopen
|
|
RUN apk add -U --no-cache ffmpeg mpv sqlite libwebp libwebpdemux libwebpmux && \
|
|
for lib in libwebp libwebpdemux libwebpmux; do \
|
|
target=$(ls /usr/lib/$lib.so.* 2>/dev/null | head -1) && \
|
|
[ -n "$target" ] && ln -sf "$target" /usr/lib/$lib.so; \
|
|
done
|
|
|
|
# Copy navidrome binary (musl build for Docker, enables native libwebp)
|
|
COPY --from=build-alpine /out/navidrome /app/
|
|
|
|
VOLUME ["/data", "/music"]
|
|
ENV ND_MUSICFOLDER=/music
|
|
ENV ND_DATAFOLDER=/data
|
|
ENV ND_CONFIGFILE=/data/navidrome.toml
|
|
ENV ND_PORT=4533
|
|
RUN touch /.nddockerenv
|
|
|
|
EXPOSE ${ND_PORT}
|
|
WORKDIR /app
|
|
ENV PATH="/app:${PATH}"
|
|
|
|
ENTRYPOINT ["/app/navidrome"]
|
|
|