# sm121 HA add-on image — the launcher as a 24/7 Home Assistant add-on
# (specs/tech-architecture/ha-addon-recipe-repos.md).
#
# Multi-stage: the launcher is COMPILED IN-CONTAINER (stage 1) so the
# binary always matches the container's architecture (no cross-toolchain
# on the host). Build context = the repo root (trimmed by .dockerignore
# to src/ + locales/ + host-scripts/ + the cargo manifest).
#
#   make addon-image
#   scripts/smoke-addon.sh     # entrypoint + file:// repo + curl /api/state

# --- stage 1: compile ----------------------------------------------------------
# (matches the repo toolchain — edition 2024 + let-chains need rust ≥ 1.88)
FROM rust:1.98-bookworm AS build
WORKDIR /src
COPY Cargo.toml Cargo.lock ./
COPY src/ src/
COPY locales/ locales/
COPY host-scripts/ host-scripts/
RUN cargo build --release

# --- stage 2: the add-on -------------------------------------------------------
FROM debian:bookworm-slim

# git (recipe-repo sync) + jq (env → config generation) + ca-certs (https)
RUN apt-get update \
 && apt-get install -y --no-install-recommends git ca-certificates jq \
 && rm -rf /var/lib/apt/lists/*

COPY --from=build /src/target/release/sm121 /usr/local/bin/sm121
COPY docker-images/sm121-addon/entrypoint.sh /entrypoint.sh
RUN chmod 755 /usr/local/bin/sm121 /entrypoint.sh

ENV SM121_WEB_PORT=3100
EXPOSE 3100
ENTRYPOINT ["/entrypoint.sh"]
