]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Added docker.
authorCharles <32498151+charlesomer@users.noreply.github.com>
Thu, 8 Jul 2021 17:29:58 +0000 (18:29 +0100)
committerCharles <32498151+charlesomer@users.noreply.github.com>
Thu, 8 Jul 2021 17:29:58 +0000 (18:29 +0100)
.github/workflows/docker-build-releases.yaml [new file with mode: 0644]
.github/workflows/docker-build.yaml [new file with mode: 0644]
docker/Dockerfile [new file with mode: 0644]
docker/README.md [new file with mode: 0644]
docker/airplay1/Dockerfile [new file with mode: 0644]
docker/airplay1/README.md [new file with mode: 0644]
docker/airplay1/start.sh [new file with mode: 0644]
docker/docker-compose.yaml [new file with mode: 0644]
docker/start.sh [new file with mode: 0644]

diff --git a/.github/workflows/docker-build-releases.yaml b/.github/workflows/docker-build-releases.yaml
new file mode 100644 (file)
index 0000000..745d4ff
--- /dev/null
@@ -0,0 +1,64 @@
+# Builds & pushes a docker image when a release occurs.
+
+# The following tags are created:
+# 'latest' & 'latest-airplay1'
+# '[RELEASE TAG]' & '[RELEASE TAG]-airplay1'
+
+name: Build and push docker images on releases.
+
+on:
+  release:
+    types: [ published ]
+jobs:
+  main:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+          
+      - name: Set SHAIRPORT_SYNC_BRANCH env.
+        run: echo "SHAIRPORT_SYNC_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: ${{ env.DOCKER_REGISTRY }}
+          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: ${{ env.DOCKER_REGISTRY }}/shairport-sync:latest ${{ env.DOCKER_REGISTRY }}/shairport-sync:${{ github.event.release.tag_name }}
+          build-args: |
+            SHAIRPORT_SYNC_BRANCH=${{ env.SHAIRPORT_SYNC_BRANCH }}
+          ssh: default=${{ env.SSH_AUTH_SOCK }} # Can be removed when no longer pulling from private repos.
+
+      - name: Build and push (AirPlay 1)
+        uses: docker/build-push-action@v2
+        with:
+          context: ./
+          file: ./docker/airplay1/Dockerfile-AirPlay1
+          platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm64,linux/arm/v7
+          push: true
+          tags: ${{ env.DOCKER_REGISTRY }}/shairport-sync:latest-airplay1, ${{ env.DOCKER_REGISTRY }}/shairport-sync:${{ github.event.release.tag_name }}-airplay1
+          build-args: |
+            SHAIRPORT_SYNC_BRANCH=${{ env.SHAIRPORT_SYNC_BRANCH }}
\ No newline at end of file
diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml
new file mode 100644 (file)
index 0000000..3a3d839
--- /dev/null
@@ -0,0 +1,62 @@
+# Builds & pushes a docker image when a commit is made to one of the branches specified below.
+# Tag pattern: 'unstable-[BRANCH NAME]'.
+# See docker-build-releases.yaml for release build process.
+
+name: Build and push docker image based on commit to specified branches.
+
+on:
+  push:
+    branches: [ master, development, charles-dev ]
+jobs:
+  main:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+          
+      - name: Set SHAIRPORT_SYNC_BRANCH env.
+        run: echo "SHAIRPORT_SYNC_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: ${{ env.DOCKER_REGISTRY }}
+          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: ${{ env.DOCKER_REGISTRY }}/shairport-sync:unstable-${{ env.SHAIRPORT_SYNC_BRANCH }}
+          build-args: |
+            SHAIRPORT_SYNC_BRANCH=${{ env.SHAIRPORT_SYNC_BRANCH }}
+          ssh: default=${{ env.SSH_AUTH_SOCK }} # Can be removed when no longer pulling from private repos.
+
+      - name: Build and push (AirPlay 1)
+        uses: docker/build-push-action@v2
+        with:
+          context: ./
+          file: ./docker/airplay1/Dockerfile
+          platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm64,linux/arm/v7
+          push: true
+          tags: ${{ env.DOCKER_REGISTRY }}/shairport-sync:unstable-${{ env.SHAIRPORT_SYNC_BRANCH }}-airplay1
+          build-args: |
+            SHAIRPORT_SYNC_BRANCH=${{ env.SHAIRPORT_SYNC_BRANCH }}
\ No newline at end of file
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644 (file)
index 0000000..1203b1c
--- /dev/null
@@ -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 \
+        libgcrypt-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 will be modified by the Github Action Workflow and is required
+# to ensure the correct branch is being used.
+ARG SHAIRPORT_SYNC_BRANCH
+RUN test -n "$SHAIRPORT_SYNC_BRANCH"
+
+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 git clone git@github.com:mikebrady/nqptp.git
+WORKDIR /nqptp
+# Use development branch for now.
+RUN git checkout development
+RUN autoreconf -fi
+RUN ./configure
+RUN make
+RUN make install
+WORKDIR /
+
+WORKDIR /shairport-sync
+COPY . .
+RUN git checkout "$SHAIRPORT_SYNC_BRANCH"
+RUN autoreconf -fi
+# 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 -U add \
+        alsa-lib \
+        dbus \
+        popt \
+        glib \
+        mbedtls \
+        soxr \
+        avahi \
+        libconfig \
+        libsndfile \
+        mosquitto \
+        su-exec \
+        libuuid \
+        ffmpeg \
+        libsodium \
+        libplist \
+        libgcrypt
+
+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/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 (file)
index 0000000..fa2b1b5
--- /dev/null
@@ -0,0 +1,39 @@
+# Shairport Sync Docker Image
+
+Available at: https://hub.docker.com/r/mikebrady/shairport-sync
+
+## Example Docker Compose File
+See the `docker-compose.yaml` file in this folder for an example.
+
+## Basic Usage
+
+```
+$ docker run -d --restart unless-stopped --net host --device /dev/snd \
+    mikebrady/shairport-sync
+```
+The above command will run Shairport Sync as a daemon in a Docker container, accessing the computer's ALSA audio infrastructure. It will send audio to the default output device and make no use of any hardware mixers the default device might have. The AirPlay service name will be the host's `hostname` with the first letter capitalised, e.g. `Ubuntu`.
+
+## Options
+
+Any options you add to the command above will be passed to Shairport Sync. Here is an example:
+```
+$ docker run -d --restart unless-stopped --net host --device /dev/snd \
+    mikebrady/shairport-sync -a DenSystem -- -d hw:0 -c PCM
+```
+This will sent audio to alsa hardware device `hw:0` and make use of the that device's mixer control called `PCM`. The service will be visible as `DenSystem` on the network.
+
+## Configuration File
+
+Edit the configuration file `/etc/shairport-sync.conf` in the container (or use the `-v` option to mirror an external copy of `shairport-sync.conf` in to `/etc/shairport-sync.conf`) to get access to the full range of configuration options.
+
+## Build Example (for arm7 devices)
+
+TODO: remove `--ssh` when going public as this is only for private repos.
+```
+docker buildx build --ssh default=$SSH_AUTH_SOCK --platform linux/arm/v7 -f ./docker/Dockerfile --build-arg SHAIRPORT_SYNC_BRANCH=development -t shairport-sync:unstable-development .
+```
+
+`SHAIRPORT_SYNC_BRANCH` is required to ensure the image is built using the expected branch.
+
+## AirPlay 1 Only
+The AirPlay1 only dockerfile is in the `airplay1` folder. This also includes the `start.sh` script used by the container.
\ No newline at end of file
diff --git a/docker/airplay1/Dockerfile b/docker/airplay1/Dockerfile
new file mode 100644 (file)
index 0000000..e60fd0b
--- /dev/null
@@ -0,0 +1,103 @@
+FROM alpine:3.12 AS builder-base
+# 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
+
+# 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 will be modified by the Github Action Workflow and is required
+# to ensure the correct branch is being used.
+ARG SHAIRPORT_SYNC_BRANCH
+RUN test -n "$SHAIRPORT_SYNC_BRANCH"
+
+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
+
+WORKDIR shairport-sync
+COPY . .
+RUN git checkout "$SHAIRPORT_SYNC_BRANCH"
+RUN autoreconf -fi
+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
+RUN make -j $(nproc)
+RUN make install
+
+# Shairport Sync Runtime System:
+FROM alpine:3.12
+
+RUN apk -U add \
+        alsa-lib \
+        dbus \
+        popt \
+        glib \
+        mbedtls \
+        soxr \
+        avahi \
+        libconfig \
+        libsndfile \
+        mosquitto-libs \
+        su-exec \
+        libgcc \
+        libgc++
+
+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
+
+# 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
+
+COPY ./docker/airplay1/start.sh /
+RUN chmod +x /start.sh
+
+ENTRYPOINT [ "/start.sh" ]
diff --git a/docker/airplay1/README.md b/docker/airplay1/README.md
new file mode 100644 (file)
index 0000000..247754e
--- /dev/null
@@ -0,0 +1,3 @@
+# AirPlay 1 Only Docker Image
+
+See the [Shairport Sync Docker Hub Repo](https://hub.docker.com/r/mikebrady/shairport-sync) for available tags. For the latest build, use `latest-airplay1`.
\ No newline at end of file
diff --git a/docker/airplay1/start.sh b/docker/airplay1/start.sh
new file mode 100644 (file)
index 0000000..f68a122
--- /dev/null
@@ -0,0 +1,13 @@
+#!/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
+
+su-exec shairport-sync shairport-sync $@
\ No newline at end of file
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
new file mode 100644 (file)
index 0000000..74ed09a
--- /dev/null
@@ -0,0 +1,11 @@
+# Example docker compose config.
+
+services:
+  shairport-sync:
+    image: mikebrady/shairport-sync:unstable-development
+    network_mode: host
+    restart: unless-stopped
+    devices:
+      - "/dev/snd"
+    # volumes:
+    #   - ./volumes/shairport-sync/shairport-sync.conf:/etc/shairport-sync.conf # Customised Shairport Sync configuration file.
\ No newline at end of file
diff --git a/docker/start.sh b/docker/start.sh
new file mode 100644 (file)
index 0000000..bb79028
--- /dev/null
@@ -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