From 30a162d35587dc8e85050ae80e6a95516438770a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 9 Mar 2023 11:50:26 +0100 Subject: [PATCH] try to fix docker build --- Dockerfile | 93 ++++++++++++++++++++--- compose.yml => docker-compose.example.yml | 8 +- pyproject.toml | 2 +- 3 files changed, 87 insertions(+), 16 deletions(-) rename compose.yml => docker-compose.example.yml (57%) diff --git a/Dockerfile b/Dockerfile index f7428c4e..5e6b07dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,93 @@ -FROM python:3.11.2 +# syntax=docker/dockerfile:experimental +ARG HASS_ARCH=amd64 +ARG BUILD_VERSION=latest +ARG PYTHON_VERSION="3.11" -# Install component packages -RUN \ - set -x \ +##################################################################### +# # +# Build Wheels # +# # +##################################################################### +FROM python:${PYTHON_VERSION}-slim as wheels-builder +ARG HASS_ARCH + +ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple +ENV PATH="${PATH}:/root/.cargo/bin" + +# Install buildtime packages +RUN set -x \ && apt-get update \ && apt-get install -y --no-install-recommends \ - libuv1 \ + build-essential \ + ca-certificates \ + curl \ + gcc \ + git \ + libffi-dev \ + libssl-dev + +RUN set -x \ + \ + && if [ ${HASS_ARCH} = "amd64" ]; then RUST_ARCH="x86_64-unknown-linux-gnu"; fi \ + && if [ ${HASS_ARCH} = "armv7" ]; then RUST_ARCH="armv7-unknown-linux-gnueabihf"; fi \ + && if [ ${HASS_ARCH} = "aarch64" ]; then RUST_ARCH="aarch64-unknown-linux-gnu"; fi \ + \ + && curl -o rustup-init https://static.rust-lang.org/rustup/dist/${RUST_ARCH}/rustup-init \ + && chmod +x rustup-init \ + && ./rustup-init -y --no-modify-path --profile minimal --default-host ${RUST_ARCH} + +WORKDIR /wheels +COPY requirements.txt . + +# build python wheels +RUN set -x \ + && pip wheel -r .[server] + + +##################################################################### +# # +# Final Image # +# # +##################################################################### +FROM python:${PYTHON_VERSION}-slim AS final-build +WORKDIR /app + +ENV DEBIAN_FRONTEND="noninteractive" + +RUN set -x \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates \ curl \ - wget \ - ffmpeg \ git \ - libjpeg62-turbo + jq \ + openssl \ + tzdata \ + ffmpeg \ + ffmpeg-libs \ + libjpeg-turbo \ + # cleanup + && rm -rf /tmp/* \ + && rm -rf /var/lib/apt/lists/* -COPY . ./ -# Install mass wheel and dependencies -RUN pip3 install --no-cache-dir .[server] +# 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 --no-cache-dir -f /tmp/wheels -r /tmp/wheels/requirements.txt + +# Required to persist build arg +ARG BUILD_VERSION +ARG HASS_ARCH +# Set some labels for the Home Assistant add-on +LABEL \ + io.hass.version=${BUILD_VERSION} \ + io.hass.name="Music Assistant" \ + io.hass.description="Music Assistant Server/Core" \ + io.hass.arch="${HASS_ARCH}" \ + io.hass.type="addon" EXPOSE 8095/tcp EXPOSE 9090/tcp diff --git a/compose.yml b/docker-compose.example.yml similarity index 57% rename from compose.yml rename to docker-compose.example.yml index ca1a84ad..66ed7ca5 100644 --- a/compose.yml +++ b/docker-compose.example.yml @@ -1,13 +1,13 @@ -version: "3.8" +version: "3" services: music-assistant-server: build: - context: ./ + context: ./docker/ dockerfile: Dockerfile - image: music-assistant-server:latest + image: ghcr.io/music-assistant/core:latest # <<< Desired release version here container_name: music-assistant-server restart: unless-stopped - # Required for player discovery to work correctly + # Network mode must be set to host for MA to work correctly network_mode: host volumes: - ${USERDIR:-$HOME}/docker/music-assistant-server/data:/data/ diff --git a/pyproject.toml b/pyproject.toml index d8d3fa9e..55881cb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,7 @@ target-version = ['py311'] line-length = 100 [tool.codespell] -ignore-words-list = "provid" +ignore-words-list = "provid,hass" [tool.mypy] python_version = "3.11" -- 2.34.1