Skip to content

Commit

Permalink
upgrade homeassistant-core container
Browse files Browse the repository at this point in the history
  • Loading branch information
ms1design committed Nov 20, 2024
1 parent d4410f1 commit 1592c83
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 11 deletions.
16 changes: 12 additions & 4 deletions packages/smart-home/homeassistant-core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
# requires: '>=34.1.0'
# docs: docs.md
# depends: [homeassistant-base, ciso8601, psutil-home-assistant, ffmpeg]
# test: test.py
# test: [go2rtc_test.sh, sqlite3_test.py, test.py]
# notes: The `homeassistant-core` wheel that's build is saved in `/usr/src/homeassistant`
#---
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

ARG HA_VERSION
ARG HA_VERSION \
SQLITE_VERSION

SHELL ["/bin/bash", "-exo", "pipefail", "-c"]

Expand All @@ -20,12 +21,19 @@ WORKDIR /usr/src
ENV S6_SERVICES_READYTIME=50 \
S6_SERVICES_GRACETIME=240000 \
UV_SYSTEM_PYTHON=true \
UV_NO_CACHE=true \
LD_PRELOAD="${LD_PRELOAD:-}:/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000"
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
SQLITE_VERSION="${SQLITE_VERSION}"

COPY *.sh /tmp/homeassistant/

RUN /tmp/homeassistant/build.sh \
&& ln -s /data/homeassistant /config
&& ln -s /data/homeassistant /config \
&& curl -L https://github.com/AlexxIT/go2rtc/releases/download/v1.9.7/go2rtc_linux_arm64 --output /bin/go2rtc \
&& chmod +x /bin/go2rtc \
&& go2rtc --version

ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/usr/local/lib

WORKDIR /config
38 changes: 33 additions & 5 deletions packages/smart-home/homeassistant-core/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,46 @@ apt-get update
apt-get install -y --no-install-recommends \
autoconf \
libpcap0.8 \
libturbojpeg
libturbojpeg \
tcl
apt-get clean
rm -rf /var/lib/apt/lists/*

python3 -m sqlite3 -v

# Download and build SQLite
mkdir -p /tmp/sqlite
# Download SQLite from GitHub mirror
wget --quiet --show-progress --progress=bar:force:noscroll \
https://github.com/sqlite/sqlite/archive/refs/tags/version-${SQLITE_VERSION}.tar.gz \
-O /tmp/sqlite/sqlite.tar.gz
# Extract and build SQLite
tar -xzf /tmp/sqlite/sqlite.tar.gz -C /tmp/sqlite
cd /tmp/sqlite/sqlite-version-${SQLITE_VERSION}
./configure --prefix=/usr/local
make -j$(nproc)
make install

ln -sf /usr/local/lib/libsqlite3.so /usr/lib/libsqlite3.so
ln -sf /usr/local/lib/libsqlite3.so.0 /usr/lib/libsqlite3.so.0

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/usr/local/lib
ldconfig

ls -l /usr/lib/libsqlite3.so
ls -l /usr/lib/libsqlite3.so.0

cd /
rm -rf /tmp/sqlite

python3 -m sqlite3 -v

pip3 install --no-cache-dir --ignore-installed blinker
pip3 install --no-cache-dir --verbose uv==0.1.27 ruff
pip3 install --no-cache-dir --verbose uv==0.5.0 ruff

# Install homeassistant-core
git clone --branch=${HA_VERSION} https://github.com/home-assistant/core /usr/src/homeassistant
uv pip install --no-cache-dir --verbose \
-r /usr/src/homeassistant/requirements.txt \
-r /usr/src/homeassistant/requirements_all.txt
uv pip install --no-cache-dir --verbose -r /usr/src/homeassistant/requirements_all.txt
uv pip install -e /usr/src/homeassistant
python3 -m compileall /usr/src/homeassistant

Expand Down
5 changes: 3 additions & 2 deletions packages/smart-home/homeassistant-core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from packaging.version import Version


def create_package(version, default=False) -> list:
def create_package(version, sqlite_version='3.40.1', default=False) -> list:
pkg = package.copy()
url = 'https://version.home-assistant.io/stable.json'
wanted_version = get_json_value_from_url(url, 'homeassistant.default') if version == 'latest' else version
pkg['name'] = f'homeassistant-core:{version}'
pkg['name'] = f'homeassistant-core:{wanted_version}'
ha_version = Version(wanted_version)

if ha_version.major >= 2024:
Expand All @@ -23,6 +23,7 @@ def create_package(version, default=False) -> list:

pkg['build_args'] = {
'HA_VERSION': wanted_version,
'SQLITE_VERSION': sqlite_version
}

if default:
Expand Down
5 changes: 5 additions & 0 deletions packages/smart-home/homeassistant-core/go2rtc_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo "testing go2rtc..."
go2rtc --version
echo "go2rtc ok"
25 changes: 25 additions & 0 deletions packages/smart-home/homeassistant-core/sqlite3_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
print("testing sqlite3...")

import os
import sqlite3
from packaging.version import Version


SQLITE_VERSION = os.getenv('SQLITE_VERSION', None)

current_version = Version(sqlite3.sqlite_version)
required_version = Version(SQLITE_VERSION)

if not SQLITE_VERSION:
raise AssertionError(
f"SQLITE_VERSION env variable is not set!"
)

print(f'sqlite3 version: {current_version} [required: {required_version}]')

if current_version < required_version:
raise AssertionError(
f"SQLite version is {current_version}, but {required_version} is required."
)

print("sqlite3 ok")
4 changes: 4 additions & 0 deletions packages/smart-home/homeassistant-core/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from pkg_resources import get_distribution

print("testing homeassistant...")

import homeassistant

print(f"Home Assistant version: {get_distribution("homeassistant").version}")

print("homeassistant OK")

0 comments on commit 1592c83

Please sign in to comment.