diff --git a/.github/workflows/update-and-build-image.yml b/.github/workflows/update-and-build-image.yml new file mode 100644 index 0000000..5da8df2 --- /dev/null +++ b/.github/workflows/update-and-build-image.yml @@ -0,0 +1,109 @@ +name: Update and build Docker image + +on: + schedule: + - cron: '0 7 * * 4' # every Thursday at 07:00 UTC + workflow_dispatch: # allow manual trigger + +jobs: + check-update: + runs-on: ubuntu-slim + permissions: + contents: write + outputs: + bumped: ${{ steps.compare.outputs.bumped }} + version: ${{ steps.compare.outputs.version }} + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Fetch latest snapcast-server version from Alpine + id: get_version + run: | + # Version is wrapped in tags on the Alpine package page + VERSION=$(curl -fsSL "https://pkgs.alpinelinux.org/package/edge/community/x86/snapcast-server" \ + | grep -oP '(?<=)[0-9]+.[0-9]+.[0-9]+-r[0-9]+(?=)' \ + | head -n1) + + if [ -z "$VERSION" ]; then + echo "ERROR: Could not parse version from Alpine package page." >&2 + exit 1 + fi + + echo "Latest version: $VERSION" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Compare versions and update Dockerfile if changed + id: compare + run: | + CURRENT=$(grep -oP '(?<=SNAPCAST_VERSION=)[^\s"]+' Dockerfile | head -n1) + NEW="${{ steps.get_version.outputs.version }}" + echo "Current: $CURRENT / Latest: $NEW" + + if [ "$CURRENT" = "$NEW" ]; then + echo "No update needed." + echo "bumped=false" >> "$GITHUB_OUTPUT" + echo "version=$CURRENT" >> "$GITHUB_OUTPUT" + else + sed -i "s/ARG SNAPCAST_VERSION=.*/ARG SNAPCAST_VERSION=${NEW}/" Dockerfile + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add Dockerfile + git commit -m "chore: bump snapcast-server to ${NEW}" + git push + echo "bumped=true" >> "$GITHUB_OUTPUT" + echo "version=$NEW" >> "$GITHUB_OUTPUT" + fi + + build: + needs: check-update + if: ${{ needs.check-update.outputs.bumped == 'true' || github.event_name == 'workflow_dispatch' }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repo (with submodules) + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + submodules: recursive + + - name: Derive version tags + id: meta_version + run: | + VERSION="${{ needs.check-update.outputs.version }}" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + SHORT=$(echo "$VERSION" | grep -oP '^[0-9]+\.[0-9]+\.[0-9]+') + echo "short=$SHORT" >> "$GITHUB_OUTPUT" + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU (for multi-arch builds) + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + provenance: false + # Full alpine version tag (e.g. 0.34.0-r0), short tag (e.g. 0.34.0), and latest + tags: | + ghcr.io/${{ github.repository_owner }}/snapserver-docker:${{ steps.meta_version.outputs.version }} + ghcr.io/${{ github.repository_owner }}/snapserver-docker:${{ steps.meta_version.outputs.short }} + ghcr.io/${{ github.repository_owner }}/snapserver-docker:latest + build-args: | + SNAPCAST_VERSION=${{ steps.meta_version.outputs.version }} diff --git a/Dockerfile b/Dockerfile index 666c25e..931c96d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,19 @@ FROM alpine:latest LABEL maintainer="kerta1n" -ARG SNAPCAST_VERSION=0.32.3-r0 +ARG SNAPCAST_VERSION=0.34.0-r0 -RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories -RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories +RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \ + && echo "https://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories \ + && apk add --no-cache bash snapcast-server=${SNAPCAST_VERSION} sed curl unzip \ + && SNAPWEB_VERSION=$(curl -fsSL "https://api.github.com/repos/badaix/snapweb/releases/latest" \ + | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p') \ + && curl -fsSL "https://github.com/badaix/snapweb/releases/download/${SNAPWEB_VERSION}/snapweb.zip" \ + -o /tmp/snapweb.zip \ + && mkdir -p /usr/share/snapserver/snapweb \ + && unzip -o /tmp/snapweb.zip -d /usr/share/snapserver/snapweb \ + && rm -f /tmp/snapweb.zip \ + && apk del curl sed unzip -RUN apk add --no-cache bash snapcast-server=${SNAPCAST_VERSION} sed - -#ENV DEVICE_NAME=Snapcast -CMD snapserver -c /etc/snapserver.conf -EXPOSE 1704/tcp 1705/tcp 1780/tcp \ No newline at end of file +CMD ["snapserver", "-c", "/etc/snapserver.conf"] +EXPOSE 1704/tcp 1705/tcp 1780/tcp