Skip to content

Commit

Permalink
[Enhancement] Distinct builds for alsa and pulseaudio #254 (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 authored Dec 30, 2023
1 parent f8663c4 commit ba52271
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 113 deletions.
51 changes: 25 additions & 26 deletions .github/workflows/docker-multi-arch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -108,34 +112,29 @@ 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}"]"
tags="$tags,${select_special_tags}"
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}"]"
Expand Down
25 changes: 10 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 \
Expand All @@ -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 / /

Expand Down
22 changes: 18 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ 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

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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions doc/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions install/install-dep.sh
Original file line number Diff line number Diff line change
@@ -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
63 changes: 0 additions & 63 deletions install/install-script.sh

This file was deleted.

83 changes: 78 additions & 5 deletions install/installer.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,81 @@
#!/bin/bash

echo ${0}
echo ${1}
export DOWNLOADED_BIN=${1}
echo $DOWNLOADED_BIN
set -ex

/bin/bash install-script.sh
# 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

0 comments on commit ba52271

Please sign in to comment.