From 30e6f2e1c873f64d718f3bca6b91c7dfe171a17b Mon Sep 17 00:00:00 2001 From: duhow Date: Mon, 16 Dec 2024 15:20:08 +0100 Subject: [PATCH 1/3] build in separated stages --- docker/Dockerfile | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 84ba6dcf..4a602941 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,11 +1,7 @@ -FROM alpine:3.17 AS builder +ARG NQPTP_BRANCH=main +ARG SHAIRPORT_SYNC_BRANCH=. -# Check required arguments exist. These will be provided by the Github Action -# Workflow and are required to ensure the correct branches are being used. -ARG SHAIRPORT_SYNC_BRANCH -RUN test -n "$SHAIRPORT_SYNC_BRANCH" -ARG NQPTP_BRANCH -RUN test -n "$NQPTP_BRANCH" +FROM alpine:3.17 AS builder RUN apk -U add \ alsa-lib-dev \ @@ -31,7 +27,8 @@ RUN apk -U add \ xxd ##### ALAC ##### -RUN git clone https://github.com/mikebrady/alac +FROM builder AS alac +RUN git clone --depth=1 https://github.com/mikebrady/alac WORKDIR /alac RUN autoreconf -i RUN ./configure @@ -41,9 +38,10 @@ WORKDIR / ##### ALAC END ##### ##### NQPTP ##### -RUN git clone https://github.com/mikebrady/nqptp +FROM builder AS nqptp +ARG NQPTP_BRANCH +RUN git clone --depth=1 -b "$NQPTP_BRANCH" https://github.com/mikebrady/nqptp WORKDIR /nqptp -RUN git checkout "$NQPTP_BRANCH" RUN autoreconf -i RUN ./configure RUN make @@ -51,6 +49,10 @@ WORKDIR / ##### NQPTP END ##### ##### SPS ##### +# Note: apple-alac requires alac build first. +FROM alac AS shairport-sync +ARG SHAIRPORT_SYNC_BRANCH + WORKDIR /shairport-sync COPY . . RUN git checkout "$SHAIRPORT_SYNC_BRANCH" @@ -96,14 +98,14 @@ RUN apk -U add \ soxr # Copy build files. -COPY --from=builder /shairport-sync/build/install/usr/local/bin/shairport-sync /usr/local/bin/shairport-sync -COPY --from=builder /shairport-sync/build/install/usr/local/share/man/man1 /usr/share/man/man1 -COPY --from=builder /nqptp/nqptp /usr/local/bin/nqptp -COPY --from=builder /usr/local/lib/libalac.* /usr/local/lib/ -COPY --from=builder /shairport-sync/build/install/etc/shairport-sync.conf /etc/ -COPY --from=builder /shairport-sync/build/install/etc/shairport-sync.conf.sample /etc/ -COPY --from=builder /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-dbus.conf /etc/dbus-1/system.d/ -COPY --from=builder /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-mpris.conf /etc/dbus-1/system.d/ +COPY --from=shairport-sync /shairport-sync/build/install/usr/local/bin/shairport-sync /usr/local/bin/shairport-sync +COPY --from=shairport-sync /shairport-sync/build/install/usr/local/share/man/man1 /usr/share/man/man1 +COPY --from=nqptp /nqptp/nqptp /usr/local/bin/nqptp +COPY --from=alac /usr/local/lib/libalac.* /usr/local/lib/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/shairport-sync.conf /etc/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/shairport-sync.conf.sample /etc/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-dbus.conf /etc/dbus-1/system.d/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-mpris.conf /etc/dbus-1/system.d/ COPY ./docker/etc/s6-overlay/s6-rc.d /etc/s6-overlay/s6-rc.d COPY ./docker/etc/pulse /etc/pulse From c6fe951cb71a2b247f06b57103b36824e986303b Mon Sep 17 00:00:00 2001 From: duhow Date: Mon, 16 Dec 2024 15:27:53 +0100 Subject: [PATCH 2/3] set executable files --- docker/etc/s6-overlay/s6-rc.d/01-startup/script.sh | 0 docker/run.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 docker/etc/s6-overlay/s6-rc.d/01-startup/script.sh mode change 100644 => 100755 docker/run.sh diff --git a/docker/etc/s6-overlay/s6-rc.d/01-startup/script.sh b/docker/etc/s6-overlay/s6-rc.d/01-startup/script.sh old mode 100644 new mode 100755 diff --git a/docker/run.sh b/docker/run.sh old mode 100644 new mode 100755 From 77e1d28472d76d1b9ed309cafe8c6581aee4a48e Mon Sep 17 00:00:00 2001 From: duhow Date: Mon, 16 Dec 2024 15:33:19 +0100 Subject: [PATCH 3/3] shrink instructions to reduce layers build --- docker/Dockerfile | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 4a602941..21d6790d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -67,6 +67,28 @@ RUN DESTDIR=install make install WORKDIR / ##### SPS END ##### +##### STATIC FILES ##### +FROM scratch AS files + +# Add run script that will start SPS +COPY --chmod=755 ./docker/run.sh ./run.sh +COPY ./docker/etc/s6-overlay/s6-rc.d /etc/s6-overlay/s6-rc.d +COPY ./docker/etc/pulse /etc/pulse +##### END STATIC FILES ##### + +##### BUILD FILES ##### +FROM scratch AS build-files + +COPY --from=shairport-sync /shairport-sync/build/install/usr/local/bin/shairport-sync /usr/local/bin/shairport-sync +COPY --from=shairport-sync /shairport-sync/build/install/usr/local/share/man/man1 /usr/share/man/man1 +COPY --from=nqptp /nqptp/nqptp /usr/local/bin/nqptp +COPY --from=alac /usr/local/lib/libalac.* /usr/local/lib/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/shairport-sync.conf /etc/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/shairport-sync.conf.sample /etc/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-dbus.conf /etc/dbus-1/system.d/ +COPY --from=shairport-sync /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-mpris.conf /etc/dbus-1/system.d/ +##### END BUILD FILES ##### + # Shairport Sync Runtime System FROM crazymax/alpine-s6:3.17-3.1.1.2 @@ -95,39 +117,23 @@ RUN apk -U add \ mandoc \ mosquitto \ popt \ - soxr + soxr && \ + rm -rfv /lib/apk/db/* && \ + rm -rfv /etc/avahi/services/*.service && \ + addgroup shairport-sync && \ + adduser -D shairport-sync -G shairport-sync && \ + addgroup -g 29 docker_audio && \ + addgroup shairport-sync docker_audio && \ + addgroup shairport-sync audio -# Copy build files. -COPY --from=shairport-sync /shairport-sync/build/install/usr/local/bin/shairport-sync /usr/local/bin/shairport-sync -COPY --from=shairport-sync /shairport-sync/build/install/usr/local/share/man/man1 /usr/share/man/man1 -COPY --from=nqptp /nqptp/nqptp /usr/local/bin/nqptp -COPY --from=alac /usr/local/lib/libalac.* /usr/local/lib/ -COPY --from=shairport-sync /shairport-sync/build/install/etc/shairport-sync.conf /etc/ -COPY --from=shairport-sync /shairport-sync/build/install/etc/shairport-sync.conf.sample /etc/ -COPY --from=shairport-sync /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-dbus.conf /etc/dbus-1/system.d/ -COPY --from=shairport-sync /shairport-sync/build/install/etc/dbus-1/system.d/shairport-sync-mpris.conf /etc/dbus-1/system.d/ - -COPY ./docker/etc/s6-overlay/s6-rc.d /etc/s6-overlay/s6-rc.d -COPY ./docker/etc/pulse /etc/pulse -RUN chmod +x /etc/s6-overlay/s6-rc.d/01-startup/script.sh +# Remove anything we don't need. +# Remove any statically-defined Avahi services, e.g. SSH and SFTP # Create non-root user for running the container -- running as the user 'shairport-sync' also allows # Shairport Sync to provide the D-Bus and MPRIS interfaces within the container - -RUN addgroup shairport-sync -RUN adduser -D shairport-sync -G shairport-sync - # Add the shairport-sync user to the pre-existing audio group, which has ID 29, for access to the ALSA stuff -RUN addgroup -g 29 docker_audio && addgroup shairport-sync docker_audio && addgroup shairport-sync audio -# Remove anything we don't need. -RUN rm -rf /lib/apk/db/* - -# Remove any statically-defined Avahi services, e.g. SSH and SFTP -RUN rm -rf /etc/avahi/services/*.service - -# Add run script that will start SPS -COPY ./docker/run.sh ./run.sh -RUN chmod +x /run.sh +COPY --from=files / / +COPY --from=build-files / / ENTRYPOINT ["/init","./run.sh"]