From b48fa995b34e6ef56d92411b6e648de7c7e440c8 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 29 Oct 2019 19:04:33 +0100 Subject: [PATCH] Almond (#807) * Initial support for almond * Fix execution * Fix package * fix style * Use package * Try origin * Fix build * Fix build * Support multiarch * Fix readme * Remove i386 * Fix pipeline * Update version * cleanup * Fix name * test-ingress * Improve nginx * cleanup config * add panel icon * Add support for ingress * Add API access * Fix script * Fix panel icon * fix quite mode * Update run.sh * Fix auth * Update almond version * Update version * Fix lint * do not modify hostname * Update version * Address comments * Fix nginx * cleanup * working * Update version * Fix API injection * cleanup nginx config * do not set an refresh token * Update almond/data/run.sh Co-Authored-By: Paulus Schoutsen * Fix command * change timehandling * debug code * debug v2 * Fix value * Debug v3 * Cleanup * Fix token valid * Fix command * Add debug * Add unzip * Fix config settings --- .hadolint.yaml | 1 + almond/Dockerfile | 50 +++++++++++++++++++++++++++++ almond/README.md | 53 +++++++++++++++++++++++++++++++ almond/azure-pipelines.yml | 22 +++++++++++++ almond/build.json | 10 ++++++ almond/config.json | 20 ++++++++++++ almond/data/nginx.conf | 59 ++++++++++++++++++++++++++++++++++ almond/data/run.sh | 63 +++++++++++++++++++++++++++++++++++++ almond/logo.png | Bin 0 -> 5736 bytes 9 files changed, 278 insertions(+) create mode 100644 almond/Dockerfile create mode 100644 almond/README.md create mode 100644 almond/azure-pipelines.yml create mode 100644 almond/build.json create mode 100644 almond/config.json create mode 100644 almond/data/nginx.conf create mode 100755 almond/data/run.sh create mode 100644 almond/logo.png diff --git a/.hadolint.yaml b/.hadolint.yaml index 4d6c5ea..6c91568 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -4,4 +4,5 @@ ignored: - DL3007 - DL3008 - DL3018 + - DL4006 - SC2046 diff --git a/almond/Dockerfile b/almond/Dockerfile new file mode 100644 index 0000000..5988704 --- /dev/null +++ b/almond/Dockerfile @@ -0,0 +1,50 @@ +ARG BUILD_FROM +FROM ${BUILD_FROM} + +# Install Alomond requirements +RUN apt-get update && apt-get install -y --no-install-recommends \ + software-properties-common \ + gnupg \ + nginx \ + unzip \ + \ + && curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \ + && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ + && echo "deb https://deb.nodesource.com/node_12.x buster main" > /etc/apt/sources.list.d/nodesource.list \ + && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \ + \ + && apt-get update && apt-get install -y --no-install-recommends \ + nodejs \ + yarn \ + && rm -rf /var/lib/apt/lists/* + + +# Install Almond +ARG ALMOND_COMMIT +WORKDIR /opt/almond +RUN apt-get update && apt-get install -y --no-install-recommends \ + git \ + python-dev \ + build-essential \ + \ + && git clone https://github.com/stanford-oval/almond-server . \ + && git checkout ${ALMOND_COMMIT} \ + && rm -fr .git \ + && yarn \ + \ + && apt-get purge -y --auto-remove \ + git \ + python-dev \ + build-essential \ + && rm -rf /var/lib/apt/lists/* \ + && rm -fr /root/.cache + +# Base env settings +ENV LANG=en_US.utf8 +ENV THINGENGINE_HOME=/data/almond-server +ENV THINGENGINE_HOST_BASED_AUTHENTICATION=local-ip + +COPY data/run.sh / +COPY data/nginx.conf /etc/nginx/ + +CMD ["/run.sh"] \ No newline at end of file diff --git a/almond/README.md b/almond/README.md new file mode 100644 index 0000000..89c7519 --- /dev/null +++ b/almond/README.md @@ -0,0 +1,53 @@ +# Hass.io Core Add-on: Almond + +Almond For Home Servers. + +![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] ![Supports i386 Architecture][i386-shield] + +## About + +## Installation + +The installation of this add-on is straightforward and easy to do. + +1. Navigate in your Home Assistant frontend to **Hass.io** -> **Add-on Store**. +2. Find the "Almond" add-on and click it. +3. Click on the "INSTALL" button. + +## How to use + +The basic thing to get the add-on running would be: + +1. Start the add-on. + +## Configuration + +Example add-on configuration: + +```json +{ +} +``` + +## Support + +Got questions? + +You have several options to get them answered: + +- The [Home Assistant Discord Chat Server][discord]. +- The Home Assistant [Community Forum][forum]. +- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit] + +In case you've found an bug, please [open an issue on our GitHub][issue]. + +[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg +[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg +[armhf-shield]: https://img.shields.io/badge/armhf-no-red.svg +[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg +[discord]: https://discord.gg/c5DvZ4e +[forum]: https://community.home-assistant.io +[i386-shield]: https://img.shields.io/badge/i386-no-red.svg +[issue]: https://github.com/home-assistant/hassio-addons/issues +[reddit]: https://reddit.com/r/homeassistant +[repository]: https://github.com/hassio-addons/repository diff --git a/almond/azure-pipelines.yml b/almond/azure-pipelines.yml new file mode 100644 index 0000000..04d82f7 --- /dev/null +++ b/almond/azure-pipelines.yml @@ -0,0 +1,22 @@ +# https://dev.azure.com/home-assistant + +trigger: + branches: + include: + - master + paths: + include: + - almond/* +pr: none + +variables: + - name: versionBuilder + value: '2.0' + - group: docker + + +jobs: +- template: /.azure/azp-template-addon.yml + parameters: + addon: 'almond' + arch: '--amd64 --armv7 --aarch64' diff --git a/almond/build.json b/almond/build.json new file mode 100644 index 0000000..6c82ce6 --- /dev/null +++ b/almond/build.json @@ -0,0 +1,10 @@ +{ + "build_from": { + "amd64": "homeassistant/amd64-base-debian:buster", + "armv7": "homeassistant/armv7-base-debian:buster", + "aarch64": "homeassistant/aarch64-base-debian:buster" + }, + "args": { + "ALMOND_COMMIT": "87d37637c8bcaea8a86d2e1eba039184d4434049" + } +} diff --git a/almond/config.json b/almond/config.json new file mode 100644 index 0000000..a62def1 --- /dev/null +++ b/almond/config.json @@ -0,0 +1,20 @@ +{ + "name": "Almond", + "version": "0.3", + "slug": "almond", + "description": "The home server version of Almond", + "url": "https://home-assistant.io/addons/almond/", + "arch": ["armv7", "aarch64", "amd64"], + "startup": "system", + "boot": "auto", + "discovery": ["almond"], + "ingress": true, + "panel_icon": "mdi:comment-eye-outline", + "homeassistant": "0.102.0b0", + "homeassistant_api": true, + "options": { + }, + "schema": { + }, + "image": "homeassistant/{arch}-addon-almond" +} diff --git a/almond/data/nginx.conf b/almond/data/nginx.conf new file mode 100644 index 0000000..281d921 --- /dev/null +++ b/almond/data/nginx.conf @@ -0,0 +1,59 @@ +worker_processes 1; +pid /var/run/nginx.pid; +error_log /dev/stdout info; +daemon off; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + proxy_read_timeout 1200; + gzip on; + gzip_disable "msie6"; + + upstream backend { + ip_hash; + server 127.0.0.1:3000; + } + + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + + # API & Ingress + server { + listen 3001 default_server; + listen 8099 default_server; + listen [::]:3001 default_server; + listen [::]:8099 default_server; + + allow 172.30.32.1; + allow 172.30.32.2; + deny all; + + server_name _; + access_log /dev/stdout combined; + + client_max_body_size 4G; + keepalive_timeout 5; + + root /dev/null; + + location / { + proxy_redirect off; + proxy_pass http://backend; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host "127.0.0.1:3000"; + proxy_set_header Origin "http://127.0.0.1:3000"; + } + } +} diff --git a/almond/data/run.sh b/almond/data/run.sh new file mode 100755 index 0000000..d1822ca --- /dev/null +++ b/almond/data/run.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bashio +WAIT_PIDS=() +TOKEN_VALID="$(python3 -c "import time; print((time.time() + 60 * 60 * 24 * 365 * 5) * 1000)")" + +ha_config=$(\ + bashio::var.json \ + host "$(hostname)" \ + port "3001" \ +) + +almond_config=$(\ + bashio::var.json \ + kind "io.home-assistant" \ + hassUrl "http://hassio/homeassistant" \ + accessToken "${HASSIO_TOKEN}" \ + refreshToken "" \ + accessTokenExpires "^${TOKEN_VALID}" \ +) + +# HA Discovery +if bashio::discovery "almond" "${ha_config}" > /dev/null; then + bashio::log.info "Successfully send discovery information to Home Assistant." +else + bashio::log.error "Discovery message to Home Assistant failed!" +fi + +# Ingress handling +# shellcheck disable=SC2155 +export THINGENGINE_BASE_URL=$(bashio::addon.ingress_entry) + +# Setup nginx +nginx -c /etc/nginx/nginx.conf & +WAIT_PIDS+=($!) + +# Skip Auth handling +if ! bashio::fs.file_exists "${THINGENGINE_HOME}/prefs.db"; then + mkdir -p "${THINGENGINE_HOME}" + echo '{"server-login":{"password":"x","salt":"x","sqliteKeySalt":"x"}}' > "${THINGENGINE_HOME}/prefs.db" +fi + +# Start Almond +yarn start & +WAIT_PIDS+=($!) + +# Insert HA connection settings +bashio::net.wait_for 3000 +if curl -f -s -X POST -H "Content-Type: application/json" -d "${almond_config}" http://127.0.0.1:3000/api/devices/create; then + bashio::log.info "Successfully register local Home Assistant on Almond" +else + bashio::log.error "Almond registration of local Home Assistant fails!" +fi + +# Register stop +function stop_addon() { + echo "Kill Processes..." + kill -15 "${WAIT_PIDS[@]}" + wait "${WAIT_PIDS[@]}" + echo "Done." +} +trap "stop_addon" SIGTERM SIGHUP + +# Wait until all is done +wait "${WAIT_PIDS[@]}" diff --git a/almond/logo.png b/almond/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..9172330fd62cdb7e3124131f03cbbef808ec99aa GIT binary patch literal 5736 zcmV-u7MJOXP)005u}0{{R3yb+fl00090P)t-s00030 z@Ad!d@&D`a|LgJp>hb^V@c--a|LgGo;pzYD@c-=b|LgJp>+t{U@c--Z|LpPq?C}5V z@c-=Y|LpMp>+t{V@&D`b|LpPq?D7BX@&D`a|LX7m?C}5Y^Z)Dc|LpMp>+t{U@7}0H zKs!AD>+tu(bl#~%-Kay|rbEMYFvWE+-KRy|s6yqaUEHce-={_Hx@5(6F~M>#->gQ& zbuQkgM8kG4FfA_LsYb?hGvTU8->OH&b27tmF5jy}!gMXbb1XwWJ@C6_+oV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