]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Add initial support for Docker Hub / GitHub Actions integration.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 3 Jul 2020 15:15:04 +0000 (16:15 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 3 Jul 2020 15:15:04 +0000 (16:15 +0100)
.github/workflows/docker.yml [new file with mode: 0644]
Dockerfile [new file with mode: 0644]
docker/start.sh [new file with mode: 0755]

diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644 (file)
index 0000000..4160499
--- /dev/null
@@ -0,0 +1,69 @@
+name: Docker
+
+# Thanks to Ryan Govostes <https://github.com/rgov> for this workflow
+
+on:
+  push:
+    # Publish `master` as Docker `latest` image.
+    branches:
+      - master
+
+    # Publish `1.2.3` tags as releases.
+    tags:
+      - '*'
+
+  # Run a test build for any PRs.
+  pull_request:
+
+env:
+  IMAGE_NAME: mikebrady/shairport-sync
+#  DOCKER_PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
+  DOCKER_PLATFORMS: linux/arm/v6
+  DOCKER_HUB_USER: mikebrady
+
+jobs:
+  # Build the container image for multiple architectures
+  build:
+    runs-on: ubuntu-latest
+
+    steps:
+      # This unusual setup is due to limitations with `docker buildx`. 
+      # See: https://github.com/crazy-max/ghaction-docker-buildx/issues/134
+      - name: Prepare
+        id: prepare
+        run: |
+          # Map git ref branch or tag name to Docker tag version
+          VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
+          [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
+          [ "$VERSION" == "master" ] && VERSION=latest && SHAIRPORT_SYNC_BRANCH=master
+          
+          # If tagged with a version, build the same version of Shairport Sync
+          [ "$VERSION" != "latest" ] && SHAIRPORT_SYNC_BRANCH=tags/$VERSION
+
+          # Output build arguments for downstream steps
+          echo ::set-output name=buildx_args::\
+            --platform ${DOCKER_PLATFORMS} \
+            --build-arg SHAIRPORT_SYNC_BRANCH=${SHAIRPORT_SYNC_BRANCH} \
+            --tag ${IMAGE_NAME}:${VERSION} \
+            .
+
+      - uses: actions/checkout@v2
+      - uses: crazy-max/ghaction-docker-buildx@v1.2.1
+
+      - name: Build
+        run: |
+          docker buildx build \
+            --output type=image,push=false \
+            ${{ steps.prepare.outputs.buildx_args }}
+
+      - name: Log into registry
+        if: github.event_name == 'push'
+        run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login --username $DOCKER_HUB_USER --password-stdin
+
+      - name: Push to registry
+        if: github.event_name == 'push'
+        run: |
+          docker buildx build \
+            --output type=image,push=true \
+            ${{ steps.prepare.outputs.buildx_args }}
+
diff --git a/Dockerfile b/Dockerfile
new file mode 100644 (file)
index 0000000..1ce4212
--- /dev/null
@@ -0,0 +1,101 @@
+FROM alpine 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 may be modified by the Github Action Workflow.
+ARG SHAIRPORT_SYNC_BRANCH=master
+
+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
+
+RUN    git clone https://github.com/mikebrady/shairport-sync
+WORKDIR shairport-sync
+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
+
+RUN    apk 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/* /
+
+ENTRYPOINT [ "/start.sh" ]
+
diff --git a/docker/start.sh b/docker/start.sh
new file mode 100755 (executable)
index 0000000..40d408d
--- /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
+
+shairport-sync $@