try to fix docker build
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 9 Mar 2023 10:50:26 +0000 (11:50 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 9 Mar 2023 10:50:26 +0000 (11:50 +0100)
Dockerfile
compose.yml [deleted file]
docker-compose.example.yml [new file with mode: 0644]
pyproject.toml

index f7428c4e170ec3ceb23513e48278d9956d52244e..5e6b07dc4eef78463ba240a19c5c977e39a11c26 100644 (file)
@@ -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/compose.yml
deleted file mode 100644 (file)
index ca1a84a..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-version: "3.8"
-services:
-  music-assistant-server:
-    build:
-      context: ./
-      dockerfile: Dockerfile
-    image: music-assistant-server:latest
-    container_name: music-assistant-server
-    restart: unless-stopped
-    # Required for player discovery to work correctly
-    network_mode: host
-    volumes:
-      - ${USERDIR:-$HOME}/docker/music-assistant-server/data:/data/
diff --git a/docker-compose.example.yml b/docker-compose.example.yml
new file mode 100644 (file)
index 0000000..66ed7ca
--- /dev/null
@@ -0,0 +1,13 @@
+version: "3"
+services:
+  music-assistant-server:
+    build:
+      context: ./docker/
+      dockerfile: Dockerfile
+    image: ghcr.io/music-assistant/core:latest # <<< Desired release version here
+    container_name: music-assistant-server
+    restart: unless-stopped
+    # Network mode must be set to host for MA to work correctly
+    network_mode: host
+    volumes:
+      - ${USERDIR:-$HOME}/docker/music-assistant-server/data:/data/
index d8d3fa9e552214db5b425b485b445ea07fb2fdd9..55881cb1bef1b46d726ea88b731832c7de02eb72 100644 (file)
@@ -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"