swingmx / swingmusic

Swing Music is a beautiful, self-hosted music player for your local audio files. Like a cooler Spotify ... but bring your own music.
https://swingmx.com
MIT License
678 stars 41 forks source link

[Docker] Arm64 Support? #154

Closed kitsumed closed 5 months ago

kitsumed commented 8 months ago

Version : 1.3.1 OS : Raspberry Pi OS (based on Debian) Error : exec /swingmusic: exec format error

It seem like the currents docker builds does not have a valid entrypoint meaning docker can't properly run swing-music.

cwilvx commented 8 months ago

Hello @kitsumed

The exec format error can also be caused by running Architecture mismatch. Are you running the your OS in a rasperry pi? If so ... can you try pulling the linux/arm/v7 image and see whether it works?

docker pull ghcr.io/swing-opensource/swingmusic:v1.3.1@sha256:58f652efef894d56ab34a9f468a31b6e6ccbcfa6fff345a908477fe338d6b043

You can view all the supported architectures by going to the container page and switching to the OS/Arch tab.

Please let me know whether it works.

VlaK0r commented 8 months ago

Hello @kitsumed

The exec format error can also be caused by running Architecture mismatch. Are you running the your OS in a rasperry pi? If so ... can you try pulling the linux/arm/v7 image and see whether it works?

docker pull ghcr.io/swing-opensource/swingmusic:v1.3.1@sha256:58f652efef894d56ab34a9f468a31b6e6ccbcfa6fff345a908477fe338d6b043

You can view all the supported architectures by going to the container page and switching to the OS/Arch tab.

Please let me know whether it works.

No image works on the raspberry pi 4

cwilvx commented 8 months ago

@VlaK0r @kitsumed

I don't know whether it's because the Docker image uses the binary which is created on a amd64 ubuntu 22. I don't have experience working with the raspberry pi or similar architectures, so I don't know how to start investigating this issue.

If you guys have any idea how I should try fixing this, let me know.

kitsumed commented 8 months ago

Hello @kitsumed

The exec format error can also be caused by running Architecture mismatch. Are you running the your OS in a rasperry pi? If so ... can you try pulling the linux/arm/v7 image and see whether it works?

docker pull ghcr.io/swing-opensource/swingmusic:v1.3.1@sha256:58f652efef894d56ab34a9f468a31b6e6ccbcfa6fff345a908477fe338d6b043

You can view all the supported architectures by going to the container page and switching to the OS/Arch tab.

Please let me know whether it works.

I just tried it and it sadly does not work either, returning the same error.

kitsumed commented 8 months ago

@VlaK0r @kitsumed

I don't know whether it's because the Docker image uses the binary which is created on a amd64 ubuntu 22. I don't have experience working with the raspberry pi or similar architectures, so I don't know how to start investigating this issue.

If you guys have any idea how I should try fixing this, let me know.

My raspberry run the x64 version meaning it should be able to support arm64, not sure about linux/arm/v7.

Edit : From quick searches I think compiling a arm64 version on GitHub would do the work. You might also by interested by https://forums.raspberrypi.com/viewtopic.php?t=181389

cwilvx commented 8 months ago

@kitsumed @VlaK0r

I have compiled a linux/arm64 image. Can you try it and let me know whether it works. ( it still uses the same binary I had mentioned earlier btw)

docker pull ghcr.io/swing-opensource/swingmusic:v1.3.2@sha256:9360ccc600c78ca5ff9564c4c7a0a7592af80a7fb8403f79729056eb588e53d3

view package

kitsumed commented 8 months ago

@kitsumed @VlaK0r

I have compiled a linux/arm64 image. Can you try it and let me know whether it works. ( it still uses the same binary I had mentioned earlier btw)

docker pull ghcr.io/swing-opensource/swingmusic:v1.3.2@sha256:9360ccc600c78ca5ff9564c4c7a0a7592af80a7fb8403f79729056eb588e53d3

view package

Thanks, I tried compiling it on my own but It just failed (seem like the github repo and Docker file does use the same paths). Edit : I managed to build it, same result.

Runned your build but it returned the same error, exec /swingmusic: exec format error. I think the problem may be with this line.

kitsumed commented 8 months ago

@VlaK0r @kitsumed

