jaedb / Iris

Discover, explore and manage your music library across multiple sources with this beautiful web-based interface. Iris is a Mopidy frontend extension.
Apache License 2.0
1.14k stars 133 forks source link

Use different base python image for docker #648

Open diabl0w opened 4 years ago

diabl0w commented 4 years ago

Is your feature request related to a problem? Please describe. The circleci/python docker base image is approximately 1gb in size, that is huge for a docker container. The official python docker base image is also about 1gb in size. However, official python docker also provides an alpine based image which is only about 100Mb in size, much better! There is also a 3rd party solution here, which isn't necessary but they do provide a nice table showing size differences for reference: https://github.com/jfloff/alpine-python

jaedb commented 4 years ago

@diabl0w are you willing and able to have a try at changing this and testing it's viability?

diabl0w commented 4 years ago

@diabl0w are you willing and able to have a try at changing this and testing it's viability?

Here is a quick draft that works:

FROM alpine:3.12

# Switch to the root user while we do our changes
USER root

# Install GStreamer and other required Debian packages

RUN apk update \
  && apk add \
    bash \
    mopidy \
    py3-pip \
#    py3-gst \
#    gst-plugins-good \
#    gst-plugins-bad \
#    gst-plugins-ugly \
    dumb-init \
    graphviz-dev \
    alsa-lib-dev \
    git \
    sudo 

# Install mopidy and extensions
RUN python3 -m pip install --no-cache \
#  mopidy \
  mopidy-mpd \
  mopidy-local 

# Clone Iris from the repository and install in development mode.
# This allows a binding at "/iris" to map to your local folder for development, rather than
# installing using pip.
RUN git clone https://github.com/jaedb/Iris.git /iris \
 && cd /iris \
 && python3 setup.py develop \
 && mkdir -p /var/lib/mopidy/.config \
 && ln -s /config /var/lib/mopidy/.config/mopidy \
 # Allow mopidy user to run system commands (restart, local scan, etc)
 && echo "mopidy ALL=NOPASSWD: /iris/mopidy_iris/system.sh" >> /etc/sudoers

# Start helper script.
COPY docker/entrypoint.sh /entrypoint.sh

# Default configuration.
COPY docker/mopidy.example.conf /config/mopidy.conf

# Copy the pulse-client configuratrion.
COPY docker/pulse-client.conf /etc/pulse/client.conf

# Add version info to image
COPY VERSION /

# Allows any user to run mopidy, but runs by default as a randomly generated UID/GID.
#RUN adduser --disabled-password -s '/bin/sh' -h '/var/lib/mopidy' mopidy
ENV HOME=/var/lib/mopidy
RUN addgroup mopidy audio \
 && mkdir /var/lib/mopidy/local \
 && chown mopidy:audio -R $HOME /entrypoint.sh /iris \
 && chmod go+rwx -R $HOME /entrypoint.sh /iris \
 && echo "1" >> /IS_CONTAINER

# Runs as mopidy user by default.
USER mopidy:audio

VOLUME ["/var/lib/mopidy/local"]

EXPOSE 6600 6680 1704 1705 5555/udp

ENTRYPOINT ["/usr/bin/dumb-init", "/entrypoint.sh"]
CMD ["mopidy"]

Observations:

1) I ended up just using the normal alpine docker base image. it is much easier to just use a plain distribution as a base image rather than a python one. This is because mopidy requires gstreamer and python-gstreamer... and when you use a prepackaged python docker image (like from circleci or python), you get too many issues with conflicting python versions. because the python-gstreamer from the distro will often be running on a different python version from the python version that circleci/python docker image provides.

2) i used the distro's mopidy version instead of mopidy's repo or the pip version of mopidy, i could fix that later.. it will probably be best to use the pip version (or we can leave as-is, youre choice)

3) i haven't tested anything to do with spotify plugins as i don't have spotify, and didnt include any spotify related stuff here

4) it would be nice to also include snapcast in the docker images

5) using this docker file, the image file size has been reduced from 2.29 Gb to 821Mb (although with less plugins)

jaedb commented 3 years ago

I've had a quick look at this, but libspotify sounds like it'll require some effort to get working on Alpine (https://discourse.mopidy.com/t/spotify-on-alpine-linux/3859).

diabl0w commented 3 years ago

librespot is available on alpine linux and I believe is an attempt to replace libspotify which has been deprecated for a few years now... https://github.com/librespot-org/librespot ....Not sure how much work that is to migrate but it does kill 2 birds with 1 stone (upgrade from deprecated library and streamline docker image)

jaedb commented 3 years ago

That'll be an interesting project, and certainly about time. Only once it is integrated into Mopidy-Spotify then we would be able to update Iris' dockerfile. There appears to be a discussion covering exactly this: https://github.com/mopidy/mopidy-spotify/issues/110

diabl0w commented 3 years ago

That'll be an interesting project, and certainly about time. Only once it is integrated into Mopidy-Spotify then we would be able to update Iris' dockerfile. There appears to be a discussion covering exactly this: mopidy/mopidy-spotify#110

ahh yes, its been awhile since I looked at the whole mopidy/iris ecosystem, not realizing that mopidy-spotify is a seperate project from here. that sounds like a fair plan, if it ever happens

PureTryOut commented 3 years ago

Switching to Alpine for the image would be nice indeed but as mentioned, as long as mopidy-spotify doesn't use librespot it's not an option.

However, there are still smaller images available that are able to run libspotify. For example the latest Python image based on Python 3.9.2 and Debian Buster is about ~300MB in size, depending on the architecture.

wu-lee commented 2 years ago

I wanted to add here: I managed to get Mopidy/Iris working on Alpine some months ago, although I don't have a coherent recipe for it to report right now and I need to find the time to revisit this. As I recall, I did have some problems with libspotify and the Rust compilation of the necessary Python crypto libs, and eventually concluded libspotify is dead in the water.

However, looking recently I see that there is a librespot package available on Alpine now:

https://pkgs.alpinelinux.org/package/edge/testing/x86_64/librespot

PureTryOut commented 2 years ago

LibreSpot, as nice as it is, however is not libspotify. Mopidy for now uses libspotify and not librespot, yet, so we're stuck with it for now.

PureTryOut commented 1 year ago

So Mopidy did switch to librespot now, and the official Docker image now makes use of that. In dcbfce4f8b7ad0e9510fa2583aaee474ea149dcf I added an Alpine Linux based OCI image which is 658MB lighter than the Debian-based one. The issue now is that no image using that Dockerfile has actually been built and pushed to Docker hub. Any chance you could do that @jaedb? Looking at other projects on Dockerhub it seems most projects push <version>-alpine versions of their images, would be nice to do the same here.