Skip to content
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

Switch base image to Alpine #1629

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 25 additions & 77 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,98 +1,45 @@
# syntax=docker/dockerfile:1
ARG TARGETPLATFORM
ARG PYTHON_VERSION="3.12"

#####################################################################
# #
# Build Wheels #
# #
#####################################################################
FROM python:${PYTHON_VERSION}-slim as wheels-builder
ARG TARGETPLATFORM
FROM python:3.12-alpine3.20

# Install buildtime packages
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libffi-dev \
cargo \
git \
curl

WORKDIR /wheels
COPY requirements_all.txt .


# build python wheels for all dependencies
RUN set -x \
&& pip install --upgrade pip \
&& pip install build maturin \
&& pip wheel -r requirements_all.txt


#####################################################################
# #
# Final Image #
# #
#####################################################################
FROM python:${PYTHON_VERSION}-slim AS final-build
WORKDIR /app

# Required to persist build arg
ARG MASS_VERSION
ARG TARGETPLATFORM
ARG MASS_VERSION=2.3.0b8

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
&& apk add --no-cache \
ca-certificates \
jemalloc \
curl \
git \
wget \
tzdata \
libsox-fmt-all \
libsox3 \
sox \
cifs-utils \
libnfs-utils \
libjemalloc2 \
# install snapcast server 0.27 from bookworm backports
&& sh -c 'echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/sources.list' \
&& apt-get update \
&& apt-get install -y --no-install-recommends -t bookworm-backports snapserver \
# install ffmpeg 6 from multimedia repo
&& sh -c 'echo "Types: deb\nURIs: https://www.deb-multimedia.org\nSuites: stable\nComponents: main non-free\nSigned-By: /etc/apt/trusted.gpg.d/deb-multimedia-keyring.gpg" >> /etc/apt/sources.list.d/deb-multimedia.sources' \
&& sh -c 'echo "Package: *\nPin: origin www.deb-multimedia.org\nPin-Priority: 1" >> /etc/apt/preferences.d/99deb-multimedia' \
&& cd /tmp && curl -sLO https://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2016.8.1_all.deb \
&& apt install -y /tmp/deb-multimedia-keyring_2016.8.1_all.deb \
&& apt-get update \
&& apt install -y -t 'o=Unofficial Multimedia Packages' ffmpeg \
# cleanup
&& rm -rf /tmp/* \
&& rm -rf /var/lib/apt/lists/*
samba \
# install ffmpeg from community repo
&& apk add ffmpeg --repository=https://dl-cdn.alpinelinux.org/alpine/v3.20/community \
# install snapcast from community repo
&& apk add snapcast --repository=https://dl-cdn.alpinelinux.org/alpine/v3.20/community \
# install libnfs from community repo
&& apk add libnfs --repository=https://dl-cdn.alpinelinux.org/alpine/v3.20/community

# Copy widevine client files to container
RUN mkdir -p /usr/local/bin/widevine_cdm
COPY widevine_cdm/* /usr/local/bin/widevine_cdm/

# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#build-mounts-run---mount
# Install all built wheels
RUN --mount=type=bind,target=/tmp/wheels,source=/wheels,from=wheels-builder,rw \
set -x \
&& pip install --upgrade pip \
&& pip install --no-cache-dir /tmp/wheels/*.whl
# Upgrade pip + Install uv
RUN pip install --upgrade pip \
&& pip install uv==0.2.27

# Install Music Assistant from published wheel
RUN pip3 install \
--no-cache-dir \
music-assistant[server]==${MASS_VERSION} \
&& python3 -m compileall music_assistant
# Install Music Assistant from published wheel on PyPi
RUN uv pip install \
--system \
--no-cache \
--find-links "https://wheels.home-assistant.io/musllinux/" \
music-assistant[server]==${MASS_VERSION}

# Enable jemalloc
RUN \
export LD_PRELOAD="$(find /usr/lib/ -name *libjemalloc.so.2)" \
export MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000"
# Configure runtime environmental variables
RUN export LD_PRELOAD="/usr/lib/libjemalloc.so.2" \
&& export UV_SYSTEM_PYTHON="1" \
&& export UV_BREAK_SYSTEM_PACKAGES==1"

# Set some labels
LABEL \
Expand All @@ -110,5 +57,6 @@ LABEL \
io.hass.type="addon"

VOLUME [ "/data" ]
EXPOSE 8095

ENTRYPOINT ["mass", "--config", "/data"]
2 changes: 1 addition & 1 deletion music_assistant/server/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
async def install_package(package: str) -> None:
"""Install package with pip, raise when install failed."""
LOGGER.debug("Installing python package %s", package)
args = ["pip", "install", "--find-links", HA_WHEELS, package]
args = ["uv", "pip", "install", "--no-cache", "--find-links", HA_WHEELS, package]
return_code, output = await check_output(*args)

if return_code != 0:
Expand Down
Binary file modified music_assistant/server/providers/airplay/bin/cliraop-linux-aarch64
100755 → 100644
Binary file not shown.
Binary file modified music_assistant/server/providers/airplay/bin/cliraop-linux-x86_64
100755 → 100644
Binary file not shown.
9 changes: 5 additions & 4 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ else
echo "Creating Virtual environment..."
python -m venv .venv
fi
echo "Activating virtual environment..."
echo "Activating virtual environment..."
source .venv/bin/activate

echo "Installing development dependencies..."

pip install -e ".[server]"
pip install -e ".[test]"
pip install --upgrade pip
pip install --upgrade uv
uv pip install -e ".[server]"
uv pip install -e ".[test]"
pre-commit install
pip install -r requirements_all.txt