From 28ad8373b38aedb3972582e805050f2a31ec3bc5 Mon Sep 17 00:00:00 2001 From: vchrisb Date: Wed, 22 May 2019 11:53:12 +0200 Subject: [PATCH] add Docker support --- .gitignore | 1 + Dockerfile | 21 +++++++++++++++++++++ README.md | 18 +++++++++++++++--- main.sh | 9 ++++----- requirements.txt | 3 +++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile mode change 100644 => 100755 main.sh create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d17dae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4755fc5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.7 as base + +FROM base as builder + +RUN mkdir /install +WORKDIR /install + +COPY requirements.txt /requirements.txt + +RUN pip install --install-option="--prefix=/install" -r /requirements.txt + +FROM python:3.7-alpine + +COPY --from=builder /install /usr/local +COPY sonos-doorbell.py /app/sonos-doorbell.py +COPY *.mp3 /app/ + +WORKDIR /app +ENV ROOM Kitchen +ENV PORT 8080 +CMD python3 sonos-doorbell.py $ROOM --port $PORT diff --git a/README.md b/README.md index 561d303..f932cb8 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,21 @@ service that can be paired with out IoT devices or smart doorbells to play an au The sonos-doorbell project launches a simple HTTP server that both receives the incoming doorbell requests and hosts the MP3 files to be used by the doorbell ring. -### Launch -1. Install python3 or run from inside a Docker envrionment with python3 setup -1. Edit main.sh to specify the Zone name and port you want the server to be hosted on +### Launch local +1. Install python3 +1. Edit `main.sh` to specify the Zone name and port you want the server to be hosted on +1. Run `main.sh` + +### Launch in Docker + +##### Build Image + +`docker build . -t sonos-doorbell` + +##### Run Image + +Only works on Linux, due to requirment of docker host networking +`docker run -d -e PORT=8888 -e ROOM=Kitchen --name sonos-doorbell --network host --restart always sonos-doorbell` ### Test http://{hostname:port}/doorbell_press?ringtone=dingdong1&volume=45 diff --git a/main.sh b/main.sh old mode 100644 new mode 100755 index 7a5a492..5e15211 --- a/main.sh +++ b/main.sh @@ -1,10 +1,9 @@ #!/bin/bash -pip install --upgrade pip -pip install SoCo -pip install mutagen -pip install netifaces +python3 -m venv .venv +source .venv/bin/activate -cd doorbell +pip install --upgrade pip +pip install -r requirements.txt python3 sonos-doorbell.py "Kitchen" --port 8888 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..81d3812 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +mutagen +netifaces +soco