From 19325219e70628cc82e99e091f14ce4d1d94e68a Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 25 Mar 2020 13:24:50 +0100 Subject: [PATCH] Move bundled modules into core repository to simplify docker build process (#14) --- .dockerignore | 6 +++++- .gitignore | 23 ++++++++--------------- .travis.yml | 2 +- Dockerfile | 32 ++++++++++++++++++++------------ README.md | 6 +++--- entrypoint.sh | 10 +++++----- modules/audi/audi.py | 21 +++++++++++++++++++++ modules/audi/audi.sh | 13 +++++++++++++ 8 files changed, 76 insertions(+), 37 deletions(-) create mode 100755 modules/audi/audi.py create mode 100755 modules/audi/audi.sh diff --git a/.dockerignore b/.dockerignore index c37b0aa76..2f46269b4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,10 @@ -.vscode +.* *.conf +*.Dockerfile *.json *.sh *.yaml +Dockerfile +!entrypoint.sh +!modules/** !evcc.dist.yaml diff --git a/.gitignore b/.gitignore index 13d275014..5e1694d75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,9 @@ -evcc.log -evcc.yaml -evcc.script.yaml -evcc.wallbe.yaml -linux-386-.Dockerfile -linux-amd64-.Dockerfile -linux-arm-7.Dockerfile -linux-arm-6.Dockerfile -linux-arm64-.Dockerfile -manifest.json -.vscode -audi.* -credentials.json -token.json -evcc __debug_bin +.vscode +*.json +*.log +*.yaml +evcc +linux-*.Dockerfile +!evcc.dist.yaml +!modules/** diff --git a/.travis.yml b/.travis.yml index c3dedeca0..1489fea0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,4 +50,4 @@ deploy: skip_cleanup: true script: make publish-images on: - tags: true + branch: master diff --git a/Dockerfile b/Dockerfile index 54d4a3fe3..0725f6fc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -############################ +# # STEP 1 build executable binary -############################ -FROM golang:1.13-alpine as builder +# + +FROM golang:1.14-alpine as builder # Install git + SSL ca certificates. # Git is required for fetching the dependencies. @@ -18,19 +19,26 @@ RUN go mod download COPY . . RUN make clean install assets build -############################# -## STEP 2 build a small image -############################# -FROM alpine +# +# STEP 2 build a small image including module support +# + +FROM alpine:3.11 + +WORKDIR /evcc + +# Audi +RUN apk add --no-cache python3 curl jq +RUN pip3 install --no-cache-dir --upgrade requests audiapi # Import from builder. -COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ - -# Copy our static executable COPY --from=builder /build/evcc /usr/local/bin/evcc +COPY modules/audi/* /evcc/ +COPY entrypoint.sh /evcc/ + EXPOSE 7070 -# Run the binary -ENTRYPOINT ["/usr/local/bin/evcc"] +ENTRYPOINT [ "/evcc/entrypoint.sh" ] +CMD [ "evcc" ] diff --git a/README.md b/README.md index 450e5c73a..017880b67 100644 --- a/README.md +++ b/README.md @@ -50,15 +50,15 @@ More information on interacting with Wallbe chargers can be found at [GoingElect The preferred way of running EVCC is using the docker image: - docker pull andig/evcc-bundle:latest + docker pull andig/evcc:latest To see the available options: - docker run andig/evcc-bundle -h + docker run andig/evcc -h To run EVCC with given config file and UI on port 7070: - docker run -v $(pwd)/evcc.dist.yaml:/etc/evcc.yaml -p 7070:7070 andig/evcc-bundle + docker run -v $(pwd)/evcc.dist.yaml:/etc/evcc.yaml -p 7070:7070 andig/evcc To build EVCC from source, [Go](2) 1.13 is required: diff --git a/entrypoint.sh b/entrypoint.sh index 54cfd9ae0..9bc8f10f9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,8 @@ -#!/bin/bash +#!/bin/sh set -e -if [ "$1" = "evcc" ]; then - exec /go/bin/evcc "$@" +if [ "$1" == '"evcc"' ] || expr "$1" : '-*' > /dev/null; then + exec evcc "$@" +else + exec "$@" fi - -exec "$@" diff --git a/modules/audi/audi.py b/modules/audi/audi.py new file mode 100755 index 000000000..8cd2ff36c --- /dev/null +++ b/modules/audi/audi.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import json, os + +from audiapi.API import API +from audiapi.Services import LogonService + +credentials = 'audi.json' + +if __name__ == '__main__': + api = API() + logon_service = LogonService(api) + if not logon_service.restore_token(): + # We need to login + if os.path.isfile(credentials): + with open(credentials) as data_file: + data = json.load(data_file) + logon_service.login(data['user'], data['pass']) + else: + user = os.environ['AUDI_USER'] + password = os.environ['AUDI_PASS'] + logon_service.login(user, password) diff --git a/modules/audi/audi.sh b/modules/audi/audi.sh new file mode 100755 index 000000000..ecb1625e8 --- /dev/null +++ b/modules/audi/audi.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +AUDI_USER=$(cat audi.json | jq -r .user) +AUDI_PASS=$(cat audi.json | jq -r .pass) +python3 audi.py + +acctoken=$(cat token.json | jq -r .access_token) +vin=$(cat audi.json | jq -r .vin) +battsoc=$(curl -s --header "Accept: application/json" --header "X-App-Name: eRemote" --header "X-App-Version: 1.0.0" --header "User-Agent: okhttp/2.3.0" --header "Authorization: AudiAuth 1 $acctoken" https://msg.audi.de/fs-car/bs/batterycharge/v1/Audi/DE/vehicles/$vin/charger) +soclevel=$(echo $battsoc | jq .charger.status.batteryStatusData.stateOfCharge.content) +echo $soclevel