From e91c9531e8bfa0a96f6ceb9c36dcce5525e5b89b Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 31 Oct 2020 23:52:14 +0100 Subject: [PATCH] include docker build strategy --- .github/workflows/docker-build-multiarch.yml | 62 ++++++++++++++++++++ Dockerfile | 38 ++++++++++++ rootfs/etc/services.d/music_assistant/finish | 8 +++ rootfs/etc/services.d/music_assistant/run | 15 +++++ 4 files changed, 123 insertions(+) create mode 100644 .github/workflows/docker-build-multiarch.yml create mode 100755 Dockerfile create mode 100644 rootfs/etc/services.d/music_assistant/finish create mode 100644 rootfs/etc/services.d/music_assistant/run diff --git a/.github/workflows/docker-build-multiarch.yml b/.github/workflows/docker-build-multiarch.yml new file mode 100644 index 00000000..a6faebbc --- /dev/null +++ b/.github/workflows/docker-build-multiarch.yml @@ -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 index 00000000..448a59f4 --- /dev/null +++ b/Dockerfile @@ -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 index 00000000..282679ee --- /dev/null +++ b/rootfs/etc/services.d/music_assistant/finish @@ -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 index 00000000..3f2ae4bf --- /dev/null +++ b/rootfs/etc/services.d/music_assistant/run @@ -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 -- 2.34.1