Skip to content

Commit

Permalink
try and fail to get local addon working, but it'll be useful for cust… (
Browse files Browse the repository at this point in the history
#43)

* try and fail to get local addon working, but it'll be useful for custom_component i hope

* addon linter has maxdepth 2

* addon helper doesn't work without top level dirs
  • Loading branch information
akshaya-a authored Apr 17, 2024
1 parent 1ad489e commit 5d5c4bc
Show file tree
Hide file tree
Showing 64 changed files with 121 additions and 38 deletions.
10 changes: 10 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ghcr.io/home-assistant/devcontainer:addons

RUN apt-get update && apt-get install -y python3 python3-venv python3-pip

# https://code.visualstudio.com/remote/advancedcontainers/start-processes#_adding-startup-commands-to-the-docker-image-instead
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh

ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "sleep", "infinity" ]
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "Mindctrl Devcontainer based on HASS addon",
"build": {
"dockerfile": "Dockerfile"
},
"appPort": [
"7123:8123",
"7357:4357",
"80:80"
],
"postAttachCommand": ". .venv/bin/activate",
"runArgs": [
"-e",
"GIT_EDITOR=code --wait",
"--privileged"
],
"containerEnv": {
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}"
},
"customizations": {
"vscode": {
"extensions": [
"timonwong.shellcheck",
"esbenp.prettier-vscode",
"ms-python.python"
],
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/usr/bin/bash"
},
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "bash",
"python.terminal.activateEnvInCurrentTerminal": true,
"python.defaultInterpreterPath": ".venv/bin/python",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
}
}
},
"mounts": [
"type=volume,target=/var/lib/docker"
]
}
26 changes: 26 additions & 0 deletions .devcontainer/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

echo "Running mindctrl devcontainer entrypoint..."

echo "running original bootstrap"
bash devcontainer_bootstrap

if [ -d "./.venv" ]; then
echo ".venv does exist."
else
echo "Create venv"
python3 -m venv ./.venv
fi

echo "Activating venv"
source ./.venv/bin/activate
python -m pip install --upgrade pip

echo "install source"
python -m pip install -e ./python

echo "install requirements"
python -m pip install -r ./tests/test-requirements.txt


exec "$@"
21 changes: 2 additions & 19 deletions .github/workflows/addon-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,14 @@ on:
- cron: "0 0 * * *"

jobs:
find:
name: Find add-ons
runs-on: ubuntu-latest
outputs:
addons: ${{ steps.addons.outputs.addons_list }}
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4

- name: 🔍 Find add-on directories
id: addons
uses: home-assistant/actions/helpers/find-addons@master

lint:
name: Lint add-on ${{ matrix.path }}
name: Lint add-on mindctrl
runs-on: ubuntu-latest
needs: find
strategy:
matrix:
path: ${{ fromJson(needs.find.outputs.addons) }}
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4

