include docker build strategy
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 31 Oct 2020 22:52:14 +0000 (23:52 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 31 Oct 2020 22:52:14 +0000 (23:52 +0100)
.github/workflows/docker-build-multiarch.yml [new file with mode: 0644]
Dockerfile [new file with mode: 0755]
rootfs/etc/services.d/music_assistant/finish [new file with mode: 0644]
rootfs/etc/services.d/music_assistant/run [new file with mode: 0644]

diff --git a/.github/workflows/docker-build-multiarch.yml b/.github/workflows/docker-build-multiarch.yml
new file mode 100644 (file)
index 0000000..a6faebb
--- /dev/null
@@ -0,0 +1,62 @@
+name: Build multiarch Docker image
+
+on:
+  release:
+    types: [published, prereleased]
+
+jobs:
+  buildx:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Prepare
+        id: prep
+        run: |
+          DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/music-assistant
+          VERSION=latest
+          SHORTREF=${GITHUB_SHA::8}
+
+          # If this is git tag, use the tag name as a docker tag
+          if [[ $GITHUB_REF == refs/tags/* ]]; then
+            VERSION=${GITHUB_REF#refs/tags/v}
+          fi
+          TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}"
+
+          # If the VERSION looks like a version number, assume that
+          # this is the most recent version of the image and also
+          # tag it 'latest'.
+          if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
+            TAGS="$TAGS,${DOCKER_IMAGE}:latest"
+          fi
+
+          # Set output parameters.
+          echo ::set-output name=tags::${TAGS}
+          echo ::set-output name=docker_image::${DOCKER_IMAGE}
+
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@master
+        with:
+          platforms: all
+
+      - name: Set up Docker Buildx
+        id: buildx
+        uses: docker/setup-buildx-action@master
+
+      - name: Login to DockerHub
+        if: github.event_name != 'pull_request'
+        uses: docker/login-action@v1
+        with:
+          username: ${{ secrets.DOCKER_USERNAME }}
+          password: ${{ secrets.DOCKER_PASSWORD }}
+
+      - name: Build
+        uses: docker/build-push-action@v2
+        with:
+          builder: ${{ steps.buildx.outputs.name }}
+          context: .
+          file: ./Dockerfile
+          platforms: linux/amd64,linux/arm64,linux/ppc64le
+          push: true
+          tags: ${{ steps.prep.outputs.tags }}
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100755 (executable)
index 0000000..448a59f
--- /dev/null
@@ -0,0 +1,38 @@
+FROM python:slim
+
+# Build arguments
+ARG MASS_VERSION=0.0.60
+ARG JEMALLOC_VERSION=5.2.1
+ARG S6_OVERLAY_VERSION=2.1.0.2
+
+RUN apt-get update && apt-get install -y --no-install-recommends \
+               # required packages
+               wget bash jq flac sox libsox-fmt-mp3 zip curl unzip ffmpeg libsndfile1 libtag1v5 libblas3 liblapack3 \
+               # build packages
+               libtag1-dev build-essential git liblapack-dev libblas-dev gfortran libatlas-base-dev && \
+    # Setup jemalloc
+    curl -L -s https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2 | tar -xjf - -C /usr/src && \
+    cd /usr/src/jemalloc-${JEMALLOC_VERSION} && \
+    ./configure && \
+    make && \
+    make install && \
+    rm -rf /usr/src/jemalloc-${JEMALLOC_VERSION} && \
+    # Setup s6 overlay
+    curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${BUILD_ARCH}.tar.gz" | tar zxvf - -C / && \
+    mkdir -p /etc/fix-attrs.d && \
+    mkdir -p /etc/services.d && \
+    # make sure uvloop is installed
+    pip install --upgrade uvloop && \
+    # install music assistant
+    cd /tmp && pip install --upgrade music-assistant==${MASS_VERSION} && \
+       # cleanup build packages
+       apt-get purge -y --auto-remove libtag1-dev build-essential liblapack-dev libblas-dev gfortran libatlas-base-dev && \
+       rm -rf /var/lib/apt/lists/*
+
+# copy rootfs
+COPY rootfs /
+
+ENV DEBUG=False
+VOLUME [ "/data" ]
+
+ENTRYPOINT ["/init"]
\ No newline at end of file
diff --git a/rootfs/etc/services.d/music_assistant/finish b/rootfs/etc/services.d/music_assistant/finish
new file mode 100644 (file)
index 0000000..282679e
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/execlineb -S0
+# ==============================================================================
+# Take down the S6 supervision tree when MusicAssistant fails
+# ==============================================================================
+if -n { s6-test $# -ne 0 }
+if -n { s6-test ${1} -eq 256 }
+
+s6-svscanctl -t /var/run/s6/services
\ No newline at end of file
diff --git a/rootfs/etc/services.d/music_assistant/run b/rootfs/etc/services.d/music_assistant/run
new file mode 100644 (file)
index 0000000..3f2ae4b
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/with-contenv sh
+# ==============================================================================
+# Run MusicAssistant
+# ==============================================================================
+
+# Enable Jemalloc
+export LD_PRELOAD="/usr/local/lib/libjemalloc.so.2"
+
+args="--config /data"
+
+if [ $DEBUG == "true" ]; then
+    args="${args} --debug"
+fi
+
+exec python -m music_assistant ${args}
\ No newline at end of file