From 36eae3c996ae7950debd9c9907e8a6ee22e7c920 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 13 Feb 2021 21:46:50 +0100 Subject: [PATCH] changes to build strategy --- .github/workflows/docker-build alpine.yml | 76 ++++++++++++++++++ ...r-build-multiarch.yml => docker-build.yml} | 16 ++-- .vscode/settings.json | 2 +- Dockerfile | 71 ++--------------- Dockerfile.alpine | 78 ------------------- music_assistant/constants.py | 2 +- music_assistant/managers/music.py | 5 +- music_assistant/managers/streams.py | 6 +- requirements.txt | 2 +- 9 files changed, 98 insertions(+), 160 deletions(-) create mode 100644 .github/workflows/docker-build alpine.yml rename .github/workflows/{docker-build-multiarch.yml => docker-build.yml} (82%) delete mode 100755 Dockerfile.alpine diff --git a/.github/workflows/docker-build alpine.yml b/.github/workflows/docker-build alpine.yml new file mode 100644 index 00000000..8df67dd5 --- /dev/null +++ b/.github/workflows/docker-build alpine.yml @@ -0,0 +1,76 @@ +name: Build multiarch Docker image (Alpine based) + +on: + push: + release: + types: [published, prereleased] + workflow_dispatch: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'warning' + tag: + description: 'Tag to set on docker image (e.g. 0.0.1' + required: true + +jobs: + buildx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prepare + id: prep + run: | + DOCKER_IMAGE=musicassistant/music-assistant + VERSION=latest + SHORTREF=${GITHUB_SHA::8} + MANUAL_TAG=${{ github.event.inputs.tag }} + + # If a manual tag was supplied, use that + if [[ -n $MANUAL_TAG ]]; then + VERSION=${MANUAL_TAG} + + # If this is git tag, use the tag name as a docker tag + elif [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + 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@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + context: . + file: ./Dockerfile.alpine + platforms: linux/amd64,linux/arm/v7,linux/arm64 + push: true + tags: ${{ steps.prep.outputs.tags }} diff --git a/.github/workflows/docker-build-multiarch.yml b/.github/workflows/docker-build.yml similarity index 82% rename from .github/workflows/docker-build-multiarch.yml rename to .github/workflows/docker-build.yml index 986c7e09..5d5300e2 100644 --- a/.github/workflows/docker-build-multiarch.yml +++ b/.github/workflows/docker-build.yml @@ -1,6 +1,7 @@ -name: Build multiarch Docker image +name: Build multiarch Docker image (Debian based) on: + push: release: types: [published, prereleased] workflow_dispatch: @@ -23,7 +24,7 @@ jobs: - name: Prepare id: prep run: | - DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/music-assistant + DOCKER_IMAGE=musicassistant/music-assistant-server VERSION=latest SHORTREF=${GITHUB_SHA::8} MANUAL_TAG=${{ github.event.inputs.tag }} @@ -50,20 +51,19 @@ jobs: echo ::set-output name=docker_image::${DOCKER_IMAGE} - name: Set up QEMU - uses: docker/setup-qemu-action@master + uses: docker/setup-qemu-action@v1 with: platforms: all - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@master + uses: docker/setup-buildx-action@v1 - name: Login to DockerHub - if: github.event_name != 'pull_request' - uses: docker/login-action@v1 + uses: docker/login-action@v1 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build uses: docker/build-push-action@v2 diff --git a/.vscode/settings.json b/.vscode/settings.json index e1a9b44c..7e607363 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "python.linting.pylintEnabled": true, "python.linting.pylintArgs": ["--rcfile=${workspaceFolder}/setup.cfg"], "python.linting.enabled": true, - "python.pythonPath": "venv/bin/python", + "python.pythonPath": "/Users/marcelvanderveldt/Workdir/music-assistant/server/.venv/bin/python3", "python.linting.flake8Enabled": true, "python.linting.flake8Args": ["--config=${workspaceFolder}/setup.cfg"], "python.linting.mypyEnabled": false, diff --git a/Dockerfile b/Dockerfile index 05f2009f..a1e4af32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,78 +1,17 @@ -FROM python:3.8-slim as builder +FROM musicassistant/base-image -ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple - -RUN set -x \ - # Install buildtime packages - && apt-get update && apt-get install -y --no-install-recommends \ - curl \ - ca-certificates \ - build-essential \ - gcc \ - libtag1-dev \ - libffi-dev \ - libssl-dev \ - zlib1g-dev \ - xvfb \ - tcl8.6-dev \ - tk8.6-dev \ - libjpeg-turbo-progs \ - libjpeg62-turbo-dev - -# build jemalloc -ARG JEMALLOC_VERSION=5.2.1 -RUN curl -L -s https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2 \ - | tar -xjf - -C /tmp \ - && cd /tmp/jemalloc-${JEMALLOC_VERSION} \ - && ./configure \ - && NB_CORES=$(grep -c '^processor' /proc/cpuinfo) \ - && export MAKEFLAGS="-j$((NB_CORES+1)) -l${NB_CORES}" \ - && make \ - && make install - -# build python wheels -WORKDIR /wheels +# install latest version COPY . /tmp -RUN pip wheel uvloop cchardet aiodns brotlipy \ - && pip wheel -r /tmp/requirements.txt \ +RUN cd /tmp \ # Include frontend-app in the source files && curl -L https://github.com/music-assistant/app/archive/master.tar.gz | tar xz \ && mv app-master/docs /tmp/music_assistant/web/static \ - && pip wheel /tmp - -#### FINAL IMAGE -FROM python:3.8-slim AS final-image - -WORKDIR /wheels -COPY --from=builder /wheels /wheels -COPY --from=builder /usr/local/lib/libjemalloc.so /usr/local/lib/libjemalloc.so -RUN set -x \ - # Install runtime dependency packages - && apt-get update \ - && apt-get install -y --no-install-recommends \ - curl \ - tzdata \ - ca-certificates \ - flac \ - sox \ - libsox-fmt-all \ - ffmpeg \ - libtag1v5 \ - openssl \ - libjpeg62-turbo \ - zlib1g \ - # install music assistant (and all it's dependencies) using the prebuilt wheels - && pip install --no-cache-dir -f /wheels music_assistant \ + && pip install --no-cache-dir music_assistant \ # cleanup - && rm -rf /tmp/* \ - && rm -rf /wheels \ - && rm -rf /var/lib/apt/lists/* \ - && rm -rf /root/* + && rm -rf /tmp/* -ENV DEBUG=false EXPOSE 8095/tcp VOLUME [ "/data" ] -ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so ENTRYPOINT ["mass", "--config", "/data"] \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine deleted file mode 100755 index 8544c7c4..00000000 --- a/Dockerfile.alpine +++ /dev/null @@ -1,78 +0,0 @@ -FROM python:3.8-alpine3.12 - -ARG JEMALLOC_VERSION=5.2.1 -WORKDIR /tmp -COPY . . - -# Install packages -RUN set -x \ - && apk update \ - && echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ - && echo "http://dl-8.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \ - # install default packages - && apk add --no-cache \ - tzdata \ - ca-certificates \ - curl \ - flac \ - sox \ - libuv \ - ffmpeg \ - uchardet \ - taglib \ - libressl \ - # dependencies for pillow - freetype \ - lcms2 \ - libimagequant \ - libjpeg-turbo \ - libwebp \ - libxcb \ - openjpeg \ - tiff \ - zlib \ - # install (temp) build packages - && apk add --no-cache --virtual .build-deps \ - build-base \ - libsndfile-dev \ - taglib-dev \ - gcc \ - musl-dev \ - freetype-dev \ - libpng-dev \ - libressl-dev \ - fribidi-dev \ - harfbuzz-dev \ - jpeg-dev \ - lcms2-dev \ - openjpeg-dev \ - tcl-dev \ - tiff-dev \ - tk-dev \ - zlib-dev \ - libuv-dev \ - libffi-dev \ - uchardet-dev \ - # setup jemalloc - && curl -L -f -s "https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2" \ - | tar -xjf - -C /tmp \ - && cd /tmp/jemalloc-${JEMALLOC_VERSION} \ - && ./configure \ - && make \ - && make install \ - && cd /tmp \ - # make sure optional packages are installed - && pip install uvloop cchardet aiodns brotlipy \ - # install music assistant - && pip install . \ - # cleanup build files - && apk del .build-deps \ - && rm -rf /tmp/* - -ENV DEBUG=false -EXPOSE 8095/tcp - -VOLUME [ "/data" ] - -ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so -ENTRYPOINT ["mass", "--config", "/data"] \ No newline at end of file diff --git a/music_assistant/constants.py b/music_assistant/constants.py index 93738cea..d0e7efd3 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -1,6 +1,6 @@ """All constants for Music Assistant.""" -__version__ = "0.0.84" +__version__ = "0.0.85" REQUIRED_PYTHON_VER = "3.7" # configuration keys/attributes diff --git a/music_assistant/managers/music.py b/music_assistant/managers/music.py index d14c8cec..8bb05a60 100755 --- a/music_assistant/managers/music.py +++ b/music_assistant/managers/music.py @@ -596,8 +596,9 @@ class MusicManager: if media_item.media_type == MediaType.Radio: full_track = media_item else: - full_track = await self.async_get_track( - media_item.item_id, media_item.provider + full_track = ( + await self.async_get_track(media_item.item_id, media_item.provider) + or media_item ) # sort by quality and check track availability for prov_media in sorted( diff --git a/music_assistant/managers/streams.py b/music_assistant/managers/streams.py index a0c810da..0ca98e6d 100755 --- a/music_assistant/managers/streams.py +++ b/music_assistant/managers/streams.py @@ -14,7 +14,7 @@ import subprocess from enum import Enum from typing import AsyncGenerator, List, Optional, Tuple -from aiofile import AIOFile, Reader +import aiofiles from music_assistant.constants import ( CONF_MAX_SAMPLE_RATE, EVENT_STREAM_ENDED, @@ -376,8 +376,8 @@ class StreamManager: audio_data += chunk # stream from file elif stream_type == StreamType.FILE: - async with AIOFile(stream_path) as afp: - async for chunk in Reader(afp): + async with aiofiles.open(stream_path) as afp: + async for chunk in afp: yield chunk if needs_analyze and len(audio_data) < 100000000: audio_data += chunk diff --git a/requirements.txt b/requirements.txt index 50eae738..521ae59e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ argparse==1.4.0 aiohttp[speedups]==3.7.3 pychromecast==8.1.0 asyncio-throttle==1.0.1 -aiofile==3.3.3 +aiofiles==0.6.0 aiosqlite==0.16.0 pytaglib==1.4.6 python-slugify==4.0.1 -- 2.34.1