From 2cddb4d9e8105a5d68cc5975595a15e8c43593fc Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Fri, 24 Dec 2021 13:12:01 +1100 Subject: [PATCH] Shrink Docker Image, bump version, docker run as non-root --- Dockerfile | 12 +++++++++--- README.md | 17 +++++++++++++++++ SunGather/exports/http.py | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 98a63f8..f188694 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM python:3 +FROM python:3-slim + +RUN useradd sungather WORKDIR /usr/src/sungather @@ -6,6 +8,10 @@ COPY requirements.txt ./ RUN pip install --no-cache-dir --upgrade -r requirements.txt COPY SunGather/ . -RUN touch /config/config.yaml -CMD [ "python", "sungather.py -c /config/config.yaml" ] \ No newline at end of file +VOLUME /config +COPY SunGather/config-example.yaml /config/config.yaml + +USER sungather + +CMD [ "python", "sungather.py", "-c", "/config/config.yaml" ] \ No newline at end of file diff --git a/README.md b/README.md index 508fd3b..8bb6d5b 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,10 @@ python3 sungather.py docker pull bohdans/sungather docker run -v {path to}/config.yaml:/config/config.yaml -e TZ=Australia/Sydney --name sungather bohdans/sungather ``` +or if using the http export +```sh +docker run -v {path to}/config.yaml:/config/config.yaml -e TZ=Australia/Sydney -p 8080:8080 --name sungather bohdans/sungather +``` Note: replace Australia/Sydney with relevant timezone

(back to top)

@@ -92,6 +96,19 @@ See config-example.py it contains default options and comments. If you want to use the new Energy section in Home Assistant, follow the Home Assistant setup below.

(back to top)

+### Commandline Arguments +usage: python3 sungather.py [options] + +Commandline arguments override any config file settings +**-c config.yaml** - Specify config file. +**-v 30** - Logging Level, 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error +**--runonce** - Run once then exit +**-h** - print this help message and exit (also --help) + +Example: +```sh +python3 sungather.py -c /full/path/config.yaml +``` ## Exports diff --git a/SunGather/exports/http.py b/SunGather/exports/http.py index 1991646..407f43f 100644 --- a/SunGather/exports/http.py +++ b/SunGather/exports/http.py @@ -11,7 +11,7 @@ class export_http(object): # Configure HTTP def configure(self, config): - self.webServer = HTTPServer(('localhost', config.get('port',8080)), MyServer) + self.webServer = HTTPServer(('', config.get('port',8080)), MyServer) t = Thread(target=self.webServer.serve_forever) t.start() logging.info("Configured Simple HTTP Server")