2021-09-20 09:07:38 +02:00
|
|
|
# Build these with the build.py script
|
|
|
|
# Example:
|
|
|
|
# python3 docker/build.py --tag dev --arch amd64 --build-type docker build
|
|
|
|
|
|
|
|
# One of "docker", "hassio"
|
|
|
|
ARG BASEIMGTYPE=docker
|
|
|
|
|
2023-11-09 09:04:39 +01:00
|
|
|
|
2022-02-16 22:25:04 +01:00
|
|
|
# https://github.com/hassio-addons/addon-debian-base/releases
|
2023-10-18 08:33:19 +02:00
|
|
|
FROM ghcr.io/hassio-addons/debian-base:7.2.0 AS base-hassio
|
|
|
|
# https://hub.docker.com/_/debian?tab=tags&page=1&name=bookworm
|
|
|
|
FROM debian:12.2-slim AS base-docker
|
2021-09-20 09:07:38 +02:00
|
|
|
|
2022-11-17 04:14:10 +01:00
|
|
|
FROM base-${BASEIMGTYPE} AS base
|
2021-09-20 09:07:38 +02:00
|
|
|
|
2023-11-09 09:04:39 +01:00
|
|
|
|
2022-12-15 21:27:59 +01:00
|
|
|
ARG TARGETARCH
|
|
|
|
ARG TARGETVARIANT
|
2023-11-09 09:04:39 +01:00
|
|
|
|
2022-12-15 21:27:59 +01:00
|
|
|
|
2023-10-18 08:33:19 +02:00
|
|
|
# Note that --break-system-packages is used below because
|
|
|
|
# https://peps.python.org/pep-0668/ added a safety check that prevents
|
|
|
|
# installing packages with the same name as a system package. This is
|
|
|
|
# not a problem for us because we are not concerned about overwriting
|
|
|
|
# system packages because we are running in an isolated container.
|
|
|
|
|
2021-09-20 09:07:38 +02:00
|
|
|
RUN \
|
|
|
|
apt-get update \
|
|
|
|
# Use pinned versions so that we get updates with build caching
|
|
|
|
&& apt-get install -y --no-install-recommends \
|
2023-10-18 08:33:19 +02:00
|
|
|
python3-pip=23.0.1+dfsg-1 \
|
|
|
|
python3-setuptools=66.1.1-1 \
|
|
|
|
python3-venv=3.11.2-1+b1 \
|
|
|
|
python3-wheel=0.38.4-2 \
|
|
|
|
iputils-ping=3:20221126-1 \
|
|
|
|
git=1:2.39.2-1.1 \
|
|
|
|
curl=7.88.1-10+deb12u4 \
|
|
|
|
openssh-client=1:9.2p1-2+deb12u1 \
|
|
|
|
python3-cffi=1.15.1-5 \
|
|
|
|
libcairo2=1.16.0-7 \
|
2023-11-23 20:10:33 +01:00
|
|
|
libmagic1=1:5.44-3 \
|
2023-09-14 01:13:55 +02:00
|
|
|
patch=2.7.6-7; \
|
2023-07-20 05:52:41 +02:00
|
|
|
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
|
|
|
apt-get install -y --no-install-recommends \
|
|
|
|
build-essential=12.9 \
|
2023-10-18 08:33:19 +02:00
|
|
|
python3-dev=3.11.2-1+b1 \
|
|
|
|
zlib1g-dev=1:1.2.13.dfsg-1 \
|
|
|
|
libjpeg-dev=1:2.1.5-2 \
|
|
|
|
libfreetype-dev=2.12.1+dfsg-5 \
|
2023-10-30 20:07:25 +01:00
|
|
|
libssl-dev=3.0.11-1~deb12u2 \
|
2023-10-18 08:33:19 +02:00
|
|
|
libffi-dev=3.4.4-1 \
|
2023-11-21 01:19:36 +01:00
|
|
|
libopenjp2-7=2.5.0-2 \
|
2023-12-21 23:55:10 +01:00
|
|
|
libtiff6=4.5.0-6+deb12u1 \
|
2023-10-18 08:33:19 +02:00
|
|
|
cargo=0.66.0+ds1-1 \
|
2023-11-08 23:50:08 +01:00
|
|
|
pkg-config=1.8.1-1 \
|
2023-10-30 20:07:25 +01:00
|
|
|
gcc-arm-linux-gnueabihf=4:12.2.0-3; \
|
2023-07-20 05:52:41 +02:00
|
|
|
fi; \
|
|
|
|
rm -rf \
|
2021-09-20 09:07:38 +02:00
|
|
|
/tmp/* \
|
|
|
|
/var/{cache,log}/* \
|
|
|
|
/var/lib/apt/lists/*
|
|
|
|
|
|
|
|
ENV \
|
|
|
|
# Fix click python3 lang warning https://click.palletsprojects.com/en/7.x/python3/
|
|
|
|
LANG=C.UTF-8 LC_ALL=C.UTF-8 \
|
|
|
|
# Store globally installed pio libs in /piolibs
|
2023-11-09 09:04:39 +01:00
|
|
|
PLATFORMIO_GLOBALLIB_DIR=/piolibs
|
2023-10-18 08:33:19 +02:00
|
|
|
|
2022-12-15 21:27:59 +01:00
|
|
|
# Support legacy binaries on Debian multiarch system. There is no "correct" way
|
|
|
|
# to do this, other than using properly built toolchains...
|
|
|
|
# See: https://unix.stackexchange.com/questions/553743/correct-way-to-add-lib-ld-linux-so-3-in-debian
|
|
|
|
RUN \
|
|
|
|
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
2023-11-17 10:16:03 +01:00
|
|
|
ln -s /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 /lib/ld-linux.so.3; \
|
2022-12-15 21:27:59 +01:00
|
|
|
fi
|
|
|
|
|
2021-09-20 09:07:38 +02:00
|
|
|
RUN \
|
|
|
|
# Ubuntu python3-pip is missing wheel
|
2023-11-09 09:04:39 +01:00
|
|
|
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
|
|
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
|
|
|
fi; \
|
|
|
|
pip3 install \
|
|
|
|
--break-system-packages --no-cache-dir \
|
|
|
|
platformio==6.1.11 \
|
2021-09-20 09:07:38 +02:00
|
|
|
# Change some platformio settings
|
|
|
|
&& platformio settings set enable_telemetry No \
|
|
|
|
&& platformio settings set check_platformio_interval 1000000 \
|
|
|
|
&& mkdir -p /piolibs
|
2019-02-13 16:54:02 +01:00
|
|
|
|
2021-09-20 10:31:48 +02:00
|
|
|
|
2020-07-15 15:03:15 +02:00
|
|
|
# First install requirements to leverage caching when requirements don't change
|
2023-10-18 08:33:19 +02:00
|
|
|
# tmpfs is for https://github.com/rust-lang/cargo/issues/8719
|
|
|
|
|
2023-04-27 02:26:06 +02:00
|
|
|
COPY requirements.txt requirements_optional.txt script/platformio_install_deps.py platformio.ini /
|
2023-11-09 09:04:39 +01:00
|
|
|
RUN --mount=type=tmpfs,target=/root/.cargo if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
|
|
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
|
|
|
fi; \
|
|
|
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse CARGO_HOME=/root/.cargo \
|
|
|
|
pip3 install \
|
|
|
|
--break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \
|
2023-05-01 05:57:57 +02:00
|
|
|
&& /platformio_install_deps.py /platformio.ini --libraries
|
2020-07-15 15:03:15 +02:00
|
|
|
|
2022-02-16 22:25:04 +01:00
|
|
|
|
|
|
|
# ======================= docker-type image =======================
|
|
|
|
FROM base AS docker
|
|
|
|
|
2021-09-20 09:07:38 +02:00
|
|
|
# Copy esphome and install
|
|
|
|
COPY . /esphome
|
2023-11-09 09:04:39 +01:00
|
|
|
RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
|
|
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
|
|
|
fi; \
|
|
|
|
pip3 install \
|
|
|
|
--break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
|
2019-02-13 16:54:02 +01:00
|
|
|
|
2020-07-15 15:03:15 +02:00
|
|
|
# Settings for dashboard
|
|
|
|
ENV USERNAME="" PASSWORD=""
|
2019-10-13 13:52:02 +02:00
|
|
|
|
2020-12-30 10:58:09 +01:00
|
|
|
# Expose the dashboard to Docker
|
|
|
|
EXPOSE 6052
|
|
|
|
|
2023-11-02 19:19:43 +01:00
|
|
|
# Run healthcheck (heartbeat)
|
|
|
|
HEALTHCHECK --interval=30s --timeout=30s \
|
|
|
|
CMD curl --fail http://localhost:6052/version -A "HealthCheck" || exit 1
|
|
|
|
|
2021-09-20 09:07:38 +02:00
|
|
|
COPY docker/docker_entrypoint.sh /entrypoint.sh
|
2021-01-27 07:16:59 +01:00
|
|
|
|
2020-07-15 15:03:15 +02:00
|
|
|
# The directory the user should mount their configuration files to
|
2021-09-20 09:07:38 +02:00
|
|
|
VOLUME /config
|
2019-02-13 16:54:02 +01:00
|
|
|
WORKDIR /config
|
2021-09-20 09:07:38 +02:00
|
|
|
# Set entrypoint to esphome (via a script) so that the user doesn't have to type 'esphome'
|
2020-07-15 15:03:15 +02:00
|
|
|
# in every docker command twice
|
2021-09-20 09:07:38 +02:00
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
2020-07-15 15:03:15 +02:00
|
|
|
# When no arguments given, start the dashboard in the workdir
|
2021-06-08 01:14:12 +02:00
|
|
|
CMD ["dashboard", "/config"]
|
2021-09-20 09:07:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ======================= hassio-type image =======================
|
|
|
|
FROM base AS hassio
|
|
|
|
|
|
|
|
RUN \
|
|
|
|
apt-get update \
|
|
|
|
# Use pinned versions so that we get updates with build caching
|
|
|
|
&& apt-get install -y --no-install-recommends \
|
2023-10-18 08:33:19 +02:00
|
|
|
nginx-light=1.22.1-9 \
|
2021-09-20 09:07:38 +02:00
|
|
|
&& rm -rf \
|
|
|
|
/tmp/* \
|
|
|
|
/var/{cache,log}/* \
|
|
|
|
/var/lib/apt/lists/*
|
|
|
|
|
|
|
|
ARG BUILD_VERSION=dev
|
|
|
|
|
|
|
|
# Copy root filesystem
|
2022-02-09 11:46:20 +01:00
|
|
|
COPY docker/ha-addon-rootfs/ /
|
2021-09-20 09:07:38 +02:00
|
|
|
|
|
|
|
# Copy esphome and install
|
|
|
|
COPY . /esphome
|
2023-11-09 09:04:39 +01:00
|
|
|
RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
|
|
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
|
|
|
fi; \
|
|
|
|
pip3 install \
|
|
|
|
--break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
|
2021-09-20 09:07:38 +02:00
|
|
|
|
|
|
|
# Labels
|
|
|
|
LABEL \
|
|
|
|
io.hass.name="ESPHome" \
|
|
|
|
io.hass.description="Manage and program ESP8266/ESP32 microcontrollers through YAML configuration files" \
|
|
|
|
io.hass.type="addon" \
|
|
|
|
io.hass.version="${BUILD_VERSION}"
|
|
|
|
# io.hass.arch is inherited from addon-debian-base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ======================= lint-type image =======================
|
|
|
|
FROM base AS lint
|
|
|
|
|
|
|
|
ENV \
|
|
|
|
PLATFORMIO_CORE_DIR=/esphome/.temp/platformio
|
|
|
|
|
|
|
|
RUN \
|
|
|
|
apt-get update \
|
|
|
|
# Use pinned versions so that we get updates with build caching
|
|
|
|
&& apt-get install -y --no-install-recommends \
|
2023-10-18 08:33:19 +02:00
|
|
|
clang-format-13=1:13.0.1-11+b2 \
|
|
|
|
clang-tidy-14=1:14.0.6-12 \
|
2021-09-20 09:07:38 +02:00
|
|
|
patch=2.7.6-7 \
|
2023-10-18 08:33:19 +02:00
|
|
|
software-properties-common=0.99.30-4 \
|
|
|
|
nano=7.2-1 \
|
2021-09-20 09:07:38 +02:00
|
|
|
build-essential=12.9 \
|
2023-10-18 08:33:19 +02:00
|
|
|
python3-dev=3.11.2-1+b1 \
|
2021-09-20 09:07:38 +02:00
|
|
|
&& rm -rf \
|
|
|
|
/tmp/* \
|
|
|
|
/var/{cache,log}/* \
|
|
|
|
/var/lib/apt/lists/*
|
|
|
|
|
2022-02-16 22:25:04 +01:00
|
|
|
COPY requirements_test.txt /
|
2023-11-09 09:04:39 +01:00
|
|
|
RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
|
|
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
|
|
|
fi; \
|
|
|
|
pip3 install \
|
|
|
|
--break-system-packages --no-cache-dir -r /requirements_test.txt
|
2021-09-20 10:31:48 +02:00
|
|
|
|
2021-09-20 09:07:38 +02:00
|
|
|
VOLUME ["/esphome"]
|
|
|
|
WORKDIR /esphome
|