From 218b3c4961121fdaaa478b5d2bd46304e0a6f7c9 Mon Sep 17 00:00:00 2001 From: Tobias Leuschner Date: Sat, 7 Mar 2026 12:08:34 +0100 Subject: [PATCH] fix: use python:3.12-alpine3.21 from Docker Hub, rewrite run.sh without bashio --- fichero_printer/Dockerfile | 10 +++++----- fichero_printer/build.yaml | 10 +++++----- fichero_printer/run.sh | 37 ++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/fichero_printer/Dockerfile b/fichero_printer/Dockerfile index d897c0c..41a8c8e 100644 --- a/fichero_printer/Dockerfile +++ b/fichero_printer/Dockerfile @@ -1,18 +1,18 @@ ARG BUILD_FROM FROM $BUILD_FROM -# System libraries: BlueZ for BLE/RFCOMM + build tools for numpy & pillow +# BlueZ for BLE/RFCOMM + build tools for packages without binary wheels RUN apk add --no-cache \ + bash \ bluez \ dbus \ gcc \ musl-dev \ libjpeg-turbo-dev \ - zlib-dev \ - libffi-dev + zlib-dev # Install Python runtime dependencies -RUN pip3 install --no-cache-dir --break-system-packages \ +RUN pip install --no-cache-dir \ "bleak>=0.21" \ "numpy" \ "pillow" \ @@ -21,7 +21,7 @@ RUN pip3 install --no-cache-dir --break-system-packages \ "python-multipart>=0.0.9" # Remove build-only packages to keep the image slim -RUN apk del gcc musl-dev libffi-dev +RUN apk del gcc musl-dev # Copy the fichero Python package into the container WORKDIR /app diff --git a/fichero_printer/build.yaml b/fichero_printer/build.yaml index 8235ba3..305711b 100644 --- a/fichero_printer/build.yaml +++ b/fichero_printer/build.yaml @@ -1,6 +1,6 @@ build_from: - aarch64: "ghcr.io/home-assistant/aarch64-base-python:3.12" - amd64: "ghcr.io/home-assistant/amd64-base-python:3.12" - armhf: "ghcr.io/home-assistant/armhf-base-python:3.12" - armv7: "ghcr.io/home-assistant/armv7-base-python:3.12" - i386: "ghcr.io/home-assistant/i386-base-python:3.12" + aarch64: "python:3.12-alpine3.21" + amd64: "python:3.12-alpine3.21" + armhf: "python:3.12-alpine3.21" + armv7: "python:3.12-alpine3.21" + i386: "python:3.12-alpine3.21" diff --git a/fichero_printer/run.sh b/fichero_printer/run.sh index d8af223..08bde2f 100644 --- a/fichero_printer/run.sh +++ b/fichero_printer/run.sh @@ -1,29 +1,24 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash +#!/bin/sh +# shellcheck shell=sh set -e -declare port -declare ble_address -declare transport -declare channel +CONFIG_PATH="/data/options.json" -port=$(bashio::config 'port') -transport=$(bashio::config 'transport') -channel=$(bashio::config 'channel') +# Read add-on options from the HA-provided JSON file using Python (already installed). +PORT=$(python3 -c "import json; d=json.load(open('${CONFIG_PATH}')); print(d.get('port', 8765))") +TRANSPORT=$(python3 -c "import json; d=json.load(open('${CONFIG_PATH}')); print(d.get('transport', 'ble'))") +CHANNEL=$(python3 -c "import json; d=json.load(open('${CONFIG_PATH}')); print(d.get('channel', 1))") +BLE_ADDRESS=$(python3 -c "import json; d=json.load(open('${CONFIG_PATH}')); print(d.get('ble_address') or '')") -# Pass connection settings to the Python module via environment variables. -# The module reads these at import time, so they must be exported before uvicorn -# imports fichero.api. -export FICHERO_TRANSPORT="${transport}" -export FICHERO_CHANNEL="${channel}" +export FICHERO_TRANSPORT="${TRANSPORT}" +export FICHERO_CHANNEL="${CHANNEL}" -ble_address=$(bashio::config 'ble_address') -if [ -n "${ble_address}" ]; then - export FICHERO_ADDR="${ble_address}" - bashio::log.info "Using fixed Bluetooth address: ${ble_address}" +if [ -n "${BLE_ADDRESS}" ]; then + export FICHERO_ADDR="${BLE_ADDRESS}" + echo "[fichero] Using fixed Bluetooth address: ${BLE_ADDRESS}" else - bashio::log.info "No address configured – will auto-scan for printer on first request." + echo "[fichero] No address configured - will auto-scan for printer on first request." fi -bashio::log.info "Starting Fichero Printer API on 0.0.0.0:${port} (transport: ${transport})..." -exec uvicorn fichero.api:app --host 0.0.0.0 --port "${port}" +echo "[fichero] Starting Fichero Printer API on 0.0.0.0:${PORT} (transport: ${TRANSPORT})..." +exec uvicorn fichero.api:app --host 0.0.0.0 --port "${PORT}"