Move bundled modules into core repository to simplify docker build process (#14)

This commit is contained in:
andig 2020-03-25 13:24:50 +01:00
parent 617b8ea9b5
commit 19325219e7
8 changed files with 76 additions and 37 deletions

View file

@ -1,6 +1,10 @@
.vscode
.*
*.conf
*.Dockerfile
*.json
*.sh
*.yaml
Dockerfile
!entrypoint.sh
!modules/**
!evcc.dist.yaml

23
.gitignore vendored
View file

@ -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/**

View file

@ -50,4 +50,4 @@ deploy:
skip_cleanup: true
script: make publish-images
on:
tags: true
branch: master

View file

@ -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" ]

View file

@ -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:

View file

@ -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 "$@"

21
modules/audi/audi.py Executable file
View file

@ -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)

13
modules/audi/audi.sh Executable file
View file

@ -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