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 \
2024-11-10 21:44:02 +01:00
iputils-ping= 3:20221126-1+deb12u1 \
2024-09-16 02:32:39 +02:00
git = 1:2.39.5-0+deb12u1 \
2024-11-10 21:44:02 +01:00
curl = 7.88.1-10+deb12u8 \
2024-09-02 00:36:18 +02:00
openssh-client= 1:9.2p1-2+deb12u3 \
2023-10-18 08:33:19 +02:00
python3-cffi= 1.15.1-5 \
libcairo2 = 1.16.0-7 \
2023-11-23 20:10:33 +01:00
libmagic1 = 1:5.44-3 \
2024-07-01 01:51:51 +02:00
patch = 2.7.6-7 \
&& 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 \
2024-06-12 00:38:26 +02:00
# Keep platformio version in sync with requirements.txt
2024-10-16 06:26:48 +02:00
platformio = = 6.1.16 \
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
2024-09-10 00:35:39 +02:00
COPY requirements.txt requirements_optional.txt /
2024-10-31 04:36:23 +01:00
RUN --mount= type = tmpfs,target= /root/.cargo <<END-OF-RUN
# Fail on any non-zero status
set -e
if [ " $TARGETARCH $TARGETVARIANT " = "armv7" ]
then
curl -L https://www.piwheels.org/cp311/cryptography-43.0.0-cp37-abi3-linux_armv7l.whl -o /tmp/cryptography-43.0.0-cp37-abi3-linux_armv7l.whl
pip3 install --break-system-packages --no-cache-dir /tmp/cryptography-43.0.0-cp37-abi3-linux_armv7l.whl
rm /tmp/cryptography-43.0.0-cp37-abi3-linux_armv7l.whl
export PIP_EXTRA_INDEX_URL = "https://www.piwheels.org/simple" ;
fi
# install build tools in case wheels are not available
BUILD_DEPS = "
build-essential= 12.9
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+deb12u3
2024-11-10 21:44:02 +01:00
libssl-dev= 3.0.15-1~deb12u1
2024-10-31 04:36:23 +01:00
libffi-dev= 3.4.4-1
cargo = 0.66.0+ds1-1
pkg-config= 1.8.1-1
"
2024-11-24 21:25:51 +01:00
LIB_DEPS = "
libtiff6 = 4.5.0-6+deb12u1
libopenjp2-7= 2.5.0-2
"
2024-10-31 04:36:23 +01:00
if [ " $TARGETARCH $TARGETVARIANT " = "arm64" ] || [ " $TARGETARCH $TARGETVARIANT " = "armv7" ]
then
apt-get update
2024-11-24 21:25:51 +01:00
apt-get install -y --no-install-recommends $BUILD_DEPS $LIB_DEPS
2024-10-31 04:36:23 +01:00
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
if [ " $TARGETARCH $TARGETVARIANT " = "arm64" ] || [ " $TARGETARCH $TARGETVARIANT " = "armv7" ]
then
apt-get remove -y --purge --auto-remove $BUILD_DEPS
rm -rf /tmp/* /var/{ cache,log} /* /var/lib/apt/lists/*
fi
END-OF-RUN
2024-09-10 00:35:39 +02:00
COPY script/platformio_install_deps.py platformio.ini /
RUN /platformio_install_deps.py /platformio.ini --libraries
2020-07-15 15:03:15 +02:00
2024-06-04 03:34:47 +02:00
# Avoid unsafe git error when container user and file config volume permissions don't match
2024-06-07 21:36:07 +02:00
RUN git config --system --add safe.directory '*'
2024-06-04 03:34:47 +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 \
2024-05-16 03:19:37 +02:00
--break-system-packages --no-cache-dir -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
2024-12-06 02:11:11 +01:00
ARG BUILD_VERSION = dev
# Labels
LABEL \
org.opencontainers.image.authors= "The ESPHome Authors" \
org.opencontainers.image.title= "ESPHome" \
2024-12-06 03:24:20 +01:00
org.opencontainers.image.description= "ESPHome is a system to configure your microcontrollers by simple yet powerful configuration files and control them remotely through Home Automation systems" \
2024-12-06 02:11:11 +01:00
org.opencontainers.image.url= "https://esphome.io/" \
org.opencontainers.image.documentation= "https://esphome.io/" \
org.opencontainers.image.source= "https://github.com/esphome/esphome" \
org.opencontainers.image.licenses= "ESPHome" \
org.opencontainers.image.version= ${ BUILD_VERSION }
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 \
2024-05-16 03:19:37 +02:00
--break-system-packages --no-cache-dir -e /esphome
2021-09-20 09:07:38 +02:00
# Labels
LABEL \
io.hass.name= "ESPHome" \
2024-12-06 03:24:20 +01:00
io.hass.description= "ESPHome is a system to configure your microcontrollers by simple yet powerful configuration files and control them remotely through Home Automation systems" \
2021-09-20 09:07:38 +02:00
io.hass.type= "addon" \
2024-12-06 02:11:11 +01:00
io.hass.version= " ${ BUILD_VERSION } "
2021-09-20 09:07:38 +02:00
# io.hass.arch is inherited from addon-debian-base
# ======================= lint-type image =======================
FROM base AS lint
ENV \
PLATFORMIO_CORE_DIR = /esphome/.temp/platformio
RUN \
2024-12-02 23:29:45 +01:00
curl -L https://apt.llvm.org/llvm-snapshot.gpg.key -o /etc/apt/trusted.gpg.d/apt.llvm.org.asc \
&& echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-18 main" > /etc/apt/sources.list.d/llvm.sources.list \
&& apt-get update \
2021-09-20 09:07:38 +02:00
# 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 \
2021-09-20 09:07:38 +02:00
patch = 2.7.6-7 \
2024-06-30 22:54:04 +02:00
software-properties-common= 0.99.30-4.1~deb12u1 \
nano = 7.2-1+deb12u1 \
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 \
2024-12-04 00:26:27 +01:00
&& if [ " $TARGETARCH $TARGETVARIANT " != "armv7" ] ; then \
# move this up after armv7 is retired
apt-get install -y --no-install-recommends clang-tidy-18= 1:18.1.8~++20240731024826+3b5b5c1ec4a3-1~exp1~20240731144843.145 ; \
fi ; \
rm -rf \
2021-09-20 09:07:38 +02:00
/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