From ba5227186de70df60c58ed49d72c200f1349a0bb Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Sat, 30 Dec 2023 19:28:39 +0100 Subject: [PATCH] [Enhancement] Distinct builds for alsa and pulseaudio #254 (#255) --- .github/workflows/docker-multi-arch.yml | 51 ++++++++------- Dockerfile | 25 +++----- build.sh | 22 +++++-- doc/release.md | 1 + install/install-dep.sh | 14 +++++ install/install-script.sh | 63 ------------------- install/installer.sh | 83 +++++++++++++++++++++++-- 7 files changed, 146 insertions(+), 113 deletions(-) create mode 100644 install/install-dep.sh delete mode 100644 install/install-script.sh diff --git a/.github/workflows/docker-multi-arch.yml b/.github/workflows/docker-multi-arch.yml index 9a9bb30..7db9712 100644 --- a/.github/workflows/docker-multi-arch.yml +++ b/.github/workflows/docker-multi-arch.yml @@ -16,8 +16,16 @@ jobs: strategy: fail-fast: false matrix: - base: ["stable"] - sourceforge: ["Y", "N"] + base: [ stable ] + sourceforge: [ Y, N] + build_mode: [ full, pulse, alsa ] + #exclude: + # - base: stable + # sourceforge: Y + # build_mode: alsa + # - base: stable + # sourceforge: Y + # build_mode: pulse steps: - name: Checkout @@ -55,24 +63,20 @@ jobs: declare -A sl_versions sl_versions[stable]=1.9.9 - sl_versions[bookworm]=1.9.9 - sl_versions[trixie]=1.9.9 - sl_versions[sid]=1.9.9 declare -A special_tags - special_tags[stable-N]="${image_name}:latest,${image_name}:stable" - special_tags[stable-Y]="${image_name}:sourceforge-latest,${image_name}:sourceforge-stable" - special_tags[bookworm-N]="${image_name}:latest,${image_name}:stable" - special_tags[bookworm-Y]="${image_name}:sourceforge-latest,${image_name}:sourceforge-stable" - special_tags[trixie-N]="${image_name}:nextstable" - special_tags[trixie-Y]="${image_name}:sourceforge-nextstable" - special_tags[sid-Y]="${image_name}:sourceforge-edge" - special_tags[sid-N]="${image_name}:edge" + special_tags[stable-N-full]="${image_name}:latest,${image_name}:stable" + special_tags[stable-N-alsa]="${image_name}:latest-alsa,${image_name}:stable-alsa" + special_tags[stable-N-pulse]="${image_name}:latest-pulse,${image_name}:stable-pulse" + special_tags[stable-Y-full]="${image_name}:sourceforge-latest,${image_name}:sourceforge-stable" + special_tags[stable-Y-alsa]="${image_name}:sourceforge-latest-alsa,${image_name}:sourceforge-stable-alsa" + special_tags[stable-Y-pulse]="${image_name}:sourceforge-latest-pulse,${image_name}:sourceforge-stable-pulse" declare -A distro_friendly_name_dict distro_friendly_name_dict[stable]=debian distro_friendly_name=${{ matrix.base }} + build_mode=${{ matrix.build_mode }} lookup_distro_name=${distro_friendly_name_dict[${{ matrix.base }}]} if [ -n "${lookup_distro_name}" ]; then distro_friendly_name=$lookup_distro_name @@ -108,11 +112,11 @@ jobs: echo "tag_name=[$tag_name]" if [[ "${tag_type}" == "release" || "${tag_type}" == "v" ]]; then echo "release tag" - tags="$image_name:${distro_friendly_name}-${squeezelite_version_str}" - tags="$tags,$image_name:${distro_friendly_name}-${squeezelite_version_str}-${tag_name}" - special_tag_lookup="${{ matrix.base }}-${{ matrix.sourceforge }}" + tags="$image_name:${distro_friendly_name}-${build_mode}-${squeezelite_version_str}" + tags="$tags,$image_name:${distro_friendly_name}-${build_mode}-${squeezelite_version_str}-${tag_name}" + special_tag_lookup="${{ matrix.base }}-${{ matrix.sourceforge }}-${{ matrix.build_mode }}" select_special_tags=${special_tags["${special_tag_lookup}"]} - building_now="${distro_friendly_name}-${{ matrix.sourceforge }}" + building_now="${distro_friendly_name}-${build_mode}-${{ matrix.sourceforge }}" echo "Building now: ["$building_now"]" if [[ -n "${select_special_tags}" ]]; then echo "Found special tags for ["${building_now}"]=["${select_special_tags}"]" @@ -120,22 +124,17 @@ jobs: else echo "No special tags found for ["${building_now}"]" fi - if [ ${{ matrix.sourceforge }} = "N" ]; then - tags="${tags},$image_name:${distro_friendly_name}" - else - tags="${tags},$image_name:${distro_friendly_name}-sourceforge" - fi elif [[ "${tag_type}" == "feature" || "${tag_type}" == "f" ]]; then echo "feature tag" - tags="${image_name}:feature-${tag_name}-${distro_friendly_name}-${squeezelite_version_str}" + tags="${image_name}:feature-${tag_name}-${distro_friendly_name}-${build_mode}-${squeezelite_version_str}" elif [[ "${tag_type}" = "daily" || "${tag_type}" = "d" ]]; then echo "daily build" if [ ${{ matrix.sourceforge }} = "N" ]; then - tags="${tags},${image_name}:daily-${distro_friendly_name}" + tags="${tags},${image_name}:daily-${distro_friendly_name}-${build_mode}" else - tags="${tags},${image_name}:daily-${distro_friendly_name}-sourceforge" + tags="${tags},${image_name}:daily-${distro_friendly_name}-${build_mode}-sourceforge" fi - tags="${tags},${image_name}:daily-${distro_friendly_name}-${squeezelite_version_str}" + tags="${tags},${image_name}:daily-${distro_friendly_name}-${build_mode}-${squeezelite_version_str}" fi fi echo "Building tags: ["${tags}"]" diff --git a/Dockerfile b/Dockerfile index abb9cae..b431b8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ ARG BASE_IMAGE FROM ${BASE_IMAGE} AS BASE ARG DOWNLOAD_FROM_SOURCEFORGE +ARG BUILD_MODE ARG USE_APT_PROXY RUN mkdir -p /app/conf @@ -16,26 +17,24 @@ RUN if [ "${USE_APT_PROXY}" = "Y" ]; then \ echo "Building without apt proxy"; \ fi -# update indexes -RUN apt-get update +# copy installer files +RUN mkdir -p /app/install -# install pulseaudio -RUN apt-get install pulseaudio --no-install-recommends -y +COPY install/install-dep.sh /app/install/ +RUN chmod u+x /app/install/install-dep.sh -# install alsa libraries -RUN apt-get install libasound2 --no-install-recommends -y +RUN /app/install/install-dep.sh +RUN rm /app/install/install-dep.sh -# copy installer files -RUN mkdir -p /app/bin -RUN mkdir -p /app/install COPY install/installer.sh /app/install/ -COPY install/install-script.sh /app/install/ RUN chmod u+x /app/install/* WORKDIR /app/install +RUN mkdir -p /app/bin + # execute installation -RUN ./installer.sh $DOWNLOAD_FROM_SOURCEFORGE +RUN /app/install/installer.sh # cleanup apt proxy config RUN if [ "${USE_APT_PROXY}" = "Y" ]; then \ @@ -48,10 +47,6 @@ RUN rm -rf /var/lib/apt/lists/* # remove scripts RUN rm -Rf /app/install -## test binary in both cases -RUN /app/bin/squeezelite -? -RUN /app/bin/squeezelite-pulseaudio -? - FROM scratch COPY --from=BASE / / diff --git a/build.sh b/build.sh index ee9a524..8d7806f 100755 --- a/build.sh +++ b/build.sh @@ -49,13 +49,14 @@ DEFAULT_USE_PROXY=N download=$DEFAULT_SOURCEFORGE_DOWNLOAD tag=$DEFAULT_TAG -while getopts b:d:t:p: flag +while getopts b:d:t:p:m: flag do case "${flag}" in b) base_image=${OPTARG};; d) download=${OPTARG};; t) tag=${OPTARG};; p) proxy=${OPTARG};; + m) build_mode=${OPTARG};; esac done @@ -63,6 +64,7 @@ echo "Input: base_image = [$base_image]"; echo "Input: Download from SourceForge = [$sd]"; echo "Input: Image Tag = [$tag]"; echo "Input: Proxy = [$proxy]"; +echo "Input: Build mode = [$build_mode]"; if [ -z "${base_image}" ]; then base_image=$DEFAULT_BASE_IMAGE @@ -90,22 +92,34 @@ fi if [ -z "${proxy}" ]; then proxy="N" fi -if [[ "${proxy}" == "Y" || "${proxy}" == "y" ]]; then +if [[ "${proxy^^}" == "Y" || "${proxy^^}" == "YES" ]]; then proxy="Y" -elif [[ "${proxy}" == "N" || "${proxy}" == "n" ]]; then +elif [[ "${proxy^^}" == "N" || "${proxy^^}" == "NO" ]]; then proxy="N" else echo "invalid proxy parameter ["${proxy}"]" exit 4 fi +if [[ -z "${build_mode}" ]]; then + build_mode=full +else + if [[ ! "${build_mode^^}" == "ALSA" ]] && [[ ! "${build_mode^^}" == "PULSE" ]] && [[ ! "${build_mode^^}" == "FULL" ]]; then + echo "invalid build_mode parameter ["${build_mode}"]" + exit 4 + fi +fi + echo "Build Argument: Base Image = ["$expanded_base_image"]" echo "Build Argument: Download from SourceForge = ["$download"]" echo "Build Argument: Image Tag = ["$tag"]" +echo "Build Argument: Build Mode = ["$build_mode"]" echo "Build Argument: Proxy = ["$proxy"]" docker build . \ --build-arg BASE_IMAGE=${expanded_base_image} \ --build-arg DOWNLOAD_FROM_SOURCEFORGE=${download} \ + --build-arg BUILD_MODE=${build_mode} \ --build-arg USE_APT_PROXY=${proxy} \ - -t giof71/squeezelite:$tag + -t giof71/squeezelite:$tag \ + --progress=plain diff --git a/doc/release.md b/doc/release.md index b05618c..894e19e 100644 --- a/doc/release.md +++ b/doc/release.md @@ -10,6 +10,7 @@ Older build might be dropped in order to save space on docker-hub and incur in l Date|Type|Description :---|:---|:--- +2023-12-30|Improvement|Separate builds for alsa and pulseaudio (see [#254](https://github.com/GioF71/squeezelite-docker/issues/254)) 2023-12-18|Improvement|Support for a config file prefix (see [#249](https://github.com/GioF71/squeezelite-docker/issues/249)) 2023-12-18|Improvement|Autogen mac address (see [#247](https://github.com/GioF71/squeezelite-docker/issues/247)) 2023-12-18|Improvement|Arguments in quotes (see [#245](https://github.com/GioF71/squeezelite-docker/issues/245)) diff --git a/install/install-dep.sh b/install/install-dep.sh new file mode 100644 index 0000000..aacddf9 --- /dev/null +++ b/install/install-dep.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +apt-get update + +if [[ -z "${BUILD_MODE^^}" ]] || [[ "${BUILD_MODE^^}" == "FULL" ]] || [[ "${BUILD_MODE^^}" == "ALSA" ]]; then + echo "Installing support for Alsa ..." + apt-get install libasound2 --no-install-recommends -y + echo "Support for Alsa installed." +fi +if [[ -z "${BUILD_MODE^^}" ]] || [[ "${BUILD_MODE^^}" == "FULL" ]] || [[ "${BUILD_MODE^^}" == "PULSE" ]]; then + echo "Installing support for PulseAudio ..." + apt-get install pulseaudio --no-install-recommends -y + echo "Support for PulseAudio installed." +fi diff --git a/install/install-script.sh b/install/install-script.sh deleted file mode 100644 index 951b423..0000000 --- a/install/install-script.sh +++ /dev/null @@ -1,63 +0,0 @@ -set -ex - -# Error codes -# 1 Unsupported platform - -ARCH=`uname -m` -OUTPUT_FILE=/app/bin/squeezelite -OUTPUT_FILE_PULSE=/app/bin/squeezelite-pulseaudio -echo "Architecture: ${ARCH}" - -arch_amd64=x86_64 -arch_arm_v7=armv7l -arch_arm_v8=aarch64 - -declare -A download_url_dict_alsa -download_url_dict_alsa[$arch_amd64]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-1.9.9.1432-x86_64.tar.gz/download" -download_url_dict_alsa[$arch_arm_v7]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-1.9.9.1430-armhf.tar.gz/download" -download_url_dict_alsa[$arch_arm_v8]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-1.9.9.1428-aarch64.tar.gz/download" - -declare -A download_url_dict_pulse -download_url_dict_pulse[$arch_amd64]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-pulse-1.9.9.1432-x86_64.tar.gz/download" -download_url_dict_pulse[$arch_arm_v7]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-pulse-1.9.9.1392-armhf.tar.gz/download" -download_url_dict_pulse[$arch_arm_v8]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-pulse-1.9.9.1428-aarch64.tar.gz/download" - -if [ "$DOWNLOADED_BIN" == "Y" ]; then - apt-get install wget -y - ARCH=`uname -m` - mkdir /assets - mkdir -p /assets/sourceforge - SL_URL=${download_url_dict_alsa["${ARCH}"]}; - if [[ -n "${SL_URL}" ]]; then - echo "Found Alsa version for architecture ${ARCH}, downloading ..." - wget $SL_URL -O /assets/sourceforge/squeezelite.tar.gz - mkdir /assets/sourceforge/expanded - tar xzvf /assets/sourceforge/squeezelite.tar.gz -C /assets/sourceforge/expanded - ls -la /assets/sourceforge/expanded/ - mv /assets/sourceforge/expanded/squeezelite $OUTPUT_FILE - else - echo "NOT Found Alsa version for architecture ${ARCH}. This was mandatory, exiting!" - exit 1 - fi - SL_URL_PULSE=${download_url_dict_pulse["${ARCH}"]}; - if [[ -n "${SL_URL_PULSE}" ]]; then - echo "Found PulseAudio version for architecture ${ARCH}, downloading ..." - wget $SL_URL_PULSE -O /assets/sourceforge/squeezelite-pulse.tar.gz - mkdir /assets/sourceforge/expanded-pulse - tar xzvf /assets/sourceforge/squeezelite-pulse.tar.gz -C /assets/sourceforge/expanded-pulse - ls -la /assets/sourceforge/expanded-pulse/ - mv /assets/sourceforge/expanded-pulse/squeezelite $OUTPUT_FILE_PULSE - else - echo "NOT Found PulseAudio version for architecture ${ARCH}. This was not mandatory." - fi - # cleanup - apt-get purge wget -y - apt-get autoremove -y - rm -Rf /assets -else - apt-get install squeezelite --no-install-recommends -y - cp /usr/bin/squeezelite /app/bin/squeezelite - apt-get install squeezelite-pulseaudio --no-install-recommends -y - cp /usr/bin/squeezelite-pulseaudio /app/bin/squeezelite-pulseaudio - apt-get remove squeezelite* -y -fi \ No newline at end of file diff --git a/install/installer.sh b/install/installer.sh index ca0c202..533ad6b 100644 --- a/install/installer.sh +++ b/install/installer.sh @@ -1,8 +1,81 @@ #!/bin/bash -echo ${0} -echo ${1} -export DOWNLOADED_BIN=${1} -echo $DOWNLOADED_BIN +set -ex -/bin/bash install-script.sh \ No newline at end of file +# Error codes +# 1 Unsupported platform + +ARCH=`uname -m` + +echo "install-script.sh: BUILD_MODE=[${BUILD_MODE}]" +echo "install-script.sh: DOWNLOAD_FROM_SOURCEFORGE=[${DOWNLOAD_FROM_SOURCEFORGE}]" +echo "install-script.sh: Architecture: ${ARCH}" + +OUTPUT_FILE=/app/bin/squeezelite +OUTPUT_FILE_PULSE=/app/bin/squeezelite-pulseaudio + +arch_amd64=x86_64 +arch_arm_v7=armv7l +arch_arm_v8=aarch64 + +declare -A download_url_dict_alsa +download_url_dict_alsa[$arch_amd64]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-1.9.9.1432-x86_64.tar.gz/download" +download_url_dict_alsa[$arch_arm_v7]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-1.9.9.1430-armhf.tar.gz/download" +download_url_dict_alsa[$arch_arm_v8]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-1.9.9.1428-aarch64.tar.gz/download" + +declare -A download_url_dict_pulse +download_url_dict_pulse[$arch_amd64]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-pulse-1.9.9.1432-x86_64.tar.gz/download" +download_url_dict_pulse[$arch_arm_v7]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-pulse-1.9.9.1392-armhf.tar.gz/download" +download_url_dict_pulse[$arch_arm_v8]="https://sourceforge.net/projects/lmsclients/files/squeezelite/linux/squeezelite-pulse-1.9.9.1428-aarch64.tar.gz/download" + +if [ "$DOWNLOADED_BIN" == "Y" ]; then + apt-get install wget -y + ARCH=`uname -m` + mkdir /assets + mkdir -p /assets/sourceforge + if [[ "${BUILD_MODE^^}" == "FULL" ]] || [[ "${BUILD_MODE^^}" == "ALSA" ]]; then + SL_URL=${download_url_dict_alsa["${ARCH}"]}; + if [[ -n "${SL_URL}" ]]; then + echo "Found Alsa version for architecture ${ARCH}, downloading ..." + wget $SL_URL -O /assets/sourceforge/squeezelite.tar.gz + mkdir /assets/sourceforge/expanded + tar xzvf /assets/sourceforge/squeezelite.tar.gz -C /assets/sourceforge/expanded + ls -la /assets/sourceforge/expanded/ + mv /assets/sourceforge/expanded/squeezelite $OUTPUT_FILE + else + echo "NOT Found Alsa version for architecture ${ARCH}. This was mandatory, exiting!" + exit 1 + fi + fi + if [[ "${BUILD_MODE^^}" == "FULL" ]] || [[ "${BUILD_MODE^^}" == "PULSE" ]]; then + SL_URL_PULSE=${download_url_dict_pulse["${ARCH}"]}; + if [[ -n "${SL_URL_PULSE}" ]]; then + echo "Found PulseAudio version for architecture ${ARCH}, downloading ..." + wget $SL_URL_PULSE -O /assets/sourceforge/squeezelite-pulse.tar.gz + mkdir /assets/sourceforge/expanded-pulse + tar xzvf /assets/sourceforge/squeezelite-pulse.tar.gz -C /assets/sourceforge/expanded-pulse + ls -la /assets/sourceforge/expanded-pulse/ + mv /assets/sourceforge/expanded-pulse/squeezelite $OUTPUT_FILE_PULSE + else + echo "NOT Found PulseAudio version for architecture ${ARCH}. This was not mandatory." + fi + fi + # cleanup + apt-get purge wget -y + apt-get autoremove -y + rm -Rf /assets +else + if [[ "${BUILD_MODE^^}" == "FULL" ]] || [[ "${BUILD_MODE^^}" == "ALSA" ]]; then + echo "Installing ALSA ..." + apt-get install squeezelite --no-install-recommends -y + cp /usr/bin/squeezelite /app/bin/squeezelite + echo "Installed ALSA." + fi + if [[ "${BUILD_MODE^^}" == "FULL" ]] || [[ "${BUILD_MODE^^}" == "PULSE" ]]; then + echo "Installing Pulse ..." + apt-get install squeezelite-pulseaudio --no-install-recommends -y + cp /usr/bin/squeezelite-pulseaudio /app/bin/squeezelite-pulseaudio + echo "Installed PULSE." + fi + apt-get remove squeezelite* -y +fi \ No newline at end of file