- name: 🚀 Run Home Assistant Add-on Lint
uses: frenck/[email protected]
with:
path: "./${{ matrix.path }}"
path: "./addons/mindctrl"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
*.code-workspace
addons/mindctrl-dev/
6 changes: 1 addition & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
"--port",
"5002"
],
"jinja": true,
"cwd": "${workspaceFolder}/mindctrl-addon/rootfs/usr/bin",
"env": {
"PYTHONPATH": "${workspaceFolder}/mindctrl-addon/rootfs/usr/bin"
}
"jinja": true
}
]
}
16 changes: 15 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Start Home Assistant",
"type": "shell",
"command": "supervisor_run",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
},
{
"label": "docker-build",
"type": "shell",
"command": "docker build -t mindctrl:latest mindctrl-addon",
"command": "docker build -t mindctrl-addon:latest addons/mindctrl",
"group": {
"kind": "build",
"isDefault": true
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mindctrl-addon/build.yaml → addons/mindctrl/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ build_from:
labels:
org.opencontainers.image.title: "LLMOps for Home Assistant"
org.opencontainers.image.description: "MLflow Store+Gateway+Model Server"
org.opencontainers.image.source: "https://github.com/akshaya-a/mindctrl/tree/main/mindctrl-addon"
org.opencontainers.image.source: "https://github.com/akshaya-a/mindctrl/tree/main/addons/mindctrl"
org.opencontainers.image.licenses: "Apache License 2.0"
4 changes: 2 additions & 2 deletions mindctrl-addon/config.yaml → addons/mindctrl/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Mindctrl"
description: "LLMOps for Homeassistant"
version: "0.0.55"
url: "https://github.com/akshaya-a/mindctrl/tree/main/mindctrl-addon"
version: "0.0.56"
url: "https://github.com/akshaya-a/mindctrl/tree/main/addons/mindctrl"
slug: "mindctrl"
init: false
arch:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ bashio::log.info "Starting dashboard script in $PWD"

ingress_entry=$(bashio::addon.ingress_entry)
bashio::log.info "ingress_entry: ${ingress_entry}"
bashio::log.info "ingress prefix: ${ingress_entry}/dapr-dashboard"
# Am I nervous about these dependencies on dapr with a bunch of undocumented stuff? Yes.
# Am I going to do it anyway? Yes.
# https://github.com/dapr/dashboard/blob/a92b8cd20d97080f07518ced9a5e8d0a58168ad9/cmd/webserver.go#L148C47-L148C63
if [[ -n "$ingress_entry" ]]; then
export SERVER_BASE_HREF="${ingress_entry}/dapr-dashboard"
export SERVER_BASE_HREF="${ingress_entry}/dapr-dashboard/dapr-dashboard/"
bashio::log.info "running dashboard with prefix $SERVER_BASE_HREF"
fi


Expand Down
3 changes: 3 additions & 0 deletions python/src/mindctrl/db/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ async def setup_db(settings: PostgresStoreSettings) -> AsyncEngine:
await conn.execute(text(ENABLE_PGVECTOR))
await conn.execute(text(CREATE_SUMMARY_TABLE))
await conn.execute(text(CONVERT_TO_HYPERTABLE))
# TODO: add an index on metadata columns (entity type? etc)
# https://docs.timescale.com/tutorials/latest/financial-ingest-real-time/financial-ingest-dataset/#creating-a-hypertable

# Not available for apache licensed version
# await conn.execute(text(ADD_RETENTION_POLICY))
await conn.commit()
Expand Down
3 changes: 2 additions & 1 deletion python/src/mindctrl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ def read_root(request: Request, response_class=HTMLResponse):

ws_base = str(request.base_url).replace("http", "ws").rstrip("/")
ws_url = (
f"ws://{ws_base}{ingress_header}{ROUTE_PREFIX}/ui/ws" # lol - do this better
f"{ws_base}{ingress_header}{ROUTE_PREFIX}/ui/ws" # lol - do this better
if ingress_header
else f"{request.url_for('websocket_endpoint')}"
)
_logger.info(f"websocket url: {ws_url}")
ingress_header = ingress_header or ""
chat_url = (
f"{ingress_header}{ROUTE_PREFIX}/deployed-models/chat/labels/latest/invocations"
Expand Down
10 changes: 5 additions & 5 deletions scripts/copy_content_to_addon_context.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

# Assert that the script is starting from the repository root
if [ ! -d "python" ] || [ ! -d "mindctrl-addon" ]; then
if [ ! -d "python" ] || [ ! -d "addons/mindctrl" ]; then
echo "This script must be run from the root of the repository."
exit 1
fi

# Define source and target directories
src_dir="python"
target_dir="mindctrl-addon/rootfs/.context/pysrc"
target_dir="addons/mindctrl/rootfs/.context/pysrc"

# Check if source directory exists
if [ ! -d "$src_dir" ]; then
Expand All @@ -32,7 +32,7 @@ echo "Python source files have been copied to $target_dir"

# Define source and target directories
src_dir="services"
target_dir="mindctrl-addon/rootfs/.context/services"
target_dir="addons/mindctrl/rootfs/.context/services"

# Check if source directory exists
if [ ! -d "$src_dir" ]; then
Expand All @@ -54,5 +54,5 @@ cp -r "$src_dir"/* "$target_dir"

echo "Services have been copied to $target_dir"

echo "Copying install_traefik.sh to mindctrl-addon/rootfs/.context/install_traefik.sh"
cp scripts/install_traefik.sh mindctrl-addon/rootfs/.context/install_traefik.sh
echo "Copying install_traefik.sh to addons/mindctrl/rootfs/.context/install_traefik.sh"
cp scripts/install_traefik.sh addons/mindctrl/rootfs/.context/install_traefik.sh
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def addon_app_settings(
mqtt_host, mqtt_port = get_external_host_port(mosquitto)
pg_host, pg_port = get_external_host_port(postgres)

addon_folder = repo_root_dir / "mindctrl-addon"
addon_folder = repo_root_dir / "addons/mindctrl"
# TODO: make all the bash scripts just call these things factored out into utils without pytest
# copy_content_to_addon_context.sh
shutil.copytree(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@pytest.fixture
def config_as_obj(repo_root_dir: Path):
config_file = repo_root_dir / "mindctrl-addon" / "config.yaml"
config_file = repo_root_dir / "addons/mindctrl" / "config.yaml"
config = yaml.safe_load(config_file.read_text())
return config

Expand Down

0 comments on commit 5d5c4bc

Please sign in to comment.