From bc476de8fb1840066d20f07bf3aa5db677e2f9aa Mon Sep 17 00:00:00 2001 From: Daniel Welch Date: Tue, 10 Jul 2018 11:58:04 -0500 Subject: [PATCH 1/2] 0.1 update with seperate edge repository, build/distro script updates --- README.md | 7 ++-- build.sh | 47 +++++++++++++++++++----- distribute.sh | 70 ++++++++++++++++++++++++------------ zigbee2mqtt-edge/Dockerfile | 22 ++++++++++++ zigbee2mqtt-edge/config.json | 32 +++++++++++++++++ zigbee2mqtt-edge/run.sh | 19 ++++++++++ zigbee2mqtt/Dockerfile | 2 +- zigbee2mqtt/config.json | 5 ++- zigbee2mqtt/run.sh | 4 --- 9 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 zigbee2mqtt-edge/Dockerfile create mode 100644 zigbee2mqtt-edge/config.json create mode 100644 zigbee2mqtt-edge/run.sh diff --git a/README.md b/README.md index c40d013..f08966b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Add-on for running [zigbee2mqtt](https://github.com/Koenkk/zigbee2mqtt) in [Hass - Add the [repository URL](https://github.com/danielwelch/hassio-zigbee2mqtt) in your **Hass.io > Add-on Store** -The addon should now be available for installation. +The repository includes two add-ons: zigbee2mqtt and zigbee2mqtt-edge. For a stable release that tracks the released versions of zigbee2mqtt, install zigbee2mqtt. zigbee2mqtt-edge tracks the master branch of zigbee2mqtt, so you can install the edge version if there are features or fixes in the master branch not yet released. ### Configuration @@ -26,7 +26,6 @@ To configure this add-on, you must set the following parameters via the Hass.io |`mqtt_pass`|string|no|Your MQTT Password, if set.| |`debug`|bool|no|Set to true to enable debug mode for zigbee-shepherd and zigbee2mqtt. See [the wiki](https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-debug) for more information.| |`err`|bool|no|Set to true to redirect zigbee2mqtt `stdout` to `out.log` and `stderr` to `err.log`. Both `out.log` and `err.log` will be located within `data_path` above.| -|`commit`|string|no|Set this to a specific `zigbee2mqtt` commit SHA hash to use a specific version of `zigbee2mqtt` (in case of regressions)| Notes: - Depending on your configuration, the MQTT server URL will need to include the port, typically `1883` or `8883` for SSL communications. For example, `mqtt://homeassistant:1883`. @@ -126,9 +125,9 @@ Notes: ### Updating the Add-on and `zigbee2mqtt` Library -Currently, `zigbee2mqtt` is adding new features and functionality quite quickly, and is not using versioned releases. This makes it difficult to increment versioning for this add-on, as we simply pull the latest master branch when building the Docker image. Until `zigbee2mqtt` stabilizes, we will likely not use versioned releases. Therefore, in order to update the add-on and to update `zigbee2mqtt`, you must uninstall and reinstall the add-on via the Hassio UI. +The stable, versioned zigbee2mqtt can be updated using the standard Hass.io update functionality within the user interface. This add-on will be updated with bug fixes and as the underlying `zigbee2mqtt` library is updated. -Note: If you have reinstalled the add-on and believe that the latest version has not been installed, try removing the repository before reinstalling. +To update the edge version of the add-on, you will need to uninstall and re-install the add-on. If you have reinstalled the add-on and believe that the latest version has not been installed, try removing the repository before reinstalling. ### Issues diff --git a/build.sh b/build.sh index a303c56..52d26d6 100755 --- a/build.sh +++ b/build.sh @@ -1,20 +1,49 @@ #!/bin/bash set -ev -if [ -z ${TRAVIS_TAG} ]; then - echo "Untagged build found." +if [ -z "${TRAVIS_TAG}" ]; then + echo "Untagged build found. Building zigbee2mqtt with tag 'test' and zigbee2mqtt with tag 'test'." + # build zigbee2mqtt + docker run -it --rm --privileged --name "${ADDON_NAME}" \ + -v ~/.docker:/root/.docker \ + -v "$(pwd)":/docker \ + hassioaddons/build-env:latest \ + --target "${ADDON_NAME}" \ + --tag-test \ + --all \ + --from "homeassistant/{arch}-base" \ + --author "Daniel Welch " \ + --doc-url "${GITHUB_URL}" \ + --login "${DOCKER_USERNAME}" \ + --password "${DOCKER_PASSWORD}" \ + --parallel + # build zigbee2mqtt-edge + docker run -it --rm --privileged --name "${ADDON_NAME_EDGE}" \ + -v ~/.docker:/root/.docker \ + -v "$(pwd)":/docker \ + hassioaddons/build-env:latest \ + --target "${ADDON_NAME_EDGE}" \ + --tag-test \ + --all \ + --from "homeassistant/{arch}-base" \ + --author "Daniel Welch " \ + --doc-url "${GITHUB_URL}" \ + --login "${DOCKER_USERNAME}" \ + --password "${DOCKER_PASSWORD}" \ + --parallel else - echo "New git tagged build found." -fi -docker run -it --rm --privileged --name ${ADDON_NAME} \ + echo "New git tagged build found. Building zigbee2mqtt with tag 'latest'." + docker run -it --rm --privileged --name "${ADDON_NAME}" \ -v ~/.docker:/root/.docker \ -v "$(pwd)":/docker \ hassioaddons/build-env:latest \ - --target ${ADDON_NAME} \ - --git \ + --target "${ADDON_NAME}" \ + --tag-latest \ --all \ --from "homeassistant/{arch}-base" \ --author "Daniel Welch " \ --doc-url "${GITHUB_URL}" \ - --login ${DOCKER_USERNAME} \ - --password ${DOCKER_PASSWORD} + --login "${DOCKER_USERNAME}" \ + --password "${DOCKER_PASSWORD}" \ + --parallel +fi echo "Local Docker build successful." diff --git a/distribute.sh b/distribute.sh index 5e847a8..b7bade9 100755 --- a/distribute.sh +++ b/distribute.sh @@ -7,28 +7,54 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then fi if [ ! -z "$TRAVIS_TAG" ]; then - echo "Tagged build found. Pushing to Docker with tag 'latest'." + echo "Tagged build found. Pushing zigbee2mqtt image to Docker with tag 'latest'." + + docker run -it --rm --privileged --name "${ADDON_NAME}" \ + -v ~/.docker:/root/.docker \ + -v "$(pwd)":/docker \ + hassioaddons/build-env:latest \ + --target "${ADDON_NAME}" \ + --tag-latest \ + --push \ + --all \ + --from "homeassistant/{arch}-base" \ + --author "Daniel Welch " \ + --doc-url "${GITHUB_URL}" \ + --login "${DOCKER_USERNAME}" \ + --password "${DOCKER_PASSWORD}" \ + --parallel else - # DIFF="$(git diff HEAD^ HEAD dropbox-sync)" - # if [ -z $DIFF ]; then - # echo "No changes in Dropbox Sync add-on. Skipping docker push." - # exit 0 - # fi - echo "No tag found. Pushing to Docker with tag 'test'." -fi + echo "No tag found. Pushing zigbee2mqtt and zigbee2mqtt-edge images to Docker with tag 'test'." -git status + # distribute zigbee2mqtt with tag test + docker run -it --rm --privileged --name "${ADDON_NAME}" \ + -v ~/.docker:/root/.docker \ + -v "$(pwd)":/docker \ + hassioaddons/build-env:latest \ + --target "${ADDON_NAME}" \ + --tag-latest \ + --push \ + --all \ + --from "homeassistant/{arch}-base" \ + --author "Daniel Welch " \ + --doc-url "${GITHUB_URL}" \ + --login "${DOCKER_USERNAME}" \ + --password "${DOCKER_PASSWORD}" \ + --parallel -docker run -it --rm --privileged --name "${ADDON_NAME}" \ - -v ~/.docker:/root/.docker \ - -v "$(pwd)":/docker \ - hassioaddons/build-env:latest \ - --target "${ADDON_NAME}" \ - --git \ - --all \ - --push \ - --from "homeassistant/{arch}-base" \ - --author "Daniel Welch " \ - --doc-url "${GITHUB_URL}" \ - --login "${DOCKER_USERNAME}" \ - --password "${DOCKER_PASSWORD}" + # distribute zigbee2mqtt-edge with tag test + docker run -it --rm --privileged --name "${ADDON_NAME_EDGE}" \ + -v ~/.docker:/root/.docker \ + -v "$(pwd)":/docker \ + hassioaddons/build-env:latest \ + --target "${ADDON_NAME_EDGE}" \ + --tag-latest \ + --push \ + --all \ + --from "homeassistant/{arch}-base" \ + --author "Daniel Welch " \ + --doc-url "${GITHUB_URL}" \ + --login "${DOCKER_USERNAME}" \ + --password "${DOCKER_PASSWORD}" \ + --parallel +fi diff --git a/zigbee2mqtt-edge/Dockerfile b/zigbee2mqtt-edge/Dockerfile new file mode 100644 index 0000000..8c7f2e1 --- /dev/null +++ b/zigbee2mqtt-edge/Dockerfile @@ -0,0 +1,22 @@ +ARG BUILD_FROM +FROM $BUILD_FROM + +# Add env +ENV LANG C.UTF-8 + +RUN apk add --update --no-cache jq nodejs nodejs-npm python3 python3-dev \ + python2 make gcc g++ linux-headers udev git && \ + pip3 install PyYAML==3.12 && \ + git clone -b '0.1.0' --single-branch --depth 1 https://github.com/Koenkk/zigbee2mqtt.git /app + +COPY run.sh /app/run.sh +COPY set_config.py /app/set_config.py + +WORKDIR /app + +RUN ["chmod", "a+x", "/app/run.sh"] +RUN ["npm", "install", "--unsafe-perm", "-g", "pm2"] +RUN ["npm", "install", "--unsafe-perm"] +RUN apk del make gcc g++ python2 linux-headers udev + +CMD [ "/app/run.sh" ] diff --git a/zigbee2mqtt-edge/config.json b/zigbee2mqtt-edge/config.json new file mode 100644 index 0000000..4e56477 --- /dev/null +++ b/zigbee2mqtt-edge/config.json @@ -0,0 +1,32 @@ +{ + "name": "zigbee2mqtt-edge", + "version": "test", + "slug": "zigbee2mqtt-edge", + "description": "Development build of the zigbee2mqtt add-on.", + "auto_uart": true, + "url": "https://github.com/danielwelch/hassio-zigbee2mqtt", + "startup": "before", + "boot": "auto", + "map": ["share:rw"], + "options": { + "data_path": "/share/zigbee2mqtt", + "homeassistant": true, + "permit_join": false, + "mqtt_base_topic": "zigbee2mqtt", + "mqtt_server": "mqtt://homeassistant", + "serial_port": "/dev/ttyACM0" + }, + "schema": { + "data_path": "str", + "homeassistant": "bool", + "permit_join": "bool", + "mqtt_base_topic": "str", + "mqtt_server": "str", + "serial_port": "str", + "mqtt_user": "str?", + "mqtt_pass": "str?", + "debug": "bool?", + "err": "bool?" + }, + "image": "dwelch2101/zigbee2mqtt-edge-{arch}" +} diff --git a/zigbee2mqtt-edge/run.sh b/zigbee2mqtt-edge/run.sh new file mode 100644 index 0000000..3001687 --- /dev/null +++ b/zigbee2mqtt-edge/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +CONFIG_PATH=/data/options.json + +DATA_PATH=$(jq --raw-output ".data_path" $CONFIG_PATH) +DEBUG_ZIGBEE2MQTT=$(jq --raw-output ".debug // empty" $CONFIG_PATH) +ERR_LOG=$(jq --raw-output ".err // empty" $CONFIG_PATH) + +python3 set_config.py "$CONFIG_PATH" "$DATA_PATH" + +if [[ ! -z "$DEBUG_ZIGBEE2MQTT" ]]; then + export DEBUG=* +fi + +if [[ ! -z "$ERR_LOG" ]]; then + ZIGBEE2MQTT_DATA="$DATA_PATH" npm start 1> "$DATA_PATH"/out.log 2> "$DATA_PATH"/err.log +else + ZIGBEE2MQTT_DATA="$DATA_PATH" pm2-runtime start npm -- start +fi diff --git a/zigbee2mqtt/Dockerfile b/zigbee2mqtt/Dockerfile index eb06f8a..0a31e53 100644 --- a/zigbee2mqtt/Dockerfile +++ b/zigbee2mqtt/Dockerfile @@ -7,7 +7,7 @@ ENV LANG C.UTF-8 RUN apk add --update --no-cache jq nodejs nodejs-npm python3 python3-dev \ python2 make gcc g++ linux-headers udev git && \ pip3 install PyYAML && \ - git clone -b master --single-branch https://github.com/Koenkk/zigbee2mqtt.git /app + git clone -b master --single-branch --depth 1 https://github.com/Koenkk/zigbee2mqtt.git /app COPY run.sh /app/run.sh COPY set_config.py /app/set_config.py diff --git a/zigbee2mqtt/config.json b/zigbee2mqtt/config.json index 9e7ca45..645a5f0 100644 --- a/zigbee2mqtt/config.json +++ b/zigbee2mqtt/config.json @@ -1,6 +1,6 @@ { "name": "zigbee2mqtt", - "version": "test", + "version": "0.1.0", "slug": "zigbee2mqtt", "description": "Zigbee to MQTT Bridge", "auto_uart": true, @@ -26,8 +26,7 @@ "mqtt_user": "str?", "mqtt_pass": "str?", "debug": "bool?", - "err": "bool?", - "commit": "str?" + "err": "bool?" }, "image": "dwelch2101/zigbee2mqtt-{arch}" } diff --git a/zigbee2mqtt/run.sh b/zigbee2mqtt/run.sh index ae4a819..bcad66c 100644 --- a/zigbee2mqtt/run.sh +++ b/zigbee2mqtt/run.sh @@ -5,7 +5,6 @@ CONFIG_PATH=/data/options.json DATA_PATH=$(jq --raw-output ".data_path" $CONFIG_PATH) DEBUG_ZIGBEE2MQTT=$(jq --raw-output ".debug // empty" $CONFIG_PATH) ERR_LOG=$(jq --raw-output ".err // empty" $CONFIG_PATH) -SHA=$(jq --raw-output ".commit // empty" $CONFIG_PATH) python3 set_config.py "$CONFIG_PATH" "$DATA_PATH" @@ -13,9 +12,6 @@ if [[ ! -z "$DEBUG_ZIGBEE2MQTT" ]]; then export DEBUG=* fi -if [[ ! -z "$SHA" ]]; then - git reset --hard "$SHA" -fi if [[ ! -z "$ERR_LOG" ]]; then ZIGBEE2MQTT_DATA="$DATA_PATH" npm start 1> "$DATA_PATH"/out.log 2> "$DATA_PATH"/err.log From 5b32d74a731735d0e53580ad3d0660721a8ad899 Mon Sep 17 00:00:00 2001 From: Daniel Welch Date: Sat, 14 Jul 2018 17:01:18 -0500 Subject: [PATCH 2/2] cp files over in build script rather than duplicate in edge dir --- build.sh | 4 ++++ distribute.sh | 3 +++ zigbee2mqtt-edge/run.sh | 19 ------------------- 3 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 zigbee2mqtt-edge/run.sh diff --git a/build.sh b/build.sh index 52d26d6..5461a15 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,9 @@ #!/bin/bash set -ev + +cp "${TRAVIS_BUILD_DIR}"/zigbee2mqtt/run.sh "${TRAVIS_BUILD_DIR}"/zigbee2mqtt-edge/run.sh +cp "${TRAVIS_BUILD_DIR}"/zigbee2mqtt/set_config.py "${TRAVIS_BUILD_DIR}"/zigbee2mqtt-edge/set_config.py + if [ -z "${TRAVIS_TAG}" ]; then echo "Untagged build found. Building zigbee2mqtt with tag 'test' and zigbee2mqtt with tag 'test'." # build zigbee2mqtt diff --git a/distribute.sh b/distribute.sh index b7bade9..6b62499 100755 --- a/distribute.sh +++ b/distribute.sh @@ -1,6 +1,9 @@ #!/bin/bash set -ev +cp "${TRAVIS_BUILD_DIR}"/zigbee2mqtt/run.sh "${TRAVIS_BUILD_DIR}"/zigbee2mqtt-edge/run.sh +cp "${TRAVIS_BUILD_DIR}"/zigbee2mqtt/set_config.py "${TRAVIS_BUILD_DIR}"/zigbee2mqtt-edge/set_config.py + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then echo "This build is a pull request, aborting distribution script." exit 0 diff --git a/zigbee2mqtt-edge/run.sh b/zigbee2mqtt-edge/run.sh deleted file mode 100644 index 3001687..0000000 --- a/zigbee2mqtt-edge/run.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -CONFIG_PATH=/data/options.json - -DATA_PATH=$(jq --raw-output ".data_path" $CONFIG_PATH) -DEBUG_ZIGBEE2MQTT=$(jq --raw-output ".debug // empty" $CONFIG_PATH) -ERR_LOG=$(jq --raw-output ".err // empty" $CONFIG_PATH) - -python3 set_config.py "$CONFIG_PATH" "$DATA_PATH" - -if [[ ! -z "$DEBUG_ZIGBEE2MQTT" ]]; then - export DEBUG=* -fi - -if [[ ! -z "$ERR_LOG" ]]; then - ZIGBEE2MQTT_DATA="$DATA_PATH" npm start 1> "$DATA_PATH"/out.log 2> "$DATA_PATH"/err.log -else - ZIGBEE2MQTT_DATA="$DATA_PATH" pm2-runtime start npm -- start -fi