166 lines
5.4 KiB
Docker
166 lines
5.4 KiB
Docker
#FROM python:alpine as base
|
|
#FROM python:latest as base
|
|
|
|
FROM python:3.12 as base
|
|
|
|
MAINTAINER "ben <ben@sudo.is>"
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
ENV TZ=UTC
|
|
ENV TERM=xterm-256color
|
|
|
|
ARG HASS_UID=1229
|
|
ARG HASS_GID=1229
|
|
|
|
# python:latest is debian -> glibc
|
|
#ARG LIBC="gnu"
|
|
# python:alpine -> musl
|
|
#ARG LIBC="musl"
|
|
|
|
#COPY deb/deps.txt /tmp/deps.txt
|
|
# xargs -a /tmp/deps.txt apt-get -y install && \
|
|
RUN set -xe && \
|
|
groupadd -g ${HASS_GID} hass && \
|
|
useradd -u ${HASS_UID} -g ${HASS_GID} -d /var/lib/hass --system -m hass && \
|
|
apt-get update && \
|
|
apt-get clean && \
|
|
mkdir /usr/local/etc/hass /etc/hass && \
|
|
chown -R hass:hass /usr/local/etc/hass /etc/hass && \
|
|
apt-get install -y \
|
|
openssh-client \
|
|
mariadb-client \
|
|
avahi-daemon avahi-utils \
|
|
python3-dev git gcc build-essential linux-headers-generic \
|
|
python3-bluez bluez bluez-hcidump \
|
|
python3-zmq libczmq-dev libczmq4 \
|
|
libcups2-dev \
|
|
libflac-dev \
|
|
libpcap-dev libpulse-dev libsodium23 \
|
|
libavformat-dev \
|
|
libavcodec-dev \
|
|
libavdevice-dev \
|
|
libavutil-dev \
|
|
libavfilter-dev \
|
|
libswscale-dev \
|
|
libswresample-dev \
|
|
gnupg-utils gnupg2 \
|
|
ffmpeg \
|
|
nmap socat \
|
|
dbus \
|
|
jq && \
|
|
echo apt-get install -y libjemalloc-dev libjemalloc2 && \
|
|
apt-get clean && \
|
|
apt-get autoclean
|
|
|
|
RUN set -x && apt-get -y install libjemalloc-dev tree
|
|
|
|
FROM base as builder
|
|
RUN set -x && \
|
|
mkdir /usr/local/src/core && \
|
|
chown -R hass:hass /usr/local/src
|
|
|
|
USER hass
|
|
WORKDIR /usr/local/src/core
|
|
RUN set -x && \
|
|
pip install wheel uv==0.2.27 && \
|
|
/var/lib/hass/.local/bin/uv venv && \
|
|
mkdir homessistant
|
|
|
|
|
|
# Since are just building prod releases, and not PRs and etc, we are fine with
|
|
# doing this in one step instead of first copying core/requirements.txt, building/installing
|
|
# them, and then copyign core/requirements_all.txt as the upstream image does.
|
|
# Doing it this way allows us to use build-requirements.sh and affords us more
|
|
# flexibility, since for us it doesnt matter that we install them all in one layer.
|
|
ARG HASS_VENV_PATH=/usr/local/src/core/.venv
|
|
ENV PATH=${HASS_VENV_PATH}/bin:/var/lib/hass/.local/bin:${PATH}
|
|
#ENV UV_SYSTYEM_PYTHON=true
|
|
|
|
# core/requirements.txt: ~30 lines
|
|
COPY --chown=hass:hass core/requirements.txt /usr/local/src/core/
|
|
COPY --chown=hass:hass core/homeassistant/package_constraints.txt /usr/local/src/core/homeassistant/
|
|
# core/requirements_all.txt: ~2800 lines
|
|
COPY --chown=hass:hass core/requirements_all.txt /usr/local/src/core/
|
|
#COPY docker/bin/muslick.sh /usr/local/bin/
|
|
#COPY docker/bin/build-requirements.sh /usr/local/bin/
|
|
|
|
# Here the upstream image also copies in wheels of frontend and intentions (we dont use intentions)
|
|
# Not sure why they dont let frontend be installed from their wheel archive
|
|
# 'home-assistatn-frontend' is in core/requirements_all.txt (but not in core/requirements.txt)
|
|
# The upstream docker container runs pip with '--no-index --only-binary=:all: --index-url https://wheels.home-assistant.io/musllinux-index'
|
|
# which is built from the home-assistant/wheels repo.
|
|
# Thats something to do in the future, but for now we'll install and compile source packages from PyPI.
|
|
RUN set -x && \
|
|
uv pip install -r requirements.txt && \
|
|
uv pip install -r requirements_all.txt
|
|
|
|
RUN set -x && \
|
|
du -sh /usr/local/src/core/.venv/ && \
|
|
which python python3 pip uv
|
|
|
|
# Upstream image installs homeassitant as editable -e, but
|
|
# that wouldnt work for our purposes
|
|
COPY --chown=hass:hass core/ /usr/local/src/core/
|
|
RUN set -x && \
|
|
uv pip install /usr/local/src/core/ && \
|
|
python3 -m compileall /usr/local/src/core/homeassistant
|
|
|
|
|
|
#RUN set -x && \
|
|
# du -sh /usr/local/src && \
|
|
# du -sh /usr/local/src/.cache/venv/core && \
|
|
# find /usr/local/src -name "*.whl" && \
|
|
# pip cache dir
|
|
|
|
# "use jemalloc" in builds: https://github.com/home-assistant/core/commit/e18a6e376cc6f4b0c818159bd83944e1ddd13f7f
|
|
|
|
#ENV MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000"
|
|
# For musl:
|
|
#ENV LD_PRELOAD="/usr/local/lib/libjemalloc.so.2"
|
|
# For libc:
|
|
#ENV LD_PRELOAD="/usr/lib/${arch}-linux-gnu/libjemalloc.so.2"
|
|
# see: docker/bin/build-requirements.sh
|
|
|
|
FROM base as packager
|
|
RUN set -x && \
|
|
apt-get install -y ruby ruby-dev rubygems && \
|
|
apt-get clean && \
|
|
apt-get autoclean && \
|
|
gem install --no-document fpm
|
|
|
|
|
|
FROM base as final
|
|
|
|
# were did deps.txt go?
|
|
#COPY deb/deps.txt /tmp/deps.txt
|
|
#RUN xargs -a /tmp/deps.txt apt-get -y install && \
|
|
#pcap-utils libflac8
|
|
# Install runtime dependencies listed on: https://www.home-assistant.io/installation/linux#install-home-assistant-core
|
|
RUN set -x && \
|
|
apt-get update && \
|
|
apt-get install -y \
|
|
python3 python3-dev python3-venv python3-pip \
|
|
bluez \
|
|
libffi-dev \
|
|
libssl-dev \
|
|
libjpeg-dev \
|
|
zlib1g-dev \
|
|
autoconf \
|
|
build-essential \
|
|
libopenjp2-7 \
|
|
libtiff6 \
|
|
libturbojpeg0-dev \
|
|
tzdata \
|
|
ffmpeg \
|
|
nmap \
|
|
liblapack3 \
|
|
liblapack-dev \
|
|
libatlas-base-dev && \
|
|
apt-get clean && \
|
|
apt-get autoclean
|
|
USER hass
|
|
|
|
COPY --from=builder --chown=hass:hass /usr/local/src/core/.venv/ /usr/local/src/core/.venv/
|
|
ENV PATH "/usr/local/src/core/.venv/bin:$PATH"
|
|
|
|
ENTRYPOINT ["python3", "-m", "homeassistant", "--config", "/etc/hass"]
|