8000 #104 Revamped by GioF71 · Pull Request #105 · GioF71/librespot-docker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#104 Revamped #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of servic 8000 e and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .github/workflows/docker-multi-arch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
base: ["bookworm", "bullseye"]
base: ["bookworm"]

steps:
- name: Checkout
Expand All @@ -31,13 +31,24 @@ jobs:
ref=${{ github.ref }}
echo "REF: ["$ref"]"

declare -A base_image_from_matrix
base_image_from_matrix[bullseye]=debian:bullseye-slim
base_image_from_matrix[bookworm]=debian:bookworm-slim
declare -A rust_image_from_matrix
rust_image_from_matrix[bullseye]=library/rust:slim-bullseye
rust_image_from_matrix[bookworm]=library/rust:slim-bookworm

declare -A base_images

base_images[bookworm]=library/debian:bookworm-slim
base_images[bullseye]=library/debian:bullseye-slim

select_rust_image=${rust_image_from_matrix[${{ matrix.base }}]}
if [ -z "${select_rust_image}" ]; then
select_rust_image=library/rust:slim
fi
echo "Select Rust Image [" $select_rust_image "]"

select_base_image=${base_image_from_matrix[${{ matrix.base }}]}
if [ -z "${select_base_image}" ]; then
select_base_image=debian:buster-slim
select_base_image=library/debian:stable-slim
fi
echo "Select Base Image [" $select_base_image "]"

Expand Down Expand Up @@ -103,7 +114,7 @@ jobs:
fi
echo "Building tags: ["${tags}"]"
echo "RELEASE_TAGS=${tags}" >> $GITHUB_ENV
echo "BASE_IMAGE=${select_base_image}" >> $GITHUB_ENV
echo "RUST_IMAGE=${select_rust_image}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
Expand All @@ -121,7 +132,8 @@ jobs:
with:
context: .
build-args: |
RUST_IMAGE=${{ env.RUST_IMAGE }}
BASE_IMAGE=${{ env.BASE_IMAGE }}
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
platforms: linux/amd64,linux/arm64/v8
push: true
tags: ${{ env.RELEASE_TAGS }}
67 changes: 45 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE} AS base
ARG USE_APT_PROXY
ARG RUST_IMAGE=""
ARG BASE_IMAGE=""
FROM ${RUST_IMAGE:-library/rust:slim} AS base

RUN mkdir -p /app/bin
RUN mkdir -p /app/conf
RUN mkdir -p /app/doc

COPY app/conf/01-apt-proxy /app/conf/
# Add build dependencies
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y cmake
RUN apt-get install -y libclang-dev
RUN apt-get install -y libasound2-dev
RUN apt-get install -y libpulse-dev
RUN apt-get install -y libavahi-compat-libdnssd-dev
RUN apt-get install -y pkg-config

RUN if [ "$USE_APT_PROXY" = "Y" ]; then \
echo "Using apt proxy"; \
cp /app/conf/01-apt-proxy /etc/apt/apt.conf.d/; \
cat /etc/apt/apt.conf.d/01-apt-proxy; \
else \
echo "Building without proxy"; \
fi
# runtime
RUN apt-get install -y libavahi-compat-libdnssd1

RUN apt-get update
RUN apt-get install -y libasound2
RUN apt-get install -y alsa-utils
RUN apt-get install -y git

RUN mkdir /src
WORKDIR /src
RUN git clone --branch master https://github.com/librespot-org/librespot.git
WORKDIR /src/librespot
RUN CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release --no-default-features --features "alsa-backend pulseaudio-backend with-avahi with-dns-sd with-libmdns"
RUN cp /src/librespot/target/release/librespot /usr/bin/librespot
WORKDIR /
# RUN rm -Rf /src

