From bd7c2a680ca79bf6294aa907f3755bc8854edcb2 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 22 May 2025 13:24:34 +1200 Subject: [PATCH] Updates for development environment (#8801) --- .devcontainer/Dockerfile | 37 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 11 +++++----- script/devcontainer-post-create | 3 --- script/run-in-env.py | 6 +----- script/setup | 2 +- script/setup.bat | 2 -- 6 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..51e2232d24 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,37 @@ +ARG BUILD_BASE_VERSION=2025.04.0 + + +FROM ghcr.io/esphome/docker-base:debian-${BUILD_BASE_VERSION} AS base + +RUN git config --system --add safe.directory "*" + +RUN apt update \ + && apt install -y \ + protobuf-compiler + +RUN pip install uv + +RUN useradd esphome -m + +USER esphome +ENV VIRTUAL_ENV=/home/esphome/.local/esphome-venv +RUN uv venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" +# Override this set to true in the docker-base image +ENV UV_SYSTEM_PYTHON=false + +WORKDIR /tmp + +COPY requirements.txt ./ +RUN uv pip install -r requirements.txt +COPY requirements_dev.txt requirements_test.txt ./ +RUN uv pip install -r requirements_dev.txt -r requirements_test.txt + +RUN \ + platformio settings set enable_telemetry No \ + && platformio settings set check_platformio_interval 1000000 + +COPY script/platformio_install_deps.py platformio.ini ./ +RUN ./platformio_install_deps.py platformio.ini --libraries --platforms --tools + +WORKDIR /workspaces diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 86f35cc47b..5a7a02a266 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,18 +1,17 @@ { "name": "ESPHome Dev", - "image": "ghcr.io/esphome/esphome-lint:dev", + "context": "..", + "dockerFile": "Dockerfile", "postCreateCommand": [ "script/devcontainer-post-create" ], - "containerEnv": { - "DEVCONTAINER": "1", - "PIP_BREAK_SYSTEM_PACKAGES": "1", - "PIP_ROOT_USER_ACTION": "ignore" + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {} }, "runArgs": [ "--privileged", "-e", - "ESPHOME_DASHBOARD_USE_PING=1" + "GIT_EDITOR=code --wait" // uncomment and edit the path in order to pass though local USB serial to the conatiner // , "--device=/dev/ttyACM0" ], diff --git a/script/devcontainer-post-create b/script/devcontainer-post-create index 2d376786ac..f4835ba6aa 100755 --- a/script/devcontainer-post-create +++ b/script/devcontainer-post-create @@ -3,9 +3,6 @@ set -e # set -x -apt update -apt-get install avahi-utils -y - mkdir -p config script/setup diff --git a/script/run-in-env.py b/script/run-in-env.py index b03f5f19d3..d9bd01a62f 100644 --- a/script/run-in-env.py +++ b/script/run-in-env.py @@ -7,11 +7,7 @@ import sys def find_and_activate_virtualenv(): - if ( - ("VIRTUAL_ENV" in os.environ) - or os.environ.get("DEVCONTAINER") - or os.environ.get("ESPHOME_NO_VENV") - ): + if "VIRTUAL_ENV" in os.environ: return try: diff --git a/script/setup b/script/setup index acc2ec58b4..b17d3235a7 100755 --- a/script/setup +++ b/script/setup @@ -4,7 +4,7 @@ set -e cd "$(dirname "$0")/.." -if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ] && [ ! "$ESPHOME_NO_VENV" ]; then +if [ ! -n "$VIRTUAL_ENV" ]; then if [ -x "$(command -v uv)" ]; then uv venv venv else diff --git a/script/setup.bat b/script/setup.bat index ea2591bb71..f89d5aea1a 100644 --- a/script/setup.bat +++ b/script/setup.bat @@ -1,8 +1,6 @@ @echo off -if defined DEVCONTAINER goto :install if defined VIRTUAL_ENV goto :install -if defined ESPHOME_NO_VENV goto :install echo Starting the Virtual Environment python -m venv venv