Fix host network (#280)

* Fix Add-On host network mode

* Split up esphomeyaml tests

* Fix perms

* Fix

* Add esphomeyaml_version option

* Revert change to travis.yml
This commit is contained in:
Otto Winter 2019-01-02 12:21:26 +01:00 committed by GitHub
parent 2e65d6c02c
commit a8c17e5d05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 17 deletions

View file

@ -58,10 +58,15 @@ Example add-on configuration:
{ {
"ssl": false, "ssl": false,
"certfile": "fullchain.pem", "certfile": "fullchain.pem",
"keyfile": "privkey.pem" "keyfile": "privkey.pem",
"port": 6052
} }
``` ```
### Option: `port`
The port to start the dashboard server on. Default is 6052.
### Option: `ssl` ### Option: `ssl`
Enables/Disables encrypted SSL (HTTPS) connections to the web server of this add-on. Enables/Disables encrypted SSL (HTTPS) connections to the web server of this add-on.
@ -87,6 +92,15 @@ The private key file to use for SSL. If this file doesn't exist, the add-on star
Adding this option to the add-on configuration allows you to disable Adding this option to the add-on configuration allows you to disable
authentication by setting it to `true`. authentication by setting it to `true`.
### Option: `esphomeyaml_version`
Manually override which esphomeyaml version to use in the addon.
For example to install the latest development version, use `"esphomeyaml_version": "dev"`,
or for version 1.10.0: `"esphomeyaml_version": "v1.10.0""`.
Please note that this does not always work and is only meant for testing, usually the
esphomeyaml add-on and dashboard version must match to guarantee a working system.
[discord-shield]: https://img.shields.io/discord/429907082951524364.svg [discord-shield]: https://img.shields.io/discord/429907082951524364.svg
[dht22]: https://esphomelib.com/esphomeyaml/components/sensor/dht.html [dht22]: https://esphomelib.com/esphomeyaml/components/sensor/dht.html
[discord]: https://discord.me/KhAMKrd [discord]: https://discord.me/KhAMKrd

View file

@ -18,9 +18,6 @@
"homeassistant_api": false, "homeassistant_api": false,
"host_network": true, "host_network": true,
"boot": "auto", "boot": "auto",
"ports": {
"6052/tcp": 6052
},
"map": [ "map": [
"ssl", "ssl",
"config:rw" "config:rw"
@ -28,12 +25,15 @@
"options": { "options": {
"ssl": false, "ssl": false,
"certfile": "fullchain.pem", "certfile": "fullchain.pem",
"keyfile": "privkey.pem" "keyfile": "privkey.pem",
"port": 6052
}, },
"schema": { "schema": {
"ssl": "bool", "ssl": "bool",
"certfile": "str", "certfile": "str",
"keyfile": "str", "keyfile": "str",
"leave_front_door_open": "bool?" "port": "int",
"leave_front_door_open": "bool?",
"esphomeyaml_version": "str?"
} }
} }

View file

@ -8,6 +8,7 @@ source /usr/lib/hassio-addons/base.sh
declare certfile declare certfile
declare keyfile declare keyfile
declare port
mkdir -p /var/log/nginx mkdir -p /var/log/nginx
@ -22,3 +23,6 @@ if hass.config.true 'ssl'; then
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf
fi fi
port=$(hass.config.get 'port')
sed -i "s/%%port%%/${port}/g" /etc/nginx/nginx.conf

View file

@ -0,0 +1,14 @@
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: esphomeyaml
# This files installs the user esphomeyaml version if specified
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
declare esphomeyaml_version
if hass.config.has_value 'esphomeyaml_version'; then
esphomeyaml_version=$(hass.config.get 'esphomeyaml_version')
pip2 install --no-cache-dir --no-binary :all: "https://github.com/OttoWinter/esphomeyaml/archive/${esphomeyaml_version}.zip"
end

View file

@ -15,7 +15,7 @@ http {
upstream esphomeyaml { upstream esphomeyaml {
ip_hash; ip_hash;
server 127.0.0.1:80; server unix:/var/run/esphomeyaml.sock;
} }
map $http_upgrade $connection_upgrade { map $http_upgrade $connection_upgrade {
default upgrade; default upgrade;
@ -24,7 +24,7 @@ http {
server { server {
server_name hassio.local; server_name hassio.local;
listen 6052 default_server ssl; listen %%port%% default_server ssl;
root /dev/null; root /dev/null;
ssl_certificate /ssl/%%certfile%%; ssl_certificate /ssl/%%certfile%%;

View file

@ -15,7 +15,7 @@ http {
upstream esphomeyaml { upstream esphomeyaml {
ip_hash; ip_hash;
server 127.0.0.1:80; server unix:/var/run/esphomeyaml.sock;
} }
map $http_upgrade $connection_upgrade { map $http_upgrade $connection_upgrade {
default upgrade; default upgrade;
@ -24,7 +24,7 @@ http {
server { server {
server_name hassio.local; server_name hassio.local;
listen 6052 default_server; listen %%port%% default_server;
root /dev/null; root /dev/null;
location / { location / {

View file

@ -11,4 +11,4 @@ if hass.config.true 'leave_front_door_open'; then
fi fi
hass.log.info "Starting esphomeyaml dashboard..." hass.log.info "Starting esphomeyaml dashboard..."
exec esphomeyaml /config/esphomeyaml dashboard --port 80 --hassio exec esphomeyaml /config/esphomeyaml dashboard --socket /var/run/esphomeyaml.sock --hassio

View file

@ -450,6 +450,8 @@ def parse_args(argv):
help="Internal flag used to tell esphomeyaml is started as a Hass.io " help="Internal flag used to tell esphomeyaml is started as a Hass.io "
"add-on.", "add-on.",
action="store_true") action="store_true")
dashboard.add_argument("--socket",
help="Make the dashboard serve under a unix socket", type=str)
subparsers.add_parser('hass-config', subparsers.add_parser('hass-config',
help="Dump the configuration entries that should be added " help="Dump the configuration entries that should be added "

View file

@ -13,6 +13,8 @@ import threading
import tornado import tornado
import tornado.concurrent import tornado.concurrent
import tornado.httpserver
import tornado.netutil
import tornado.gen import tornado.gen
import tornado.ioloop import tornado.ioloop
import tornado.iostream import tornado.iostream
@ -548,9 +550,16 @@ def start_web_server(args):
storage.save(path) storage.save(path)
COOKIE_SECRET = storage.cookie_secret COOKIE_SECRET = storage.cookie_secret
app = make_app(args.verbose)
if args.socket is not None:
_LOGGER.info("Starting dashboard web server on unix socket %s and configuration dir %s...",
args.socket, CONFIG_DIR)
server = tornado.httpserver.HTTPServer(app)
socket = tornado.netutil.bind_unix_socket(args.socket, mode=0o666)
server.add_socket(socket)
else:
_LOGGER.info("Starting dashboard web server on port %s and configuration dir %s...", _LOGGER.info("Starting dashboard web server on port %s and configuration dir %s...",
args.port, CONFIG_DIR) args.port, CONFIG_DIR)
app = make_app(args.verbose)
app.listen(args.port) app.listen(args.port)
if args.open_ui: if args.open_ui:
@ -567,3 +576,5 @@ def start_web_server(args):
STOP_EVENT.set() STOP_EVENT.set()
PING_REQUEST.set() PING_REQUEST.set()
ping_thread.join() ping_thread.join()
if args.socket is not None:
os.remove(args.socket)