RUN rm -rf /var/lib/apt/lists/*

RUN apt-get -y install curl
RUN curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
FROM ${BASE_IMAGE:-library/debian:stable-slim} AS intermediate

RUN if [ "$USE_APT_PROXY" = "Y" ]; then \
rm /etc/apt/apt.conf.d/01-apt-proxy; \
fi
COPY --from=base /usr/bin/librespot /usr/bin/librespot

# Add runtime dependencies only
RUN apt-get update
RUN apt-get install -y libasound2
RUN apt-get install -y alsa-utils
RUN apt-get install -y --no-install-recommends pulseaudio-utils
RUN apt-get install -y ca-certificates
RUN apt-get install -y libavahi-compat-libdnssd1

RUN rm -rf /var/lib/apt/lists/*

FROM scratch
COPY --from=base / /
COPY --from=intermediate / /

LABEL maintainer="GioF71"
LABEL source="https://github.com/GioF71/librespot-docker"
Expand Down Expand Up @@ -73,6 +90,7 @@ ENV DISABLE_DISCOVERY=""
ENV DITHER=""

ENV ZEROCONF_PORT=""
ENV ZEROCONF_BACKEND=""

ENV ENABLE_VOLUME_NORMALISATION=""
ENV NORMALISATION_METHOD=""
Expand Down Expand Up @@ -102,17 +120,22 @@ ENV ONEVENT_POST_ENDPOINT=""

ENV ENABLE_OAUTH=""

ENV CARGO_HOME "/cargo-home"
ENV ADDITIONAL_ARGUMENTS=""

VOLUME /data/cache
VOLUME /data/system-cache
VOLUME /user/config

VOLUME /cargo-home

COPY README.md /app/doc/

RUN mkdir -p /app/assets

COPY app/assets/pulse-client-template.conf /app/assets/

RUN which librespot
#RUN which librespot

COPY app/bin/run-librespot.sh /app/bin/
COPY app/bin/read-file.sh /app/bin/
Expand All @@ -122,4 +145,4 @@ COPY app/bin/post-event-data.sh /app/bin/
RUN chmod u+x /app/bin/*.sh

WORKDIR /app/bin
ENTRYPOINT ["/app/bin/run-librespot.sh"]
ENTRYPOINT ["/app/bin/run-librespot.sh"]
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ First and foremost, the reference to the awesome project:

[Librespot](https://github.com/librespot-org/librespot)

I am also currently relying on Raspotify because building images from crates.io fails for armhf platfrom. So here is the reference to this other excellent project:
For a long time, I have also been relying on Raspotify because building images from crates.io fails for armhf platfrom. So here is the reference to this other excellent project:

[Raspotify](https://github.com/dtcooper/raspotify)

Since the first days of 2025, we are building the images directly from source code.

## Links

REPOSITORY TYPE|LINK
:---|:---
Git Repository|[GitHub](https://github.com/giof71/librespot-docker)
Docker Images|[DockerHub](https://hub.docker.com/r/giof71/librespot)

The `latest` image is published daily, so it will include the same version of [Librespot](https://github.com/librespot-org/librespot) included in the current release of [Raspotify](https://github.com/dtcooper/raspotify).

## Why

I prepared this Dockerfile Because I wanted to be able to install librespot easily on any machine (provided the architecture is amd64, armhf or arm64). Also I wanted to be able to configure and govern the parameter easily, maybe through a webapp like Portainer.
Expand All @@ -38,10 +38,11 @@ This command will output one line if the current user does belong to the "docker

The Dockerfile and the included scripts have been tested on the following distros:

- Manjaro Linux with Gnome (amd64)
- Manjaro Linux with Gnome/KDE (amd64)
- Raspberry Pi 3/4 (32 and 64 bit)
- Asus Tinkerboard with DietPi ([don't let that board run at a very low minimum frequency](https://github.com/GioF71/squeezelite-docker/blob/main/doc/asus-tinkerboard.md))
- OSMC on Raspberry Pi 4
- Moode Audio on Raspberry Pi 3/4

As I test the Dockerfile on more platforms, I will update this list.

6DB6 Expand Down Expand Up @@ -90,6 +91,7 @@ AP_PORT||Connect to an AP with a specified port. If no AP with that port is pres
DISABLE_DISCOVERY||Disable zeroconf discovery mode. `Y` or `y` to disable discovery.
DITHER||Dither algorithm: none, gpdf, tpdf, tpdf_hp. Defaults to tpdf for formats S16, S24, S24_3 and none for other formats.
ZEROCONF_PORT||The port the internal server advertises over zeroconf: `1` - `65535`. Ports <= `1024` may require root privileges.
ZEROCONF_BACKEND||Select the desidered backend, valid values are `avahi`, `libmdns`, `dns-sd`. With the latest builds, I am getting good results with `libmdns`, so it will be the default if discovery is not disabled
ENABLE_VOLUME_NORMALISATION||Enables volume normalisation for librespot. `Y` or `y` to enable.
NORMALISATION_METHOD||Specify the normalisation method to use: `basic`, `dynamic`. Defaults to `dynamic`.
NORMALISATION_GAIN_TYPE||Specify the normalisation gain type to use: `track`, `album`, `auto`. Defaults to `auto`.
Expand All @@ -111,6 +113,7 @@ ONEVENT_COMMAND||Specifies the name of a user defined script/executable that wil
ONEVENT_POST_ENDPOINT||Send a `POST` request with event data to the specified endpoint URL whenever a player event occurs. Request body is `json` encoded and contains all available fields specified by the [librespot's player event handler](https://github.com/librespot-org/librespot/blob/dev/src/player_event_handler.rs). Will be ignored if `ONEVENT_COMMAND` is set.
ENABLE_OAUTH||Set to `headless` to enable OAUTH authentication. You will need to run the container interactively the first time. Recommended to enable when caching is also enabled.
LOG_COMMAND_LINE||Set to `Y` or `y` to enable, `N` or `n` to disable. Defaults to `Y`.
ADDITIONAL_ARGUMENTS||Use this to add additional arguments to be appended to the command line

### Volumes

Expand Down
33 changes: 29 additions & 4 deletions app/bin/run-librespot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ current_user_id=$(id -u)
echo "Current user id is [$current_user_id]"

DEFAULT_STARTUP_DELAY_SEC=0
DEFAULT_ZEROCONF_BACKEND=libmdns

# enabled unless explicitly disabled
discovery_enabled=1

declare -A file_dict

Expand All @@ -20,6 +24,7 @@ if [ -f "$CREDENTIALS_FILE" ]; then
SPOTIFY_PASSWORD=$(get_value "SPOTIFY_PASSWORD" $PARAMETER_PRIORITY)
fi

# CMD_LINE="/usr/bin/librespot"
CMD_LINE="/usr/bin/librespot"

DEFAULT_UID=1000
Expand Down Expand Up @@ -128,7 +133,7 @@ if [ -n "$SPOTIFY_PASSWORD" ]; then
CMD_LINE="$CMD_LINE --password '$SPOTIFY_PASSWORD'"
fi

if [ -n "$BACKEND" ]; then
if [ -n "${BACKEND}" ]; then
CMD_LINE="$CMD_LINE --backend $BACKEND"
fi

Expand Down Expand Up @@ -224,14 +229,28 @@ fi

if [ "${DISABLE_DISCOVERY^^}" = "Y" ]; then
CMD_LINE="$CMD_LINE --disable-discovery"
discovery_enabled=0
fi

if [ -n "$DITHER" ]; then
CMD_LINE="$CMD_LINE --dither $DITHER"
fi

if [ -n "$ZEROCONF_PORT" ]; then
CMD_LINE="$CMD_LINE --zeroconf-port $ZEROCONF_PORT"
# zeroconf
if [ $discovery_enabled -eq 1 ]; then
echo "Discovery is enabled."
if [ -n "$ZEROCONF_PORT" ]; then
echo "Using zeroconf port [$ZEROCONF_PORT}]"
CMD_LINE="$CMD_LINE --zeroconf-port $ZEROCONF_PORT"
fi
zeroconf_backend=$DEFAULT_ZEROCONF_BACKEND
if [[ -n "${ZEROCONF_BACKEND}" ]]; then
zeroconf_backend=$ZEROCONF_BACKEND
fi
echo "Using zeroconf backend [${zeroconf_backend}]"
CMD_LINE="$CMD_LINE --zeroconf-backend $zeroconf_backend"
else
echo "Discovery is not enabled."
fi

if [ "${ENABLE_VOLUME_NORMALISATION^^}" = "Y" ]; then
Expand Down Expand Up @@ -301,11 +320,17 @@ if [[ -n "${ENABLE_OAUTH}" ]]; then
fi
fi

if [[ -n "${ADDITIONAL_ARGUMENTS}" ]]; then
echo "ADDITIONAL_ARGUMENTS=[${ADDITIONAL_ARGUMENTS}]"
CMD_LINE="$CMD_LINE ${ADDITIONAL_ARGUMENTS}"
else
echo "Additional arguments have not been specified."
fi

if [[ -z "${LOG_COMMAND_LINE}" || "${LOG_COMMAND_LINE^^}" = "Y" ]]; then
ur=$(printf '*%.0s' $(seq 1 ${#SPOTIFY_USERNAME}))
pr=$(printf '*%.0s' $(seq 1 ${#SPOTIFY_PASSWORD}))
some_asterisks=$(printf '*%.0s' $(seq 1 16))

safe=$CMD_LINE
safe=$(echo "${safe/"$SPOTIFY_USERNAME"/"$some_asterisks"}")
safe=$(echo "${safe/"$SPOTIFY_PASSWORD"/"$some_asterisks"}")
Expand Down
2 changes: 0 additions & 2 deletions app/conf/01-apt-proxy

This file was deleted.

43 changes: 29 additions & 14 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
#!/bin/bash

declare -A rust_images

rust_images[stable]=library/rust:slim
rust_images[bookworm]=library/rust:slim-bookworm
rust_images[bullseye]=library/rust:slim-bullseye

declare -A base_images

base_images[bullseye]=debian:bullseye-slim
base_images[buster]=debian:buster-slim
base_images[bookworm]=debian:bookworm-slim
base_images[kinetic]=ubuntu:kinetic
base_images[focal]=ubuntu:focal
base_images[jammy]=ubuntu:jammy
base_images[stable]=library/debian:stable-slim
base_images[bookworm]=library/debian:bookworm-slim
base_images[bullseye]=library/debian:bullseye-slim

# DEFAULT_RUST_IMAGE=bookworm
# DEFAULT_TAG=latest
DEFAULT_RUST_IMAGE=library/rust:slim
DEFAULT_BASE_IMAGE=library/debian:stable-slim

DEFAULT_BASE_IMAGE=bookworm
DEFAULT_TAG=late E0A5 st
DEFAULT_USE_PROXY=N
DEFAULT_BRANCH=master

tag=$DEFAULT_TAG
use_proxy=$DEFAULT_USE_PROXY
use_branch=$DEFAULT_BRANCH

while getopts b:t:p:v: flag
while getopts r:b:t:p:v: flag
do
case "${flag}" in
r) rust_image=${OPTARG};;
b) base_image=${OPTARG};;
t) tag=${OPTARG};;
p) proxy=${OPTARG};;
v) select_branch=${OPTARG};;
esac
done

echo "rust_image: $rust_image";
echo "base_image: $base_image";
echo "tag: $tag";
echo "proxy: $proxy";
echo "branch: $select_branch"

if [ -z "${rust_image}" ]; then
rust_image=$DEFAULT_RUST_IMAGE
fi

if [ -z "${base_image}" ]; then
base_image=$DEFAULT_BASE_IMAGE
fi
Expand All @@ -47,8 +59,11 @@ if [ -z "${tag}" ]; then
tag="latest"
fi

if [ -n "${select_branch}" ]; then
use_branch=${select_branch}
if [[ -z ${rust_images[$rust_image]} ]]; then
echo "Image for ["$rust_image"] not found"
select_rust_image=${rust_images[$DEFAULT_RUST_IMAGE]}
else
select_rust_image=${rust_images[$rust_image]}
fi

if [[ -z ${base_images[$base_image]} ]]; then
Expand All @@ -58,14 +73,14 @@ else
select_base_image=${base_images[$base_image]}
fi

echo "Rust Image: ["$select_rust_image"]"
echo "Base Image: ["$select_base_image"]"
echo "Tag: ["$tag"]"
echo "Proxy: ["$use_proxy"]"
echo "Branch: ["$use_branch"]"

docker build . \
docker buildx build . \
--build-arg RUST_IMAGE=${select_rust_image} \
--build-arg BASE_IMAGE=${select_base_image} \
--build-arg USE_BRANCH=${use_branch} \
--build-arg USE_APT_PROXY=${use_proxy} \
-t giof71/librespot:$tag

0