From d8e894045cf77fac5b049d75aa72e9c2dc8db5ab Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 8 Nov 2020 13:25:20 +0100 Subject: [PATCH] Add Hass.io add-on (#408) --- .gitignore | 3 +-- Dockerfile | 4 +++- docker/bin/entrypoint.sh | 22 +++++++++++++++++++--- docker/tmpl.Dockerfile | 4 +++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index cd3d09cb4..0c0f814c8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,7 @@ __debug_bin evcc linux-*.Dockerfile !evcc.dist.yaml -!modules/** dist *.py node_modules -server/assets.go \ No newline at end of file +server/assets.go diff --git a/Dockerfile b/Dockerfile index 9a88cc83b..68875fb22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ FROM golang:1.14-alpine as builder # Install git + SSL ca certificates. # Git is required for fetching the dependencies. # Ca-certificates is required to call HTTPS endpoints. -RUN apk update && apk add --no-cache git ca-certificates tzdata alpine-sdk npm && update-ca-certificates +RUN apk update && apk add --no-cache git jq ca-certificates tzdata alpine-sdk npm && update-ca-certificates WORKDIR /build @@ -34,6 +34,8 @@ ENV TZ=Europe/Berlin COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /build/evcc /usr/local/bin/evcc +COPY --from=builder /usr/bin/jq /usr/bin/ +COPY --from=builder /usr/lib/libjq.so.1* /usr/lib/ COPY docker/bin/* /evcc/ diff --git a/docker/bin/entrypoint.sh b/docker/bin/entrypoint.sh index 9bc8f10f9..b52b92a8a 100755 --- a/docker/bin/entrypoint.sh +++ b/docker/bin/entrypoint.sh @@ -1,8 +1,24 @@ #!/bin/sh set -e -if [ "$1" == '"evcc"' ] || expr "$1" : '-*' > /dev/null; then - exec evcc "$@" +# started as hassio addon +HASSIO_OPTIONSFILE=/data/options.json + +if [ -f ${HASSIO_OPTIONSFILE} ]; then + CONFIG=$(jq -r .config_file ${HASSIO_OPTIONSFILE}) + echo "Using config file: ${CONFIG}" + + if [ ! -f ${CONFIG} ]; then + echo "Config not found. Please create a config under ${CONFIG}." + echo "For details see evcc documentation at https://github.com/andig/evcc#readme." + else + echo "starting evcc: 'evcc --config ${CONFIG}'" + exec evcc --config ${CONFIG} + fi else - exec "$@" + if [ "$1" == '"evcc"' ] || expr "$1" : '-*' > /dev/null; then + exec evcc "$@" + else + exec "$@" + fi fi diff --git a/docker/tmpl.Dockerfile b/docker/tmpl.Dockerfile index af5a22762..048d433f1 100644 --- a/docker/tmpl.Dockerfile +++ b/docker/tmpl.Dockerfile @@ -6,7 +6,7 @@ FROM golang:1.14-alpine as builder # Install git + SSL ca certificates. # Git is required for fetching the dependencies. # Ca-certificates is required to call HTTPS endpoints. -RUN apk update && apk add --no-cache git ca-certificates tzdata alpine-sdk npm && update-ca-certificates +RUN apk update && apk add --no-cache git jq ca-certificates tzdata alpine-sdk npm && update-ca-certificates WORKDIR /build @@ -30,6 +30,8 @@ ENV TZ=Europe/Berlin COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /build/evcc /usr/local/bin/evcc +COPY --from=builder /usr/bin/jq /usr/bin/ +COPY --from=builder /usr/lib/libjq.so.1* /usr/lib/ COPY docker/bin/* /evcc/