Skip to content

Commit

Permalink
Merge pull request #162 from svrooij/beta
Browse files Browse the repository at this point in the history
Januari 2022 release
  • Loading branch information
svrooij authored Jan 22, 2022
2 parents 20cab50 + 0921e29 commit 46bf61e
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 2,796 deletions.
11 changes: 10 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@
"contributions": [
"doc"
]
},
{
"login": "JonasMH",
"name": "Jonas Hansen",
"avatar_url": "https://avatars.github.com/u/1939229?v=4",
"profile": "http://jonasmhansen.com",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
"contributorsPerLine": 5,
"skipCi": true
}
98 changes: 83 additions & 15 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,152 @@
name: Run tests and publish
name: Run tests and release npm package

on:
workflow_dispatch:
push:
branches:
- master
- main
- development
- beta
- auto-build
paths-ignore:
- 'docs/**'
- 'README.md'
- '.all-contributorsrc'
pull_request:
branches:
- master
- main
- beta
paths-ignore:
- 'docs/**'
- 'README.md'
- '.all-contributorsrc'

jobs:
run-build-on-node12:
# Install dependencies, run tests and try to build
test:
name: 'Build and test on Node v${{ matrix.node }}'
runs-on: ubuntu-latest
strategy:
matrix:
node: [12, 14, 16]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 12
node-version: ${{ matrix.node }}
- name: Install depencencies
run: npm ci
- name: Run tests
run: npm test
- name: Build library
run: npm run build

# Release to NPM if its not a pull request
npm-release:
runs-on: ubuntu-latest
name: NPM Release
if: github.event_name != 'pull_request'
needs: [test]
outputs:
released: ${{ steps.semantic.outputs.new_release_published }}
version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- name: Install depencencies
run: npm ci
- name: Build library
run: npm run build
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setup node for Github Registry
if: steps.semantic.outputs.new_release_published == 'true'
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: 'https://npm.pkg.github.com'
scope: 'svrooij'
- name: Publish To GitHub Package Registry
if: steps.semantic.outputs.new_release_published == 'true'
run: |
sed -i 's+"name": "sonos2mqtt"+"name": "@svrooij/sonos2mqtt"+g' package**.json
npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

# Release container if it released to npm.
container-release:
runs-on: ubuntu-latest
name: Container release
needs: [npm-release]
if: needs.npm-release.outputs.released == 'true'
steps:
- uses: actions/checkout@v2

-
name: Set up QEMU (multi platform)
uses: docker/setup-qemu-action@v1
if: steps.semantic.outputs.new_release_published == 'true'
with:
platforms: all

-
name: Set up Docker Buildx
id: buildx
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/setup-buildx-action@v1
with:
version: latest

-
name: Login to DockerHub
uses: docker/login-action@v1
if: steps.semantic.outputs.new_release_published == 'true'
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Publish to docker with buildx as latest
if: steps.semantic.outputs.new_release_published == 'true' && github.ref == 'refs/heads/master'
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish container as latest
if: github.ref == 'refs/heads/master'
run: |
docker buildx build \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--push \
-f ./Dockerfile.npm \
-t $GITHUB_REPOSITORY:latest \
-t $GITHUB_REPOSITORY:${{ steps.semantic.outputs.new_release_version }} \
-t $GITHUB_REPOSITORY:${{ needs.npm-release.outputs.version }} \
-t ghcr.io/svrooij/sonos2mqtt:latest \
-t ghcr.io/svrooij/sonos2mqtt:${{ needs.npm-release.outputs.version }} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg BUILD_VERSION=${{ steps.semantic.outputs.new_release_version }} \
--build-arg BUILD_VERSION=${{ needs.npm-release.outputs.version }} \
--build-arg VSC_REF=$(echo ${GITHUB_SHA} | cut -c1-8) \
.
- name: Publish to docker with buildx as beta
if: steps.semantic.outputs.new_release_published == 'true' && github.ref != 'refs/heads/master'
- name: Publish container as beta
if: github.ref != 'refs/heads/master'
run: |
docker buildx build \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--push \
-f ./Dockerfile.npm \
-t $GITHUB_REPOSITORY:beta \
-t $GITHUB_REPOSITORY:${{ steps.semantic.outputs.new_release_version }} \
-t $GITHUB_REPOSITORY:${{ needs.npm-release.outputs.version }} \
-t ghcr.io/svrooij/sonos2mqtt:beta \
-t ghcr.io/svrooij/sonos2mqtt:${{ needs.npm-release.outputs.version }} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg BUILD_VERSION=${{ steps.semantic.outputs.new_release_version }} \
--build-arg BUILD_VERSION=${{ needs.npm-release.outputs.version }} \
--build-arg VSC_REF=$(echo ${GITHUB_SHA} | cut -c1-8) \
.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM node:current-alpine as build
FROM node:current-alpine3.12 as build
WORKDIR /usr/src/app
COPY package*.json tsconfig.json ./
RUN npm ci
COPY ./src ./src
RUN npm run build

