Refactor add-on (#232)

* Refactor add-on

* Replace NGinx Configuration

* Ingress!!!

* More tweaks, renames and other touches

* Revert accidental upgrade of JupyterLab
This commit is contained in:
Franck Nijhof 2021-02-02 22:36:04 +01:00 committed by GitHub
parent d504c96223
commit 5a7eb72d4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 260 additions and 377 deletions

View file

@ -20,7 +20,7 @@ jobs:
build: ${{ steps.information.outputs.build }} build: ${{ steps.information.outputs.build }}
description: ${{ steps.information.outputs.description }} description: ${{ steps.information.outputs.description }}
name: ${{ steps.information.outputs.name }} name: ${{ steps.information.outputs.name }}
slug: ${{ steps.information.outputs.slug }} slug: "jupyterlab"
target: ${{ steps.information.outputs.target }} target: ${{ steps.information.outputs.target }}
steps: steps:
- name: ⤵️ Check out code from GitHub - name: ⤵️ Check out code from GitHub

View file

@ -28,7 +28,7 @@ jobs:
description: ${{ steps.information.outputs.description }} description: ${{ steps.information.outputs.description }}
environment: ${{ steps.release.outputs.environment }} environment: ${{ steps.release.outputs.environment }}
name: ${{ steps.information.outputs.name }} name: ${{ steps.information.outputs.name }}
slug: ${{ steps.information.outputs.slug }} slug: "jupyterlab"
target: ${{ steps.information.outputs.target }} target: ${{ steps.information.outputs.target }}
version: ${{ steps.release.outputs.version }} version: ${{ steps.release.outputs.version }}
steps: steps:

View file

@ -25,5 +25,5 @@ Even better: You could submit a pull request with a fix / new feature!
developers, or if you do not have permission to do that, you may request developers, or if you do not have permission to do that, you may request
the second reviewer to merge it for you. the second reviewer to merge it for you.
[github]: https://github.com/hassio-addons/addon-jupyterlab-lite/issues [github]: https://github.com/hassio-addons/addon-jupyterlab/issues
[prs]: https://github.com/hassio-addons/addon-jupyterlab-lite/pulls [prs]: https://github.com/hassio-addons/addon-jupyterlab/pulls

View file

@ -1,4 +1,4 @@
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
[![GitHub Release][releases-shield]][releases] [![GitHub Release][releases-shield]][releases]
![Project Stage][project-stage-shield] ![Project Stage][project-stage-shield]
@ -105,30 +105,30 @@ SOFTWARE.
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg [amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg [armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg
[armv7-shield]: https://img.shields.io/badge/armv7-no-red.svg [armv7-shield]: https://img.shields.io/badge/armv7-no-red.svg
[commits-shield]: https://img.shields.io/github/commit-activity/y/hassio-addons/addon-jupyterlab-lite.svg [commits-shield]: https://img.shields.io/github/commit-activity/y/hassio-addons/addon-jupyterlab.svg
[commits]: https://github.com/hassio-addons/addon-jupyterlab-lite/commits/main [commits]: https://github.com/hassio-addons/addon-jupyterlab/commits/main
[contributors]: https://github.com/hassio-addons/addon-jupyterlab-lite/graphs/contributors [contributors]: https://github.com/hassio-addons/addon-jupyterlab/graphs/contributors
[discord-ha]: https://discord.gg/c5DvZ4e [discord-ha]: https://discord.gg/c5DvZ4e
[discord-shield]: https://img.shields.io/discord/478094546522079232.svg [discord-shield]: https://img.shields.io/discord/478094546522079232.svg
[discord]: https://discord.me/hassioaddons [discord]: https://discord.me/hassioaddons
[docs]: https://github.com/hassio-addons/addon-jupyterlab-lite/blob/main/jupyterlab-lite/DOCS.md [docs]: https://github.com/hassio-addons/addon-jupyterlab/blob/main/jupyterlab/DOCS.md
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg [forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
[forum]: https://community.home-assistant.io/t/home-assistant-community-add-on-jupyterlab-lite/87337?u=frenck [forum]: https://community.home-assistant.io/t/home-assistant-community-add-on-jupyterlab-lite/87337?u=frenck
[frenck]: https://github.com/frenck [frenck]: https://github.com/frenck
[github-actions-shield]: https://github.com/hassio-addons/addon-jupyterlab-lite/workflows/CI/badge.svg [github-actions-shield]: https://github.com/hassio-addons/addon-jupyterlab/workflows/CI/badge.svg
[github-actions]: https://github.com/hassio-addons/addon-jupyterlab-lite/actions [github-actions]: https://github.com/hassio-addons/addon-jupyterlab/actions
[github-sponsors-shield]: https://frenck.dev/wp-content/uploads/2019/12/github_sponsor.png [github-sponsors-shield]: https://frenck.dev/wp-content/uploads/2019/12/github_sponsor.png
[github-sponsors]: https://github.com/sponsors/frenck [github-sponsors]: https://github.com/sponsors/frenck
[home-assistant]: https://home-assistant.io [home-assistant]: https://home-assistant.io
[i386-shield]: https://img.shields.io/badge/i386-no-red.svg [i386-shield]: https://img.shields.io/badge/i386-no-red.svg
[issue]: https://github.com/hassio-addons/addon-jupyterlab-lite/issues [issue]: https://github.com/hassio-addons/addon-jupyterlab/issues
[license-shield]: https://img.shields.io/github/license/hassio-addons/addon-jupyterlab-lite.svg [license-shield]: https://img.shields.io/github/license/hassio-addons/addon-jupyterlab.svg
[maintenance-shield]: https://img.shields.io/maintenance/yes/2021.svg [maintenance-shield]: https://img.shields.io/maintenance/yes/2021.svg
[patreon-shield]: https://frenck.dev/wp-content/uploads/2019/12/patreon.png [patreon-shield]: https://frenck.dev/wp-content/uploads/2019/12/patreon.png
[patreon]: https://www.patreon.com/frenck [patreon]: https://www.patreon.com/frenck
[project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg [project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg
[python-packages]: https://pypi.org/ [python-packages]: https://pypi.org/
[reddit]: https://reddit.com/r/homeassistant [reddit]: https://reddit.com/r/homeassistant
[releases-shield]: https://img.shields.io/github/release/hassio-addons/addon-jupyterlab-lite.svg [releases-shield]: https://img.shields.io/github/release/hassio-addons/addon-jupyterlab.svg
[releases]: https://github.com/hassio-addons/addon-jupyterlab-lite/releases [releases]: https://github.com/hassio-addons/addon-jupyterlab/releases
[repository]: https://github.com/hassio-addons/repository [repository]: https://github.com/hassio-addons/repository

View file

@ -1,4 +1,4 @@
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
[![Release][release-shield]][release] ![Project Stage][project-stage-shield] ![Project Maintenance][maintenance-shield] [![Release][release-shield]][release] ![Project Stage][project-stage-shield] ![Project Maintenance][maintenance-shield]
@ -76,4 +76,4 @@ If you are more interested in stable releases of our add-ons:
[project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg [project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg
[release-shield]: https://img.shields.io/badge/version-{{ version }}-blue.svg [release-shield]: https://img.shields.io/badge/version-{{ version }}-blue.svg
[release]: {{ repo }}/tree/{{ version }} [release]: {{ repo }}/tree/{{ version }}
[screenshot]: https://github.com/hassio-addons/addon-jupyterlab-lite/raw/main/images/screenshot.png [screenshot]: https://github.com/hassio-addons/addon-jupyterlab/raw/main/images/screenshot.png

View file

@ -1,4 +1,4 @@
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
JupyterLab is an open-source web application that allows you to create and share JupyterLab is an open-source web application that allows you to create and share
documents that contain live code, equations, visualizations and narrative text. documents that contain live code, equations, visualizations and narrative text.
@ -14,10 +14,10 @@ reproducible computing, based on the Jupyter Notebook and Architecture.
The installation of this add-on is pretty straightforward and not different in The installation of this add-on is pretty straightforward and not different in
comparison to installing any other Home Assistant add-on. comparison to installing any other Home Assistant add-on.
1. Search for the "JupyterLab Lite" add-on in the Supervisor add-on store 1. Search for the "JupyterLab" add-on in the Supervisor add-on store
and install it. and install it.
1. Start the "JupyterLab Lite" add-on 1. Start the "JupyterLab" add-on
1. Check the logs of the "JupyterLab Lite" add-on to see if everything went well. 1. Check the logs of the "JupyterLab" add-on to see if everything went well.
## Configuration ## Configuration
@ -28,9 +28,6 @@ Example add-on configuration:
```yaml ```yaml
log_level: info log_level: info
github_access_token: abcdef1234567890abcdef0123456789abcdef01 github_access_token: abcdef1234567890abcdef0123456789abcdef01
ssl: true
certfile: fullchain.pem
keyfile: privkey.pem
system_packages: system_packages:
- ffmpeg - ffmpeg
init_commands: init_commands:
@ -69,23 +66,6 @@ There is a chapter in this document with instruction on obtaining such a token.
**Note**: _This option support secrets, e.g., `!secret github_token`._ **Note**: _This option support secrets, e.g., `!secret github_token`._
### Option: `ssl`
Enables/Disables SSL (HTTPS) on the JupyterLab Set it `true` to enable it,
`false` otherwise.
### Option: `certfile`
The certificate file to use for SSL.
**Note**: _The file MUST be stored in `/ssl/`, which is the default_
### Option: `keyfile`
The private key file to use for SSL.
**Note**: _The file MUST be stored in `/ssl/`, which is the default_
### Option: `system_packages` ### Option: `system_packages`
Allows you to specify additional [Alpine packages][alpine-packages] to be Allows you to specify additional [Alpine packages][alpine-packages] to be
@ -100,23 +80,6 @@ Customize your environment even more with the `init_commands` option.
Add one or more shell commands to the list, and they will be executed every Add one or more shell commands to the list, and they will be executed every
single time this add-on starts. single time this add-on starts.
## Embedding into Home Assistant
It is possible to embed JupyterLab directly into Home Assistant, allowing
you to access the JupyterLab through the Home Assistant frontend.
Home Assistant provides the `panel_iframe` integration, for these purposes.
Example configuration:
```yaml
panel_iframe:
jupyterlab:
title: JupyterLab
icon: mdi:flask
url: https://addres.to.your.home.assistant:7777
```
## Getting a GitHub access token ## Getting a GitHub access token
You can get an access token by following these steps: You can get an access token by following these steps:
@ -194,15 +157,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
[alpine-packages]: https://pkgs.alpinelinux.org/packages [alpine-packages]: https://pkgs.alpinelinux.org/packages
[contributors]: https://github.com/hassio-addons/addon-jupyterlab-lite/graphs/contributors [contributors]: https://github.com/hassio-addons/addon-jupyterlab/graphs/contributors
[discord-ha]: https://discord.gg/c5DvZ4e [discord-ha]: https://discord.gg/c5DvZ4e
[discord]: https://discord.me/hassioaddons [discord]: https://discord.me/hassioaddons
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg [forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
[forum]: https://community.home-assistant.io/t/home-assistant-community-add-on-jupyterlab-lite/87337?u=frenck [forum]: https://community.home-assistant.io/t/home-assistant-community-add-on-jupyterlab/87337?u=frenck
[frenck]: https://github.com/frenck [frenck]: https://github.com/frenck
[github-verify]: https://help.github.com/articles/verifying-your-email-address [github-verify]: https://help.github.com/articles/verifying-your-email-address
[issue]: https://github.com/hassio-addons/addon-jupyterlab-lite/issues [issue]: https://github.com/hassio-addons/addon-jupyterlab/issues
[python-packages]: https://pypi.org/ [python-packages]: https://pypi.org/
[reddit]: https://reddit.com/r/homeassistant [reddit]: https://reddit.com/r/homeassistant
[releases]: https://github.com/hassio-addons/addon-jupyterlab-lite/releases [releases]: https://github.com/hassio-addons/addon-jupyterlab/releases
[semver]: http://semver.org/spec/v2.0.0.htm [semver]: http://semver.org/spec/v2.0.0.htm

View file

@ -1,4 +1,4 @@
ARG BUILD_FROM=hassioaddons/debian-base:3.2.3 ARG BUILD_FROM=ghcr.io/hassio-addons/debian-base/amd64:4.1.2
# hadolint ignore=DL3006 # hadolint ignore=DL3006
FROM ${BUILD_FROM} FROM ${BUILD_FROM}
@ -25,26 +25,25 @@ RUN \
gpg=2.2.12-1+deb10u1 \ gpg=2.2.12-1+deb10u1 \
libffi-dev=3.2.1-9 \ libffi-dev=3.2.1-9 \
libffi6=3.2.1-9 \ libffi6=3.2.1-9 \
libfreetype6-dev=2.9.1-3+deb10u1 \ libfreetype6-dev=2.9.1-3+deb10u2 \
libfreetype6=2.9.1-3+deb10u1 \ libfreetype6=2.9.1-3+deb10u2 \
libjpeg62-turbo-dev=1:1.5.2-2+b1 \ libjpeg62-turbo-dev=1:1.5.2-2+deb10u1 \
libjpeg62-turbo=1:1.5.2-2+b1 \ libjpeg62-turbo=1:1.5.2-2+deb10u1 \
libmariadb-dev=1:10.3.25-0+deb10u1 \ libmariadb-dev=1:10.3.25-0+deb10u1 \
libmariadb3=1:10.3.25-0+deb10u1 \ libmariadb3=1:10.3.25-0+deb10u1 \
libnginx-mod-http-lua=1.14.2-2+deb10u3 \ libnginx-mod-http-lua=1.14.2-2+deb10u3 \
libpng-dev=1.6.36-6 \ libpng-dev=1.6.36-6 \
libpng16-16=1.6.36-6 \ libpng16-16=1.6.36-6 \
libpq-dev=11.7-0+deb10u1 \ libpq-dev=11.9-0+deb10u1 \
libpq5=11.7-0+deb10u1 \ libpq5=11.9-0+deb10u1 \
libssl-dev=1.1.1d-0+deb10u3 \ libssl-dev=1.1.1d-0+deb10u4 \
libtiff5-dev=4.1.0+git191117-2~deb10u1 \ libtiff5-dev=4.1.0+git191117-2~deb10u1 \
libxml2-dev=2.9.4+dfsg1-7+b3 \ libxml2-dev=2.9.4+dfsg1-7+deb10u1 \
libxml2=2.9.4+dfsg1-7+b3 \ libxml2=2.9.4+dfsg1-7+deb10u1 \
libxslt1-dev=1.1.32-2.2~deb10u1 \ libxslt1-dev=1.1.32-2.2~deb10u1 \
libxslt1.1=1.1.32-2.2~deb10u1 \ libxslt1.1=1.1.32-2.2~deb10u1 \
libzmq3-dev=4.3.1-4+deb10u2 \ libzmq3-dev=4.3.1-4+deb10u2 \
libzmq5=4.3.1-4+deb10u2 \ libzmq5=4.3.1-4+deb10u2 \
luarocks=2.4.2+dfsg-1 \
nginx=1.14.2-2+deb10u3 \ nginx=1.14.2-2+deb10u3 \
pandoc>=2.2.1-3 \ pandoc>=2.2.1-3 \
pkg-config=0.29-6 \ pkg-config=0.29-6 \
@ -54,19 +53,17 @@ RUN \
python3-minimal=3.7.3-1 \ python3-minimal=3.7.3-1 \
zlib1g-dev=1:1.2.11.dfsg-1 \ zlib1g-dev=1:1.2.11.dfsg-1 \
\ \
&& luarocks install lua-resty-http 0.15-0 \
\
&& curl -sL https://deb.nodesource.com/setup_12.x | bash - \ && curl -sL https://deb.nodesource.com/setup_12.x | bash - \
\ \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
nodejs=12.19.0-1nodesource1 \ nodejs=12.20.1-1nodesource1 \
\ \
&& curl https://bootstrap.pypa.io/get-pip.py | python3 \ && curl https://bootstrap.pypa.io/get-pip.py | python3 \
\ \
&& update-alternatives \ && update-alternatives \
--install /usr/bin/python python /usr/bin/python3 10 \ --install /usr/bin/python python /usr/bin/python3 10 \
\ \
&& pip3 install --no-cache-dir numpy==1.19.4 \ && pip3 install --no-cache-dir numpy==1.20.0 \
&& pip3 install --no-cache-dir -r /opt/requirements.txt \ && pip3 install --no-cache-dir -r /opt/requirements.txt \
\ \
&& jupyter labextension install \ && jupyter labextension install \

View file

@ -1,7 +1,6 @@
{ {
"build_from": { "build_from": {
"aarch64": "hassioaddons/debian-base-aarch64:3.2.3", "aarch64": "ghcr.io/hassio-addons/debian-base/aarch64:4.1.2",
"amd64": "hassioaddons/debian-base-amd64:3.2.3", "amd64": "ghcr.io/hassio-addons/debian-base/amd64:4.1.2"
"armhf": "hassioaddons/debian-base-armhf:3.2.3"
} }
} }

View file

@ -1,32 +1,22 @@
{ {
"name": "JupyterLab Lite", "name": "JupyterLab",
"version": "dev", "version": "dev",
"slug": "jupyterlablite", "slug": "jupyterlablite",
"description": "Create documents containing live code, equations, visualizations, and explanatory text", "description": "Create documents containing live code, equations, visualizations, and explanatory text",
"url": "https://github.com/hassio-addons/addon-jupyterlab-lite", "url": "https://github.com/hassio-addons/addon-jupyterlab",
"webui": "[PROTO:ssl]://[HOST]:[PORT:7777]", "ingress": true,
"arch": ["aarch64", "amd64", "armhf"], "panel_icon": "mdi:flask-outline",
"hassio_api": true, "arch": ["aarch64", "amd64"],
"auth_api": true,
"homeassistant_api": true, "homeassistant_api": true,
"ports": { "map": ["config:rw", "share:rw"],
"7777/tcp": 7777
},
"map": ["config:rw", "share:rw", "ssl"],
"options": { "options": {
"github_access_token": "", "github_access_token": "",
"ssl": false,
"certfile": "fullchain.pem",
"keyfile": "privkey.pem",
"system_packages": [], "system_packages": [],
"init_commands": [] "init_commands": []
}, },
"schema": { "schema": {
"log_level": "list(trace|debug|info|notice|warning|error|fatal)?", "log_level": "list(trace|debug|info|notice|warning|error|fatal)?",
"github_access_token": "password", "github_access_token": "password",
"ssl": "bool",
"certfile": "str",
"keyfile": "str",
"system_packages": ["str"], "system_packages": ["str"],
"init_commands": ["str"] "init_commands": ["str"]
} }

View file

@ -10,10 +10,10 @@ jupyterlab==2.2.9
matplotlib==3.3.3 matplotlib==3.3.3
mysqlclient==2.0.3 mysqlclient==2.0.3
nbconvert==6.0.7 nbconvert==6.0.7
numpy==1.19.5 numpy==1.20.0
pandas-datareader==0.9.0 pandas-datareader==0.9.0
pandas==1.2.1 pandas==1.2.1
psycopg2==2.8.6 psycopg2==2.8.6
python-dateutil==2.8.1 python-dateutil==2.8.1
scrapy==2.4.1 scrapy==2.4.1
SQLAlchemy==1.3.22 SQLAlchemy==1.3.23

View file

@ -1,6 +0,0 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite
# This files check if all user configuration requirements are met
# ==============================================================================
bashio::config.require.ssl

View file

@ -1,24 +0,0 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite
# Configures NGINX for use with JupyterLab
# ==============================================================================
declare certfile
declare keyfile
declare dns_host
mkdir -p /var/log/nginx
if bashio::config.true 'ssl'; then
rm /etc/nginx/nginx.conf
mv /etc/nginx/nginx-ssl.conf /etc/nginx/nginx.conf
certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')
sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/nginx.conf
sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/nginx.conf
fi
dns_host=$(bashio::dns.host)
sed -i "s/%%dns_host%%/${dns_host}/g" /etc/nginx/nginx.conf

View file

@ -1,13 +0,0 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite
# Install the users GitHub Access token into JupyterLab
# ==============================================================================
readonly CONFIG_PATH="/etc/jupyter/jupyter_notebook_config.py"
# Set password
if bashio::config.has_value 'github_access_token'; then
token=$(bashio::config 'github_access_token')
sed -i "s/c.GitHubConfig.access_token\\ .*/c.GitHubConfig.access_token\\ =\\ '${token}'/" "${CONFIG_PATH}" \
|| bashio::exit.nok 'Failed setting up GitHub access token'
fi

View file

@ -1,11 +0,0 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite
# Executes user configured/requested commands on startup
# ==============================================================================
if bashio::config.has_value 'init_commands'; then
while read -r cmd; do
eval "${cmd}" \
|| bashio::exit.nok "Failed executing init command: ${cmd}"
done <<< "$(bashio::config 'init_commands')"
fi

View file

@ -1,7 +1,7 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Ensure directories in the persistent storage exists # Configure JupterLabs
# ============================================================================== # ==============================================================================
if ! bashio::fs.directory_exists '/data/user-settings'; then if ! bashio::fs.directory_exists '/data/user-settings'; then
mkdir -p /data/user-settings \ mkdir -p /data/user-settings \
@ -20,4 +20,14 @@ if ! bashio::fs.directory_exists '/data/local'; then
|| bashio::exit.nok \ || bashio::exit.nok \
'Failed creating persistent local directory' 'Failed creating persistent local directory'
fi fi
ln -s /data/local /root/.local ln -s /data/local /root/.local
bashio::var.json \
entry "$(bashio::addon.ingress_entry)" \
token "$(bashio::config 'github_access_token')" \
| tempio \
-template /etc/jupyter/jupyter_notebook_config.gtpl \
-out /etc/jupyter/jupyter_notebook_config.py

View file

@ -0,0 +1,12 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: JupyterLab
# Configures NGINX for use with JupyterLab
# ==============================================================================
# Generate Ingress configuration
bashio::var.json \
entry "$(bashio::addon.ingress_entry)" \
| tempio \
-template /etc/nginx/templates/ingress.gtpl \
-out /etc/nginx/servers/ingress.conf

View file

@ -1,6 +1,6 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Ensures the JupyterLab notebooks directory exists # Ensures the JupyterLab notebooks directory exists
# ============================================================================== # ==============================================================================
readonly BOOKS="/config/notebooks/" readonly BOOKS="/config/notebooks/"
@ -20,11 +20,6 @@ if ! bashio::fs.directory_exists '/config/notebooks'; then
"${BOOKS}bokeh-examples" \ "${BOOKS}bokeh-examples" \
|| bashio::exit.nok \ || bashio::exit.nok \
'Failed installing Bokeh example notebooks' 'Failed installing Bokeh example notebooks'
ln -sf \
"${BOOKS}home-assistant/~ GETTING STARTED.ipynb" \
"${BOOKS}GETTING STARTED.ipynb"
else else
if [ -z "$(git -C ${BOOKS}/home-assistant status --untracked-files=no --porcelain)" ]; if [ -z "$(git -C ${BOOKS}/home-assistant status --untracked-files=no --porcelain)" ];
then then

View file

@ -1,7 +1,7 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Install user configured/requested packages # Install user configured requested packages & commands
# ============================================================================== # ==============================================================================
if bashio::config.has_value 'system_packages'; then if bashio::config.has_value 'system_packages'; then
apt-get update \ apt-get update \
@ -12,3 +12,10 @@ if bashio::config.has_value 'system_packages'; then
|| bashio::exit.nok "Failed installing package ${package}" || bashio::exit.nok "Failed installing package ${package}"
done done
fi fi
if bashio::config.has_value 'init_commands'; then
while read -r cmd; do
eval "${cmd}" \
|| bashio::exit.nok "Failed executing init command: ${cmd}"
done <<< "$(bashio::config 'init_commands')"
fi

View file

@ -6,7 +6,7 @@ c = get_config()
# NotebookApp configuration # NotebookApp configuration
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
c.GitHubConfig.access_token = '' c.GitHubConfig.access_token = '{{ .token }}'
c.JupyterApp.answer_yes = True c.JupyterApp.answer_yes = True
c.LabApp.user_settings_dir = '/data/user-settings' c.LabApp.user_settings_dir = '/data/user-settings'
c.LabApp.workspaces_dir = '/data/workspaces' c.LabApp.workspaces_dir = '/data/workspaces'
@ -14,7 +14,7 @@ c.NotebookApp.allow_origin = '*'
c.NotebookApp.allow_password_change = False c.NotebookApp.allow_password_change = False
c.NotebookApp.allow_remote_access = True c.NotebookApp.allow_remote_access = True
c.NotebookApp.allow_root = True c.NotebookApp.allow_root = True
c.NotebookApp.base_url = '/' c.NotebookApp.base_url = '{{ .entry }}'
c.NotebookApp.ip = '127.0.0.1' c.NotebookApp.ip = '127.0.0.1'
c.NotebookApp.notebook_dir = '/config/notebooks' c.NotebookApp.notebook_dir = '/config/notebooks'
c.NotebookApp.open_browser = False c.NotebookApp.open_browser = False

View file

@ -1,83 +0,0 @@
local http = require "resty.http"
local auths = ngx.shared.auths
function authenticate()
--- Test Authentication header is set and with a value
local header = ngx.req.get_headers()['Authorization']
if header == nil or header:find(" ") == nil then
return false
end
local divider = header:find(' ')
if header:sub(0, divider-1) ~= 'Basic' then
return false
end
local auth = ngx.decode_base64(header:sub(divider+1))
if auth == nil or auth:find(':') == nil then
return false
end
divider = auth:find(':')
local username = auth:sub(0, divider-1)
local password = auth:sub(divider+1)
--- Check if authentication is cached
if auths:get(username) == password then
ngx.log(ngx.DEBUG, "Authenticated user against Home Assistant (cache).")
return true
end
--- HTTP request against the Supervisor API
local httpc = http.new()
local res, err = httpc:request_uri("http://supervisor.local.hass.io/auth", {
method = "POST",
body = ngx.encode_args({["username"]=username, ["password"]=password}),
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["X-Supervisor-Token"] = os.getenv("SUPERVISOR_TOKEN"),
},
keepalive_timeout = 60,
keepalive_pool = 10
})
--- Error during API request
if err then
ngx.log(ngx.WARN, "Error during Home Assistant user authentication.", err)
return false
end
--- No result? Something went wrong...
if not res then
ngx.log(ngx.WARN, "Error during Home Assistant user authentication.")
return false
end
--- Valid response, the username/password is valid
if res.status == 200 then
ngx.log(ngx.INFO, "Authenticated user against Home Assistant.")
auths:set(username, password, 60)
return true
end
--- Whatever the response is, it is invalid
ngx.log(ngx.WARN, "Authentication against Home Assistant failed!")
return false
end
-- Only authenticate if its not disabled
if not os.getenv('DISABLE_HA_AUTHENTICATION') then
--- Try to authenticate against HA
local authenticated = authenticate()
--- If authentication failed, throw a basic auth
if not authenticated then
ngx.header.content_type = 'text/plain'
ngx.header.www_authenticate = 'Basic realm="Home Assistant"'
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.say('401 Access Denied')
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
end

View file

@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

View file

@ -0,0 +1,15 @@
proxy_http_version 1.1;
proxy_ignore_client_abort off;
proxy_read_timeout 86400s;
proxy_redirect off;
proxy_send_timeout 86400s;
proxy_max_temp_file_size 0;
proxy_set_header Accept-Encoding "";
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;

View file

@ -0,0 +1,10 @@
root /dev/null;
server_name $hostname;
client_max_body_size 64m;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires off;

View file

@ -0,0 +1,3 @@
upstream backend {
server 127.0.0.1:28459;
}

View file

@ -1,73 +0,0 @@
worker_processes 1;
pid /var/run/nginx.pid;
error_log stderr;
env SUPERVISOR_TOKEN;
env DISABLE_HA_AUTHENTICATION;
load_module "/usr/lib/nginx/modules/ndk_http_module.so";
load_module "/usr/lib/nginx/modules/ngx_http_lua_module.so";
events {
worker_connections 1024;
}
http {
access_log stdout;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
lua_shared_dict auths 16k;
resolver %%dns_host%%;
upstream jupyter {
ip_hash;
server 127.0.0.1:28459;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
server_name hassio.local;
listen 7777 default_server ssl;
root /dev/null;
ssl_certificate /ssl/%%certfile%%;
ssl_certificate_key /ssl/%%keyfile%%;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA;
ssl_ecdh_curve secp384r1;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
location / {
access_by_lua_file /etc/nginx/ha-auth.lua;
proxy_redirect off;
proxy_pass http://jupyter;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Authorization "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}
}

View file

@ -1,58 +1,45 @@
worker_processes 1; # Run nginx in foreground.
pid /var/run/nginx.pid; daemon off;
error_log stderr;
env SUPERVISOR_TOKEN;
env DISABLE_HA_AUTHENTICATION;
load_module "/usr/lib/nginx/modules/ndk_http_module.so";
load_module "/usr/lib/nginx/modules/ngx_http_lua_module.so";
# This is run inside Docker.
user root;
# Pid storage location.
pid /var/run/nginx.pid;
# Set number of worker processes.
worker_processes 1;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Write error log to the add-on log.
error_log off;
# Load allowed environment vars
env SUPERVISOR_TOKEN;
# Max num of simultaneous connections by a worker process.
events { events {
worker_connections 1024; worker_connections 512;
} }
http { http {
access_log stdout; access_log off;
include mime.types; client_max_body_size 4G;
default_type application/octet-stream; default_type application/octet-stream;
sendfile on; gzip on;
keepalive_timeout 65; keepalive_timeout 65;
lua_shared_dict auths 16k; sendfile on;
resolver %%dns_host%%; server_tokens off;
client_max_body_size 0; tcp_nodelay on;
tcp_nopush on;
upstream jupyter {
ip_hash;
server 127.0.0.1:28459;
}
map $http_upgrade $connection_upgrade { map $http_upgrade $connection_upgrade {
default upgrade; default upgrade;
'' close; '' close;
} }
server { include /etc/nginx/includes/upstream.conf;
server_name hassio.local; include /etc/nginx/servers/*.conf;
listen 7777 default_server;
root /dev/null;
location / {
access_by_lua_file /etc/nginx/ha-auth.lua;
proxy_redirect off;
proxy_pass http://jupyter;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Authorization "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}
} }

View file

@ -0,0 +1 @@
Without requirements or design, programming is the art of adding bugs to an empty text file. (Louis Srygley)

View file

@ -0,0 +1,13 @@
server {
listen 8099 default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
location / {
allow 172.30.32.2;
deny all;
proxy_pass http://backend{{ .entry }}/;
}
}

View file

@ -1,6 +1,6 @@
#!/usr/bin/execlineb -S0 #!/usr/bin/execlineb -S0
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Take down the S6 supervision tree when the Jupyter daemon fails # Take down the S6 supervision tree when the Jupyter daemon fails
# ============================================================================== # ==============================================================================
if -n { s6-test $# -ne 0 } if -n { s6-test $# -ne 0 }

View file

@ -1,7 +1,7 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# shellcheck disable=SC2191 # shellcheck disable=SC2191
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Runs Jupyter # Runs Jupyter
# ============================================================================== # ==============================================================================
declare -a options declare -a options

View file

@ -1,6 +1,6 @@
#!/usr/bin/execlineb -S0 #!/usr/bin/execlineb -S0
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Take down the S6 supervision tree when Nginx fails # Take down the S6 supervision tree when Nginx fails
# ============================================================================== # ==============================================================================
if -n { s6-test $# -ne 0 } if -n { s6-test $# -ne 0 }

View file

@ -1,16 +1,11 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Home Assistant Community Add-on: JupyterLab Lite # Home Assistant Community Add-on: JupyterLab
# Runs the Nginx daemon # Runs the Nginx daemon
# ============================================================================== # ==============================================================================
# Wait for JupyterLab to become available # Wait for JupyterLab to become available
s6-svwait -u -t 5000 /var/run/s6/services/jupyter bashio::net.wait_for 28459
timeout 15 \
bash -c \
'until echo > /dev/tcp/localhost/28459 ; do sleep 0.5; done' \
> /dev/null 2>&1
bashio::log.info "Starting NGinx..." bashio::log.info "Starting NGinx..."
exec nginx
exec nginx -g "daemon off;"