2025-04-21 23:51:59 +02:00
|
|
|
# syntax=docker/dockerfile:1.7
|
2025-11-20 00:10:19 +01:00
|
|
|
# Dockerfile
|
|
|
|
|
|
2026-09-07 08:13:09 +02:00
|
|
|
# Support both Home Assistant builds and standalone builds.
|
|
|
|
|
# Only Debian based images are supported (no Alpine).
|
2025-12-30 22:08:21 +01:00
|
|
|
ARG BUILD_FROM
|
2026-08-21 07:07:34 +02:00
|
|
|
ARG PYTHON_VERSION=3.13.15
|
2024-09-16 11:48:20 +02:00
|
|
|
|
2026-09-07 08:13:09 +02:00
|
|
|
# Builder and runtime share the same base so the copied virtualenv is ABI-safe.
|
|
|
|
|
# If BUILD_FROM is set (Home Assistant), use it; otherwise use python-slim.
|
|
|
|
|
FROM ${BUILD_FROM:-python:${PYTHON_VERSION}-slim} AS builder
|
|
|
|
|
|
|
|
|
|
# uv: pinned, copied as a static binary (no extra Python packages installed).
|
|
|
|
|
COPY --from=ghcr.io/astral-sh/uv:0.12.7 /uv /bin/uv
|
|
|
|
|
|
|
|
|
|
ENV UV_COMPILE_BYTECODE=1 \
|
|
|
|
|
UV_LINK_MODE=copy \
|
|
|
|
|
UV_PYTHON_DOWNLOADS=never \
|
|
|
|
|
UV_PROJECT_ENVIRONMENT=/opt/venv \
|
|
|
|
|
VIRTUAL_ENV=/opt/venv \
|
|
|
|
|
PATH="/opt/venv/bin:$PATH"
|
|
|
|
|
|
|
|
|
|
WORKDIR /opt/eos
|
|
|
|
|
|
|
|
|
|
# Build toolchain for the numpy/scipy/pandas/matplotlib stack. python3 is
|
|
|
|
|
# explicit because the Home Assistant base image ships without it.
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
|
python3 \
|
|
|
|
|
gcc g++ gfortran \
|
|
|
|
|
libopenblas-dev liblapack-dev \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
# Resolve and install dependencies from the lock file first. This layer stays
|
|
|
|
|
# cached as long as pyproject.toml / uv.lock are unchanged.
|
|
|
|
|
COPY pyproject.toml uv.lock ./
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
uv sync --frozen --no-dev --no-install-project
|
|
|
|
|
|
|
|
|
|
# Project sources and generated version (pyproject reads version from version.txt).
|
|
|
|
|
COPY src/ ./src
|
|
|
|
|
COPY scripts/get_version.py ./scripts/get_version.py
|
|
|
|
|
RUN python scripts/get_version.py > version.txt
|
|
|
|
|
|
|
|
|
|
# Install the project itself. Editable, because akkudoktoreos.core.version
|
|
|
|
|
# requires the src/akkudoktoreos layout at runtime; the runtime stage copies
|
|
|
|
|
# src/ back in.
|
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
|
|
|
uv sync --frozen --no-dev
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FROM ${BUILD_FROM:-python:${PYTHON_VERSION}-slim} AS runtime
|
|
|
|
|
|
|
|
|
|
# Supplied by Home Assistant, docker-compose and CI; "dev" marks an
|
|
|
|
|
# unversioned local build. CI stamps org.opencontainers.image.version via
|
|
|
|
|
# docker/metadata-action, so it is not set here.
|
|
|
|
|
ARG BUILD_VERSION=dev
|
2025-12-30 22:08:21 +01:00
|
|
|
|
|
|
|
|
LABEL \
|
2026-09-07 08:13:09 +02:00
|
|
|
io.hass.version="${BUILD_VERSION}" \
|
2025-12-30 22:08:21 +01:00
|
|
|
io.hass.type="addon" \
|
|
|
|
|
io.hass.arch="aarch64|amd64" \
|
2026-09-07 08:13:09 +02:00
|
|
|
source="https://github.com/Akkudoktor-EOS/EOS" \
|
|
|
|
|
org.opencontainers.image.source="https://github.com/Akkudoktor-EOS/EOS" \
|
|
|
|
|
org.opencontainers.image.licenses="Apache-2.0"
|
2024-09-16 11:48:20 +02:00
|
|
|
|
2024-10-07 20:56:10 +02:00
|
|
|
ENV EOS_DIR="/opt/eos"
|
2025-12-30 22:08:21 +01:00
|
|
|
# Create persistent data directory similar to home assistant add-on
|
|
|
|
|
# - EOS_DATA_DIR: Persistent data directory
|
|
|
|
|
# - MPLCONFIGDIR: user customizations to Mathplotlib
|
|
|
|
|
ENV EOS_DATA_DIR="/data"
|
|
|
|
|
ENV EOS_CACHE_DIR="${EOS_DATA_DIR}/cache"
|
2026-09-07 08:13:09 +02:00
|
|
|
# Written by EOS after resolving its startup configuration.
|
|
|
|
|
ENV EOS_HEALTHCHECK_PORT_FILE="${EOS_CACHE_DIR}/eos-healthcheck-port"
|
2025-12-30 22:08:21 +01:00
|
|
|
ENV EOS_OUTPUT_DIR="${EOS_DATA_DIR}/output"
|
|
|
|
|
ENV EOS_CONFIG_DIR="${EOS_DATA_DIR}/config"
|
|
|
|
|
ENV MPLCONFIGDIR="${EOS_DATA_DIR}/mplconfigdir"
|
2024-09-17 09:02:35 +02:00
|
|
|
|
2025-02-23 16:17:54 +01:00
|
|
|
# Overwrite when starting the container in a production environment
|
|
|
|
|
ENV EOS_SERVER__EOSDASH_SESSKEY=s3cr3t
|
|
|
|
|
|
2025-10-28 02:50:31 +01:00
|
|
|
# Set environment variables to reduce threading needs
|
|
|
|
|
ENV OPENBLAS_NUM_THREADS=1
|
|
|
|
|
ENV OMP_NUM_THREADS=1
|
|
|
|
|
ENV MKL_NUM_THREADS=1
|
|
|
|
|
ENV PIP_PROGRESS_BAR=off
|
|
|
|
|
ENV PIP_NO_COLOR=1
|
|
|
|
|
|
2025-12-30 22:08:21 +01:00
|
|
|
# Generic environment
|
|
|
|
|
ENV LANG=C.UTF-8
|
|
|
|
|
ENV VENV_PATH=/opt/venv
|
|
|
|
|
# - Use .venv for python commands
|
|
|
|
|
ENV PATH="$VENV_PATH/bin:$PATH"
|
|
|
|
|
|
2024-10-07 20:56:10 +02:00
|
|
|
WORKDIR ${EOS_DIR}
|
2024-09-16 11:48:20 +02:00
|
|
|
|
2026-09-07 08:13:09 +02:00
|
|
|
# Runtime shared libraries only (no -dev packages, no compilers). Create the eos
|
|
|
|
|
# user and the persistent data directories with eos ownership.
|
2025-12-30 22:08:21 +01:00
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
2026-09-07 08:13:09 +02:00
|
|
|
adduser python3 libopenblas0 liblapack3 \
|
|
|
|
|
&& adduser --system --group --no-create-home eos \
|
|
|
|
|
&& mkdir -p "${EOS_DATA_DIR}" "${EOS_CACHE_DIR}" "${EOS_OUTPUT_DIR}" "${EOS_CONFIG_DIR}" "${MPLCONFIGDIR}" \
|
|
|
|
|
&& chown -R eos:eos "${EOS_DATA_DIR}" \
|
2025-12-30 22:08:21 +01:00
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
2026-09-07 08:13:09 +02:00
|
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
|
|
|
# Editable install: the venv only points at the source tree, so it must be present.
|
2025-11-20 00:10:19 +01:00
|
|
|
COPY src/ ./src
|
2025-01-24 00:09:28 +01:00
|
|
|
|
2024-09-16 11:48:20 +02:00
|
|
|
ENTRYPOINT []
|
|
|
|
|
|
2025-12-30 22:08:21 +01:00
|
|
|
EXPOSE 8503
|
2026-09-07 08:13:09 +02:00
|
|
|
EXPOSE 8504
|
|
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
|
|
|
|
CMD ["python", "-m", "akkudoktoreos.server.container_healthcheck"]
|
2024-11-15 22:27:25 +01:00
|
|
|
|
2025-11-20 00:10:19 +01:00
|
|
|
# Ensure EOS and EOSdash bind to 0.0.0.0
|
2026-09-07 08:13:09 +02:00
|
|
|
# EOS is started with root privileges. EOS will drop root privileges and switch to user eos.
|
2025-12-30 22:08:21 +01:00
|
|
|
CMD ["python", "-m", "akkudoktoreos.server.eos", "--host", "0.0.0.0", "--run_as_user", "eos"]
|
2024-10-07 20:56:10 +02:00
|
|
|
|
2025-12-30 22:08:21 +01:00
|
|
|
# Persistent data
|
|
|
|
|
# (Not recognized by home assistant add-on management, but there we have /data anyway)
|
|
|
|
|
VOLUME ["${EOS_DATA_DIR}"]
|