diff --git a/.github/workflows/docker-build-master.yaml b/.github/workflows/docker-build-master.yaml new file mode 100644 index 00000000..71ca9d87 --- /dev/null +++ b/.github/workflows/docker-build-master.yaml @@ -0,0 +1,42 @@ +# Pushes to tag 'unstable-BRANCH'. +# Releases are pushed to latest and tagged - see docker-build-releases.yaml. + +name: Build and push docker image based on master branch. + +on: + push: + branches: [ master, development ] + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set branch env. + run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + - name: Set up ssh agent + uses: webfactory/ssh-agent@v0.5.2 # Can be removed when no longer pulling from private repos. + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to Docker Registry + uses: docker/login-action@v1 + with: + registry: registry.nova.do + username: ${{ secrets.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./docker/Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm64,linux/arm/v7 + push: true + tags: registry.nova.do/shairport-sync:unstable-${{ env.BRANCH }} + build-args: | + BRANCH=${{ env.BRANCH }} + ssh: github=${{ env.SSH_AUTH_SOCK }} # Can be removed when no longer pulling from private repos. \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..d12ad352 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,137 @@ +FROM alpine:3.12 AS builder-base +# Version 3.12 is required for now since libplist has breaking changes in v3.13 and above which are not yet standard +# in debian/ubuntu. + +# General Build System: +RUN apk -U add \ + git \ + build-base \ + autoconf \ + automake \ + libtool \ + dbus \ + su-exec \ + alsa-lib-dev \ + libdaemon-dev \ + popt-dev \ + mbedtls-dev \ + soxr-dev \ + avahi-dev \ + libconfig-dev \ + libsndfile-dev \ + mosquitto-dev \ + xmltoman \ + openssh-client \ + libsodium-dev \ + ffmpeg-dev \ + xxd \ + libressl-dev \ + openssl-dev \ + libplist-dev + +# ALAC Build System: +FROM builder-base AS builder-alac + +RUN git clone https://github.com/mikebrady/alac +WORKDIR /alac +RUN autoreconf -fi +RUN ./configure +RUN make +RUN make install + +# Shairport Sync Build System: +FROM builder-base AS builder-sps + +# This may be modified by the Github Action Workflow. +ARG SHAIRPORT_SYNC_BRANCH=development + +COPY --from=builder-alac /usr/local/lib/libalac.* /usr/local/lib/ +COPY --from=builder-alac /usr/local/lib/pkgconfig/alac.pc /usr/local/lib/pkgconfig/alac.pc +COPY --from=builder-alac /usr/local/include /usr/local/include + +# TODO: Remove when no longer pulling from private repos. +RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts + +RUN --mount=type=ssh,id=github git clone git@github.com:charlesomer/nqptp.git +WORKDIR /nqptp +# Use development branch for now. +RUN git checkout development +RUN autoreconf -fi +RUN ./configure +RUN make +RUN make install +WORKDIR / + +RUN --mount=type=ssh,id=github git clone git@github.com:aillwee/shairport-sync.git +WORKDIR /shairport-sync +RUN git checkout "$SHAIRPORT_SYNC_BRANCH" +RUN autoreconf -fi +RUN git submodule init +RUN git submodule update +# RUN ./configure \ +# --with-alsa \ +# --with-dummy \ +# --with-pipe \ +# --with-stdout \ +# --with-avahi \ +# --with-ssl=mbedtls \ +# --with-soxr \ +# --sysconfdir=/etc \ +# --with-dbus-interface \ +# --with-mpris-interface \ +# --with-mqtt-client \ +# --with-apple-alac \ +# --with-convolution \ +# --with-airplay-2 +# RUN make -j $(nproc) +RUN CFLAGS="-O0 -g" CXXFLAGS="-O0 -g" ./configure --sysconfdir=/etc --with-metadata --with-dummy --with-pipe \ + --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-dbus-interface --with-stdout \ + --with-mpris-interface --with-mqtt-client --with-apple-alac --with-convolution --with-airplay-2 +RUN make -j +RUN make install + +# Shairport Sync Runtime System: +FROM alpine:3.12 + +RUN apk add \ + alsa-lib \ + dbus \ + popt \ + glib \ + mbedtls \ + soxr \ + avahi \ + libconfig \ + libsndfile \ + mosquitto-libs \ + su-exec \ + libuuid \ + ffmpeg-dev \ + ffmpeg-libs \ + libsodium-dev \ + libplist-dev + +RUN rm -rf /lib/apk/db/* + +COPY --from=builder-alac /usr/local/lib/libalac.* /usr/local/lib/ +COPY --from=builder-sps /etc/shairport-sync* /etc/ +COPY --from=builder-sps /etc/dbus-1/system.d/shairport-sync-dbus.conf /etc/dbus-1/system.d/ +COPY --from=builder-sps /etc/dbus-1/system.d/shairport-sync-mpris.conf /etc/dbus-1/system.d/ +COPY --from=builder-sps /usr/local/bin/shairport-sync /usr/local/bin/shairport-sync +COPY --from=builder-sps /usr/local/bin/nqptp /usr/local/bin/nqptp + +# 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 + +COPY ./docker/shairport-sync.conf /etc/shairport-sync.conf +COPY ./docker/start.sh / + +RUN chmod +x ./start.sh + +ENTRYPOINT [ "/start.sh" ] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..74b986ca --- /dev/null +++ b/docker/README.md @@ -0,0 +1,3 @@ +# Shairport Sync Docker Image + +https://hub.docker.com/r/mikebrady/shairport-sync \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 00000000..4153577a --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,12 @@ +# Example docker compose config. + +version: "3.8" +services: + shairport-sync: + image: registry.nova.do/shairport-sync:unstable-development + network_mode: host + restart: unless-stopped + devices: + - "/dev/snd" + volumes: + - ./volumes/shairport-sync/shairport-sync.conf:/etc/shairport-sync.conf \ No newline at end of file diff --git a/docker/shairport-sync.conf b/docker/shairport-sync.conf new file mode 100644 index 00000000..bb447958 --- /dev/null +++ b/docker/shairport-sync.conf @@ -0,0 +1,14 @@ +# Temp sample Configuration File for Shairport Sync on a Raspberry Pi using the built-in audio DAC. +general = +{ + volume_range_db = 60; +}; + +alsa = +{ + output_device = "hw:0"; + # Could also be hw:1. aplay -l should help identify the correct one. + # e.g. card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones] + # card x where x is the number to use above in hw:x + mixer_control_name = "Headphone"; +}; \ No newline at end of file diff --git a/docker/start.sh b/docker/start.sh new file mode 100644 index 00000000..bb790283 --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +rm -rf /var/run/dbus.pid +#mkdir -p /var/run/dbus + +dbus-uuidgen --ensure +dbus-daemon --system + +avahi-daemon --daemonize --no-chroot + +# TODO: This should probably be implemented in a better way and using the correct nqptp group. +nqptp & + +# su-exec shairport-sync shairport-sync $@ + +shairport-sync -vu --statistics \ No newline at end of file