FROM node:current-alpine as prod
FROM node:current-alpine3.12 as prod
ARG BUILD_DATE=unknown
ARG BUILD_VERSION=0.0.0-development
ARG VCS_REF=not-set
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile.npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# FROM node:current-alpine as build
# WORKDIR /usr/src/app
# COPY package*.json tsconfig.json ./
# RUN npm ci
# COPY ./src ./src
# RUN npm run build

FROM node:current-alpine3.12 as prod
ENV SONOS2MQTT_RUNNING_IN_CONTAINER=true
WORKDIR /usr/src/app

ARG BUILD_VERSION=latest

RUN npm install -g sonos2mqtt@${BUILD_VERSION}

ARG BUILD_DATE=unknown
ARG VCS_REF=unknown
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.description="Connecting your sonos speakers to mqtt" \
org.label-schema.name=sonos2mqtt \
org.label-schema.schema-version=1.0 \
org.label-schema.url=https://github.com/svrooij/sonos2mqtt/ \
org.label-schema.version=$BUILD_VERSION \
org.label-schema.vcs-ref=$VCS_REF
EXPOSE 6329
CMD ["sonos2mqtt"]
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[![github issues][badge_issues]][link_issues]
[![Run build and publish][badge_build]][link_build] -->
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![mqtt-smarthome](https://img.shields.io/badge/mqtt-smarthome-blue.svg?style=flat-square)](https://github.com/mqtt-smarthome/mqtt-smarthome)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
Expand All @@ -36,6 +36,8 @@ See: [https://svrooij.github.io/sonos2mqtt](https://svrooij.github.io/sonos2mqtt

## Node-sonos-ts

[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript]

This library depends on [node-sonos-ts](https://github.com/svrooij/node-sonos-ts/) which I also developed. All other libraries using node-sonos-ts should also be able to implemented all the nice features included there. Like **notifications** or **text-to-speech** which are the coolest new additions for **sonos2mqtt**!

## Beer or Coffee
Expand All @@ -62,11 +64,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://mi.o-o.im"><img src="https://avatars0.githubusercontent.com/u/7872104?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matthias Burgfried</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=matthias-burgfried" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/mqtt-fan"><img src="https://avatars1.githubusercontent.com/u/32242849?v=4?s=100" width="100px;" alt=""/><br /><sub><b>mqtt-fan</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=mqtt-fan" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/roth"><img src="https://avatars3.githubusercontent.com/u/716931?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Martin Roth</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=roth" title="Documentation">📖</a></td>
<td align="center"><a href="http://dgmltn.com"><img src="https://avatars3.githubusercontent.com/u/698270?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Doug Melton</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/issues?q=author%3Adgmltn" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://sebbo.net/"><img src="https://avatars.github.com/u/812398?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=sebbo2002" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="http://dgmltn.com"><img src="https://avatars3.githubusercontent.com/u/698270?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Doug Melton</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/issues?q=author%3Adgmltn" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://sebbo.net/"><img src="https://avatars.github.com/u/812398?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=sebbo2002" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/evenisse"><img src="https://avatars.github.com/u/682743?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Emmanuel Venisse</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=evenisse" title="Documentation">📖</a></td>
<td align="center"><a href="http://jonasmhansen.com"><img src="https://avatars.github.com/u/1939229?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonas Hansen</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=JonasMH" title="Documentation">📖</a></td>
</tr>
</table>

Expand All @@ -78,7 +81,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
Contributions of any kind welcome!

[badge_build]: https://github.com/svrooij/sonos2mqtt/workflows/Run%20tests%20and%20publish/badge.svg
[badge_build]: https://github.com/svrooij/sonos2mqtt/workflows/Run%20tests%20and%20release%20npm%20package/badge.svg
[badge_docker]: https://img.shields.io/docker/pulls/svrooij/sonos2mqtt
[badge_discord]: https://img.shields.io/discord/782374564054564875?style=flat-square
[badge_issues]: https://img.shields.io/github/issues/svrooij/sonos2mqtt?style=flat-square
Expand Down
5 changes: 3 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://mi.o-o.im"><img src="https://avatars0.githubusercontent.com/u/7872104?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matthias Burgfried</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=matthias-burgfried" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/mqtt-fan"><img src="https://avatars1.githubusercontent.com/u/32242849?v=4?s=100" width="100px;" alt=""/><br /><sub><b>mqtt-fan</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=mqtt-fan" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/roth"><img src="https://avatars3.githubusercontent.com/u/716931?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Martin Roth</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=roth" title="Documentation">📖</a></td>
<td align="center"><a href="http://dgmltn.com"><img src="https://avatars3.githubusercontent.com/u/698270?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Doug Melton</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/issues?q=author%3Adgmltn" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://sebbo.net/"><img src="https://avatars.github.com/u/812398?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=sebbo2002" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="http://dgmltn.com"><img src="https://avatars3.githubusercontent.com/u/698270?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Doug Melton</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/issues?q=author%3Adgmltn" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://sebbo.net/"><img src="https://avatars.github.com/u/812398?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=sebbo2002" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/evenisse"><img src="https://avatars.github.com/u/682743?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Emmanuel Venisse</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=evenisse" title="Documentation">📖</a></td>
<td align="center"><a href="http://jonasmhansen.com"><img src="https://avatars.github.com/u/1939229?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonas Hansen</b></sub></a><br /><a href="https://github.com/svrooij/sonos2mqtt/commits?author=JonasMH" title="Documentation">📖</a></td>
</tr>
</table>

Expand Down
39 changes: 32 additions & 7 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Using this library in docker is the preferred way.

1. Create an `.env` file with the following settings.
2. Set the required values.
3. Run `docker run --env-file .env -p 6329:6329 svrooij/sonos2mqtt`
3. Run `docker run --env-file .env -p 6329:6329 ghcr.io/svrooij/sonos2mqtt`

```shell
# Set the IP of one known sonos speaker (device discovery doesnt always work inside docker.)
Expand All @@ -44,23 +44,48 @@ SONOS_LISTENER_HOST=192.168.x.x

See [configuration](#configuration) for additional settings.

This app makes heavy use of events, so you'll have to make sure they still work. That is why you need to expose the listening port (`6329`), changing the port will cause problems. The library will automaticcally subscribe to events from the sonos device, but because you're running in docker it cannot figure out the IP by itself. You set the IP of the docker host in the `SONOS_LISTENER_HOST` environment variable. This is how the events flow.
### Events

sonos2mqtt requires events to be configured correctly before being able to send status updates to MQTT, so you'll have to make sure they work. Sonos events works by sonos2mqtt registers a callback url in the speaker(s), when the speaker state then changes, the speaker will make a new http request to the provided callback url:

```
================ =============== ==============
| Sonos Device | == HTTP => | Docker host | == HTTP => | sonos2mqtt |
================ =============== ==============
+-------------+ +-------------+ +-------+
| sonos2mqtt | | dockerhost | | sonos |
+-------------+ +-------------+ +-------+
| | |
| SetupEvents(callbackUrl) | |
|----------------------------------------->| |
| | |
| | SetupEvents(callbackUrl) |
| |-------------------------------------->|
| | |
| | http://callbackUrl: State changed |
| |<--------------------------------------|
| | |
| http://callbackUrl: State changed | |
|<-----------------------------------------| |
| | |
```

We automatically build a multi-architecture image for `amd64`, `arm64`, `armv7` and `i386`. This means you can run sonos2mqtt in docker on almost any device.
This means that the speaker should be able to connect to sonos2mqtt on `SONOS_LISTENER_HOST:6329`. This can be verified by starting up sonos2mqtt, and then on another machine try to access `http://SONOS_LISTENER_HOST:6329/status` where you should see a json document. If this doesn't work, try through the following steps one by one until it works:

1. Verify `SONOS_LISTENER_HOST` is set to the host machine ip
2. Verify port `6329` has been bound in docker (See the `docker-compose.yml` below)
3. Create an exception for `6329` in the firewall
4. Make sure port `6329` is not in use by another service

That is why you need to expose the listening port (`6329`), changing the port will cause problems. The library will automaticcally subscribe to events from the sonos device, but because you're running in docker it cannot figure out the IP by itself. You set the IP of the docker host in the `SONOS_LISTENER_HOST` environment variable. This is how the events flow:

### Docker-compose

We automatically build a multi-architecture image for `amd64`, `arm64`, `armv7` and `i386`. This means you can run sonos2mqtt in docker on almost any device.

```yaml
version: "3.7"
services:
sonos:
image: svrooij/sonos2mqtt
image: ghcr.io/svrooij/sonos2mqtt
# or the dockerhub svrooij/sonos2mqtt
restart: unless-stopped
ports:
- "6329:6329"
Expand Down
Loading

0 comments on commit 46bf61e

Please sign in to comment.