diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml new file mode 100644 index 0000000..3dedba0 --- /dev/null +++ b/.github/workflows/build-workflow.yml @@ -0,0 +1,70 @@ +# Docker Hub CI/CD for Multi Arch Images... +name: buildx + +on: + pull_request: + branches: + - master + - releases/* + - actions + push: + branches: + - master + - releases/* + - actions + tags: + +jobs: + buildx: + runs-on: ubuntu-latest + steps: + - + name: Prepare + id: prepare + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo ::set-output name=version::${GITHUB_REF#refs/tags/v} + else + echo ::set-output name=version::${GITHUB_SHA::8} + fi + echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386 + echo ::set-output name=docker_image::bushrangers/ha-voltronic-mqtt + - + name: Checkout + uses: actions/checkout@v1 + - + name: Set up Docker Buildx + id: buildx + uses: crazy-max/ghaction-docker-buildx@v1 + with: + version: latest + - + name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + - + name: Docker Login + if: success() + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + - + name: Run Buildx (Push to Docker Hub) + run: | + docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \ + --output "type=image,push=true" \ + --build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ + --build-arg "VCS_REF=${GITHUB_SHA::8}" \ + --build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ + --tag "${{ steps.prepare.outputs.docker_image }}:latest" \ + --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ + --file Dockerfile.multiarch . + - + name: Clear + if: always() + run: | + rm -f ${HOME}/.docker/config.json + + diff --git a/Dockerfile b/Dockerfile.dev similarity index 63% rename from Dockerfile rename to Dockerfile.dev index 9f81a23..aecf7ae 100644 --- a/Dockerfile +++ b/Dockerfile.dev @@ -14,5 +14,12 @@ ADD config/ /etc/inverter/ RUN cd /opt/inverter-cli && \ mkdir bin && cmake . && make && mv inverter_poller bin/ +HEALTHCHECK \ + --interval=30s \ + --timeout=10s \ + --start-period=1m \ + --retries=3 \ + CMD /opt/healthcheck + WORKDIR /opt -ENTRYPOINT ["/bin/bash", "/opt/inverter-mqtt/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "/opt/inverter-mqtt/entrypoint.sh"] diff --git a/Dockerfile.multiarch b/Dockerfile.multiarch new file mode 100644 index 0000000..49a1c80 --- /dev/null +++ b/Dockerfile.multiarch @@ -0,0 +1,37 @@ +# Uncomment if building locally... +# FROM debian:stretch + +FROM --platform=${TARGETPLATFORM:-linux/amd64} debian:stretch + +ARG BUILD_DATE +ARG VERSION +ARG VCS_REF +ARG TARGETPLATFORM + +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.version=$VERSION \ + org.label-schema.vcs-ref=$VCS_REF + +RUN apt update && apt install -y \ + curl \ + git \ + build-essential \ + cmake \ + jq \ + mosquitto-clients + +ADD sources/ /opt/ +ADD config/ /etc/inverter/ + +RUN cd /opt/inverter-cli && \ + mkdir bin && cmake . && make && mv inverter_poller bin/ + +HEALTHCHECK \ + --interval=30s \ + --timeout=10s \ + --start-period=1m \ + --retries=3 \ + CMD /opt/healthcheck + +WORKDIR /opt +ENTRYPOINT ["/bin/bash", "/opt/inverter-mqtt/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index c0981d4..75b4e46 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ grafana-example.jpg **Docker Hub:** [`bushrangers/ha-voltronic-mqtt`](https://hub.docker.com/r/bushrangers/ha-voltronic-mqtt/) -![License](https://img.shields.io/github/license/ned-kelly/docker-voltronic-homeassistant.svg) ![Docker Pulls](https://img.shields.io/docker/pulls/bushrangers/ha-voltronic-mqtt.png) +![License](https://img.shields.io/github/license/ned-kelly/docker-voltronic-homeassistant.svg) ![Docker Pulls](https://img.shields.io/docker/pulls/bushrangers/ha-voltronic-mqtt.png) ![buildx](https://github.com/ned-kelly/docker-voltronic-homeassistant/workflows/buildx/badge.svg) ## Prerequisites @@ -64,7 +64,11 @@ docker-compose up -d ``` -_**Note:** builds on docker hub are currently for x64 -- If you have issues standing up the image on your Linux distribution (i.e. Your Raspberry Pi/ARM device) you will need to manually build the image - This can be done by uncommenting the build flag in your docker-compose.yml file._ +_**Note:**_ + + - builds on docker hub are currently for `linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386` -- If you have issues standing up the image on your Linux distribution (i.e. An old Pi/ARM device) you may need to manually build the image to support your local device architecture - This can be done by uncommenting the build flag in your docker-compose.yml file. + + - The default `docker-compose.yml` file includes Watchtower, which can be configured to auto-update this image when we push new changes to github - Please **uncomment if you wish to auto-update to the latest builds of this project**. ## Integrating into Home Assistant. diff --git a/config/inverter.conf b/config/inverter.conf index 3b8ecb7..21e6a2f 100644 --- a/config/inverter.conf +++ b/config/inverter.conf @@ -30,7 +30,7 @@ watt_factor=1.01 # mentioned in https://github.com/ned-kelly/docker-voltronic-homeassistant/issues/5 # This allows you to modify the buffersize for the qpiri command -qpiri=97 +qpiri=98 # This allows you to modify the buffersize for the qpiws command qpiws=36 @@ -39,4 +39,4 @@ qpiws=36 qmod=5 # This allows you to modify the buffersize for the qpigs command -qpigs=110 \ No newline at end of file +qpigs=110 diff --git a/docker-compose.yml b/docker-compose.yml index 23e3977..7d49ad3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,16 @@ -version: '2' +version: '3' services: voltronic-mqtt: - build: . - #image: bushrangers/ha-voltronic-mqtt + # We're now (finally) supporting Multi-Arch builds (via Github actions) on Docker Hub! + # image: bushrangers/ha-voltronic-mqtt + + # Uncomment if you want to build your own local version. + build: + context: . + dockerfile: Dockerfile.dev + container_name: voltronic-mqtt @@ -26,3 +32,19 @@ services: - /dev/ttyS0:/dev/ttyS0 - /dev/ttyS1:/dev/ttyS1 - /dev/ttyS2:/dev/ttyS2 + + # Used to auto-update images as we release new versions... + watchtower: + # Please see the following for configuration options: + # https://containrrr.github.io/watchtower/container-selection/ + image: containrrr/watchtower + container_name: watchtower + + restart: always + privileged: true + + volumes: + - /var/run/docker.sock:/var/run/docker.sock + + command: --interval 500 + diff --git a/sources/healthcheck b/sources/healthcheck new file mode 100755 index 0000000..476093f --- /dev/null +++ b/sources/healthcheck @@ -0,0 +1,9 @@ +#!/bin/bash + +PROC=`ps cax | grep -E "mqtt-subscriber|mosquitto_sub|watch" | awk '{print $5}' | sort -u | wc -l` + +if [ "$PROC" -eq "3" ] ; then + exit 0 +else + exit 99 +fi \ No newline at end of file diff --git a/sources/inverter-mqtt/mqtt-push.sh b/sources/inverter-mqtt/mqtt-push.sh index 6fa8d9f..5b28cae 100755 --- a/sources/inverter-mqtt/mqtt-push.sh +++ b/sources/inverter-mqtt/mqtt-push.sh @@ -100,9 +100,6 @@ Battery_recharge_voltage=`echo $INVERTER_DATA | jq '.Battery_recharge_voltage' - Battery_under_voltage=`echo $INVERTER_DATA | jq '.Battery_under_voltage' -r` [ ! -z "$Battery_under_voltage" ] && pushMQTTData "Battery_under_voltage" "$Battery_under_voltage" -Battery_under_voltage=`echo $INVERTER_DATA | jq '.Battery_under_voltage' -r` -[ ! -z "$Battery_under_voltage" ] && pushMQTTData "Battery_under_voltage" "$Battery_under_voltage" - Battery_bulk_voltage=`echo $INVERTER_DATA | jq '.Battery_bulk_voltage' -r` [ ! -z "$Battery_bulk_voltage" ] && pushMQTTData "Battery_bulk_voltage" "$Battery_bulk_voltage"