From 17798dee1e90d7cb2b07ca6caaa4000787612de5 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 3 Jun 2018 19:22:25 +0200 Subject: [PATCH] HassIO add-on pre-built images --- esphomeyaml-edge/Dockerfile | 43 ++++++++++++++++++++++++++++ esphomeyaml-edge/build.json | 10 +++++++ esphomeyaml-edge/config.json | 29 +++++++++++++++++++ esphomeyaml-edge/platformio.ini | 12 ++++++++ esphomeyaml/Dockerfile | 50 +++++++++++++++++++++++++-------- esphomeyaml/build.json | 10 +++++++ esphomeyaml/config.json | 3 +- esphomeyaml/helpers.py | 6 ++-- esphomeyaml/platformio.ini | 12 ++++++++ esphomeyaml/wizard.py | 2 +- requirements.txt | 2 ++ setup.py | 2 ++ 12 files changed, 164 insertions(+), 17 deletions(-) create mode 100644 esphomeyaml-edge/Dockerfile create mode 100644 esphomeyaml-edge/build.json create mode 100644 esphomeyaml-edge/config.json create mode 100644 esphomeyaml-edge/platformio.ini create mode 100644 esphomeyaml/build.json create mode 100644 esphomeyaml/platformio.ini diff --git a/esphomeyaml-edge/Dockerfile b/esphomeyaml-edge/Dockerfile new file mode 100644 index 0000000000..b569cb72d5 --- /dev/null +++ b/esphomeyaml-edge/Dockerfile @@ -0,0 +1,43 @@ +# Dockerfile for HassIO add-on +ARG BUILD_FROM=ubuntu:bionic +FROM ${BUILD_FROM} + +# Re-declare BUILD_FROM to fix weird docker issue +ARG BUILD_FROM + +# On amd64 and alike, using ubuntu as the base is better as building +# for the ESP32 only works with glibc (and ubuntu). However, on armhf +# the build toolchain frequently procudes segfaults under ubuntu. +# -> Use ubuntu for most architectures, except alpine for armhf +# +# * python and related required because this is a python project +# * git required for platformio library dependencies downloads +# * libc6-compat and openssh required on alpine for weird reasons +# * disable platformio telemetry on install +RUN /bin/bash -c "if [[ '$BUILD_FROM' = *\"ubuntu\"* ]]; then \ + apt-get update && apt-get install -y --no-install-recommends \ + python python-pip python-setuptools git && \ + rm -rf /var/lib/apt/lists/* /tmp/*; \ + else \ + apk add --no-cache python2 py2-pip git openssh libc6-compat; \ + fi" && \ + pip install --no-cache-dir platformio && \ + platformio settings set enable_telemetry No + + +# Create fake project to make platformio install all depdencies. +# * Ignore build errors from platformio - empty project +# * On alpine, only install ESP8266 toolchain +COPY platformio.ini /pio/platformio.ini +RUN /bin/bash -c "if [[ '$BUILD_FROM' = *\"ubuntu\"* ]]; then \ + platformio run -e espressif32 -e espressif8266 -d /pio; \ + else \ + echo \"\$(head -8 /pio/platformio.ini)\" >/pio/platformio.ini; \ + platformio run -e espressif8266 -d /pio; \ + fi"; rm -rf /pio + +# Install latest esphomeyaml from git +RUN pip install --no-cache-dir \ + git+git://github.com/OttoWinter/esphomeyaml.git + +CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"] diff --git a/esphomeyaml-edge/build.json b/esphomeyaml-edge/build.json new file mode 100644 index 0000000000..a306cb0cc3 --- /dev/null +++ b/esphomeyaml-edge/build.json @@ -0,0 +1,10 @@ +{ + "squash": false, + "build_from": { + "aarch64": "arm64v8/ubuntu:bionic", + "amd64": "ubuntu:bionic", + "armhf": "homeassistant/armhf-base:latest", + "i386": "i386/ubuntu:bionic" + }, + "args": {} +} diff --git a/esphomeyaml-edge/config.json b/esphomeyaml-edge/config.json new file mode 100644 index 0000000000..d5a0ec4920 --- /dev/null +++ b/esphomeyaml-edge/config.json @@ -0,0 +1,29 @@ +{ + "name": "esphomeyaml-edge", + "version": "dev", + "slug": "esphomeyaml-edge", + "description": "Development build of the esphomeyaml HassIO add-on.", + "url": "https://esphomelib.com/esphomeyaml/index.html", + "startup": "application", + "webui": "http://[HOST]:[PORT:6052]", + "boot": "auto", + "ports": { + "6052/tcp": 6052, + "6053/tcp": 6053 + }, + "arch": [ + "aarch64", + "amd64", + "armhf", + "i386" + ], + "auto_uart": true, + "map": [ + "config:rw" + ], + "options": {}, + "environment": { + "ESPHOMEYAML_OTA_HOST_PORT": "6053" + }, + "schema": {} +} diff --git a/esphomeyaml-edge/platformio.ini b/esphomeyaml-edge/platformio.ini new file mode 100644 index 0000000000..7f6ab6851d --- /dev/null +++ b/esphomeyaml-edge/platformio.ini @@ -0,0 +1,12 @@ +; This file allows the docker build file to install the required platformio +; platforms + +[env:espressif8266] +platform = espressif8266 +board = nodemcuv2 +framework = arduino + +[env:espressif32] +platform = espressif32 +board = nodemcu-32s +framework = arduino diff --git a/esphomeyaml/Dockerfile b/esphomeyaml/Dockerfile index 65189f2f46..99090fc49b 100644 --- a/esphomeyaml/Dockerfile +++ b/esphomeyaml/Dockerfile @@ -1,20 +1,46 @@ # Dockerfile for HassIO add-on +ARG BUILD_FROM=ubuntu:bionic +FROM ${BUILD_FROM} + +# Re-declare BUILD_FROM to fix weird docker issue ARG BUILD_FROM -FROM $BUILD_FROM +ARG BUILD_VERSION -ENV LANG C.UTF-8 - -# Install requirements for add-on -RUN apk add --no-cache python2 py2-pip git openssh libc6-compat && \ +# On amd64 and alike, using ubuntu as the base is better as building +# for the ESP32 only works with glibc (and ubuntu). However, on armhf +# the build toolchain frequently procudes segfaults under ubuntu. +# -> Use ubuntu for most architectures, except alpine for armhf +# +# * python and related required because this is a python project +# * git required for platformio library dependencies downloads +# * libc6-compat and openssh required on alpine for weird reasons +# * disable platformio telemetry on install +RUN /bin/bash -c "if [[ '$BUILD_FROM' = *\"ubuntu\"* ]]; then \ + apt-get update && apt-get install -y --no-install-recommends \ + python python-pip python-setuptools git && \ + rm -rf /var/lib/apt/lists/* /tmp/*; \ + else \ + apk add --no-cache python2 py2-pip git openssh libc6-compat; \ + fi" && \ pip install --no-cache-dir platformio && \ - platformio platform install espressif8266 \ - --with-package tool-esptool \ - --with-package framework-arduinoespressif8266 \ - --with-package tool-mkspiffs \ - --with-package tool-espotapy + platformio settings set enable_telemetry No + +# Create fake project to make platformio install all depdencies. +# * Ignore build errors from platformio - empty project +# * On alpine, only install ESP8266 toolchain +COPY platformio.ini /pio/platformio.ini +RUN /bin/bash -c "if [[ '$BUILD_FROM' = *\"ubuntu\"* ]]; then \ + platformio run -e espressif32 -e espressif8266 -d /pio; \ + else \ + echo \"\$(head -8 /pio/platformio.ini)\" >/pio/platformio.ini; \ + platformio run -e espressif8266 -d /pio; \ + fi"; rm -rf /pio + +# Install latest esphomeyaml from git RUN pip install --no-cache-dir \ - git+git://github.com/OttoWinter/esphomeyaml.git@v1.6.0 \ - tornado esptool + esphomeyaml==${BUILD_VERSION} \ + tornado \ + esptool CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"] diff --git a/esphomeyaml/build.json b/esphomeyaml/build.json new file mode 100644 index 0000000000..a306cb0cc3 --- /dev/null +++ b/esphomeyaml/build.json @@ -0,0 +1,10 @@ +{ + "squash": false, + "build_from": { + "aarch64": "arm64v8/ubuntu:bionic", + "amd64": "ubuntu:bionic", + "armhf": "homeassistant/armhf-base:latest", + "i386": "i386/ubuntu:bionic" + }, + "args": {} +} diff --git a/esphomeyaml/config.json b/esphomeyaml/config.json index 7c1df9dfb3..f6cf4affcc 100644 --- a/esphomeyaml/config.json +++ b/esphomeyaml/config.json @@ -19,5 +19,6 @@ "environment": { "ESPHOMEYAML_OTA_HOST_PORT": "6053" }, - "schema": {} + "schema": {}, + "image": "ottowinter/esphomeyaml-hassio-{arch}" } diff --git a/esphomeyaml/helpers.py b/esphomeyaml/helpers.py index f6313cf097..aa98bb4592 100644 --- a/esphomeyaml/helpers.py +++ b/esphomeyaml/helpers.py @@ -407,11 +407,11 @@ def process_lambda(value, parameters, capture='=', return_type=None): yield return parts = value.parts[:] - for i in range(1, len(parts), 2): + for i, id in enumerate(value.requires_ids): var = None - for var in get_variable(parts[i]): + for var in get_variable(id): yield - parts[i] = var._ + parts[i*2 + 1] = var._ yield LambdaExpression(parts, parameters, capture, return_type) return diff --git a/esphomeyaml/platformio.ini b/esphomeyaml/platformio.ini new file mode 100644 index 0000000000..7f6ab6851d --- /dev/null +++ b/esphomeyaml/platformio.ini @@ -0,0 +1,12 @@ +; This file allows the docker build file to install the required platformio +; platforms + +[env:espressif8266] +platform = espressif8266 +board = nodemcuv2 +framework = arduino + +[env:espressif32] +platform = espressif32 +board = nodemcu-32s +framework = arduino diff --git a/esphomeyaml/wizard.py b/esphomeyaml/wizard.py index 2f91712ae9..23de624bf3 100644 --- a/esphomeyaml/wizard.py +++ b/esphomeyaml/wizard.py @@ -306,5 +306,5 @@ def wizard(path): print(color('bold_white', " discovery: True")) print() print(" > Then follow the rest of the getting started guide:") - print(" > https://esphomelib.com/esphomeyaml/getting-started.html") + print(" > https://esphomelib.com/esphomeyaml/guides/getting_started_command_line.html") return 0 diff --git a/requirements.txt b/requirements.txt index 1cec484c87..11a5a0924c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ platformio==3.5.2 pyyaml==3.12 paho-mqtt==1.3.1 colorlog==3.1.2 +tornado==5.0.2 +esptool==2.3.1 diff --git a/setup.py b/setup.py index 870023beed..2b5e80e465 100755 --- a/setup.py +++ b/setup.py @@ -27,6 +27,8 @@ REQUIRES = [ 'pyyaml>=3.12', 'paho-mqtt>=1.3.1', 'colorlog>=3.1.2', + 'tornado>=5.0.0', + 'esptool>=2.3.1', ] CLASSIFIERS = [