I don't know whether it's because the Docker image uses the binary which is created on a amd64 ubuntu 22. I don't have experience working with the raspberry pi or similar architectures, so I don't know how to start investigating this issue.

If you guys have any idea how I should try fixing this, let me know.

I just realized but If you compiled the original binary on a amd64 I doubt it would work on ARM, did you consider compiling the whole code (making the binary etc...) from the dockerfile or directly running manage.py without compiling it as one binary?

isole commented 6 months ago

Neither arm image works on pi5

zuble commented 5 months ago

got same error with both armv7 and arm64 images on pi4b

exec /swingmusic: exec format error

Capevace commented 5 months ago

I had the same problem, wanting to run Swingmusic on my Hetzner ARM server, wrote myself this Dockerfile to fix it. Feel free to use it.

It properly uses Docker and builds the Swingmusic client inside the container, then just runs the server directly. This way everything is virualized for it to work on multiple platforms and we're not just copying the compiled binary into the container.

FROM ubuntu:latest

WORKDIR /

# copy the source code (except dockerfile)
COPY ./ /app

# install python and poetry
RUN apt-get update && apt-get install -y ffmpeg python3 python3-pip python3-venv && \
    pip3 install poetry

# install nodejs 18
RUN apt-get install -y curl && \
    curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get install -y nodejs

# install yarn
RUN npm install --global yarn

RUN cd /app/client_src && yarn install && yarn build --outDir /app/client

RUN cd /app && \
    poetry install

WORKDIR /app

EXPOSE 1970/tcp

VOLUME /music

VOLUME /config

ENTRYPOINT ["poetry", "run", "python", "manage.py", "--host", "0.0.0.0", "--config", "/config"]
Capevace commented 5 months ago

Oh, you'll need to clone the client repo into this one when building, was easier that way

git clone https://github.com/swing-opensource/swingmusic swingmusic
cd swingmusic
git clone https://github.com/swing-opensource/swingmusic client_src
docker build . -t swingmusic

You'll need to provide your own LastFM API key in this case, but IMO this should be the default. Including it in the binary doesn't look super safe

  swingmusic:
    image: swingmusic:latest
    container_name: swingmusic
    environment:
      - LASTFM_API_KEY=<KEY>
    volumes:
      - ./swingmusic/music:/music
      - ./swingmusic/config:/config
    ports:
      - "1970:1970"
    restart: unless-stopped
ManBearPigg commented 4 months ago

If anyone wants to build on the bare metal of their Raspberry Pi (or other ARM64 / aarch64 architecture) I got this build script working.

Poetry gave me a super hard time. It's not friendly on the Pi right now. But once you build you're done with it.

An ARM64 binary in future releases would be hella swag. There are lots of Pi homelabbers out there and Swing Music is right up their alley. Just downloading the binary is great.

By the way, I'm running NordVPN meshnet and I need to give --host 0.0.0.0 when I run the binary so that my local IP and VPN IP both work, if anyone is wondering about that kind of thing.

#!/bin/bash

# README
#   Builds swingmusic binary for aarch64 aka ARM64 architecture
# Run
#   ./buildswingmusic.sh
#   chmod a+x swingmusicbuilder/swingmusic/dist/swingmusic
#   .swingmusicbuilder/swingmusic/dist/swingmusic --port <optional_port_param> --host <optional_host_param>
# Notes
#   Poetry installer and pipx install poetry are both broken on ARM64 Raspberry Pi OS
#   Moving or renaming venv directory (comment inline below) will break that venv.
#   Additional poetry bug ongoing https://github.com/python-poetry/poetry/issues/5250 (comment inline below)
#   Changed to bash shebang above from repo build script setting of zsh

mkdir swingmusicbuilder
cd swingmusicbuilder

git clone https://github.com/swing-opensource/swingmusic-client.git
git clone https://github.com/swing-opensource/swingmusic.git

# Manual poetry installation as installers are broken.
python3 -m venv poetry
source poetry/bin/activate

cd swingmusic

pip install -U pip setuptools
pip install poetry

cd ../swingmusic-client
yarn install
yarn build --outDir ../swingmusic/client

cd ../swingmusic
# Fixes poetry issue 5250.
export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring
poetry install
# Swing gives error if this is not set. Set to version of repo you cloned.
export SWINGMUSIC_APP_VERSION="1.4.8"
poetry run python manage.py --build