Skip to content

Commit

Permalink
Revert to debian images but include uvloop and armv7
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jul 10, 2023
1 parent 037b0d1 commit b6f7dd8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 166 deletions.
42 changes: 3 additions & 39 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ jobs:
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/music-assistant/server
# we use 3 different jobs here due so we can pass the correct BUILD_ARCH
- name: Build and Push amd64
- name: Build and Push images
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64
platforms: linux/amd64,linux/arm64,linux/arm/v7
file: Dockerfile
tags: |-
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.patch }},
Expand All @@ -102,38 +100,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"MASS_VERSION=${{ needs.build-and-publish-pypi.outputs.version }}"
"BUILD_ARCH=amd64"
- name: Build and Push arm64
uses: docker/[email protected]
with:
context: .
platforms: linux/arm64
file: Dockerfile
tags: |-
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.patch }},
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.minor }},
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.major }},
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.channel }},
ghcr.io/${{ github.repository_owner }}/server:latest
push: true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"MASS_VERSION=${{ needs.build-and-publish-pypi.outputs.version }}"
"BUILD_ARCH=aarch64"
- name: Build and Push armv7
uses: docker/[email protected]
with:
context: .
platforms: linux/arm/v7
file: Dockerfile
tags: |-
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.patch }},
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.minor }},
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.major }},
ghcr.io/${{ github.repository_owner }}/server:${{ steps.tags.outputs.channel }},
ghcr.io/${{ github.repository_owner }}/server:latest
push: true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"MASS_VERSION=${{ needs.build-and-publish-pypi.outputs.version }}"
"BUILD_ARCH=armv7"
101 changes: 73 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,90 @@
# syntax=docker/dockerfile:1
ARG BUILD_ARCH
ARG BASE_IMAGE_VERSION="3.11-alpine3.18"
ARG TARGETPLATFORM
ARG PYTHON_VERSION="3.11"

FROM ghcr.io/home-assistant/$BUILD_ARCH-base-python:${BASE_IMAGE_VERSION}
#####################################################################
# #
# Build Wheels #
# #
#####################################################################
FROM python:${PYTHON_VERSION}-slim as wheels-builder
ARG TARGETPLATFORM

ARG MASS_VERSION
ENV S6_SERVICES_GRACETIME=220000
ENV WHEELS_LINKS="https://wheels.home-assistant.io/musllinux/"
ARG UVLOOP_VERSION="0.17.0"
# 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

# build music assistant wheel
COPY music_assistant music_assistant
COPY pyproject.toml .
COPY MANIFEST.in .
RUN python3 -m build --wheel --outdir /wheels --skip-dependency-check

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

# Install OS requirements
RUN apk update \
&& apk add --no-cache \
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
wget \
tzdata \
ffmpeg \
libsox-fmt-all \
libsox3 \
sox \
cifs-utils \
nfs-utils
libnfs-utils \
libjemalloc2 \
# cleanup
&& rm -rf /tmp/* \
&& rm -rf /var/lib/apt/lists/*

## Setup Core dependencies
COPY requirements_all.txt .
RUN pip3 install \
--no-cache-dir \
--only-binary=:all: \
--find-links ${WHEELS_LINKS} \
-r requirements_all.txt

# Install Music Assistant
# 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

# Install Music Assistant from published wheel
RUN pip3 install \
--no-cache-dir \
music-assistant[server]==${MASS_VERSION} \
&& python3 -m compileall music-assistant

# Install optional uvloop if possible (will fail on armv7)
RUN pip3 install --no-cache-dir uvloop==${UVLOOP_VERSION}; exit 0
# 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"

# Required to persist build arg
ARG MASS_VERSION
ARG TARGETPLATFORM

# Set some labels
LABEL \
Expand All @@ -46,16 +94,13 @@ LABEL \
org.opencontainers.image.authors="The Music Assistant Team" \
org.opencontainers.image.documentation="https://github.com/orgs/music-assistant/discussions" \
org.opencontainers.image.licenses="Apache License 2.0" \
io.hass.version=${MASS_VERSION} \
io.hass.version="${MASS_VERSION}" \
io.hass.type="addon" \
io.hass.name="Music Assistant" \
io.hass.description="Music Assistant Server/Core" \
io.hass.platform="linux/${BUILD_ARCH}" \
io.hass.platform="${TARGETPLATFORM}" \
io.hass.type="addon"

VOLUME [ "/data" ]

# S6-Overlay
COPY rootfs /

WORKDIR /data
ENTRYPOINT ["mass", "--config", "/data"]
9 changes: 1 addition & 8 deletions music_assistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
from music_assistant.server import MusicAssistant
from music_assistant.server.helpers.logging import activate_log_queue_handler

try:
import uvloop # noqa: F401

USE_UVLOOP = True
except ImportError:
USE_UVLOOP = False

FORMAT_DATE: Final = "%Y-%m-%d"
FORMAT_TIME: Final = "%H:%M:%S"
FORMAT_DATETIME: Final = f"{FORMAT_DATE} {FORMAT_TIME}"
Expand Down Expand Up @@ -184,7 +177,7 @@ async def start_mass():

run(
start_mass(),
use_uvloop=USE_UVLOOP,
use_uvloop=True,
shutdown_callback=on_shutdown,
executor_workers=64,
)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ server = [
"shortuuid==1.0.11",
"zeroconf==0.70.0",
"cryptography==41.0.1",
"ifaddr==0.2.0"
"ifaddr==0.2.0",
"uvloop==0.17.0"
]
test = [
"black==23.3.0",
Expand Down
1 change: 1 addition & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ python-slugify==8.0.1
shortuuid==1.0.11
soco==0.29.1
unidecode==1.3.6
uvloop==0.17.0
xmltodict==0.13.0
ytmusicapi==1.0.0
zeroconf==0.70.0
30 changes: 0 additions & 30 deletions rootfs/etc/services.d/music-assistant/finish

This file was deleted.

11 changes: 0 additions & 11 deletions rootfs/etc/services.d/music-assistant/run

This file was deleted.

49 changes: 0 additions & 49 deletions rootfs/init

This file was deleted.

0 comments on commit b6f7dd8

Please sign in to comment.