Skip to content

Commit ee6a66b

Browse files
authored
use same devcontainer as home assistant core (lbbrhzn#1677)
* use same devcontainer as home assistant core * remove old devcontainer.json * Add Dockerfile * update port settings * fix location of schemas * fix location of setup script * add bootstrap script * make bootstrap executable * fix Dockerfile * Update Dockerfile.dev * allow prereleases
1 parent 2c800b1 commit ee6a66b

File tree

7 files changed

+641
-42
lines changed

7 files changed

+641
-42
lines changed

.devcontainer.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "Home Assistant Dev",
3+
"context": "..",
4+
"dockerFile": "../Dockerfile.dev",
5+
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && scripts/setup",
6+
"postStartCommand": "scripts/bootstrap",
7+
"containerEnv": {
8+
"PYTHONASYNCIODEBUG": "1"
9+
},
10+
"features": {
11+
"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {},
12+
"ghcr.io/devcontainers/features/github-cli:1": {}
13+
},
14+
"appPort": [
15+
"9000:9000", // OCPP
16+
"8123:8123", // Home Assistant
17+
"5683:5683/udp" // Shelly integration
18+
],
19+
"runArgs": [
20+
"-e",
21+
"GIT_EDITOR=code --wait",
22+
"--security-opt",
23+
"label=disable"
24+
],
25+
"customizations": {
26+
"vscode": {
27+
"extensions": [
28+
"charliermarsh.ruff",
29+
"ms-python.pylint",
30+
"ms-python.vscode-pylance",
31+
"visualstudioexptteam.vscodeintellicode",
32+
"redhat.vscode-yaml",
33+
"esbenp.prettier-vscode",
34+
"GitHub.vscode-pull-request-github",
35+
"GitHub.copilot"
36+
],
37+
// Please keep this file in sync with settings in home-assistant/.vscode/settings.default.json
38+
"settings": {
39+
"python.experiments.optOutFrom": [
40+
"pythonTestAdapter"
41+
],
42+
"python.defaultInterpreterPath": "/home/vscode/.local/ha-venv/bin/python",
43+
"python.pythonPath": "/home/vscode/.local/ha-venv/bin/python",
44+
"python.terminal.activateEnvInCurrentTerminal": true,
45+
"python.testing.pytestArgs": [
46+
"--no-cov"
47+
],
48+
"pylint.importStrategy": "fromEnvironment",
49+
"editor.formatOnPaste": false,
50+
"editor.formatOnSave": true,
51+
"editor.formatOnType": true,
52+
"files.trimTrailingWhitespace": true,
53+
"terminal.integrated.profiles.linux": {
54+
"zsh": {
55+
"path": "/usr/bin/zsh"
56+
}
57+
},
58+
"terminal.integrated.defaultProfile.linux": "zsh",
59+
"yaml.customTags": [
60+
"!input scalar",
61+
"!secret scalar",
62+
"!include_dir_named scalar",
63+
"!include_dir_list scalar",
64+
"!include_dir_merge_list scalar",
65+
"!include_dir_merge_named scalar"
66+
],
67+
"[python]": {
68+
"editor.defaultFormatter": "charliermarsh.ruff"
69+
},
70+
"json.schemas": [
71+
{
72+
"fileMatch": [
73+
"homeassistant/components/*/manifest.json"
74+
],
75+
"url": "${containerWorkspaceFolder}/scripts/json_schemas/manifest_schema.json"
76+
}
77+
]
78+
}
79+
}
80+
}
81+
}

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Automatically generated by hassfest.
2+
#
3+
# To update, run python3 -m script.hassfest -p docker
4+
ARG BUILD_FROM
5+
FROM ${BUILD_FROM}
6+
7+
# Synchronize with homeassistant/core.py:async_stop
8+
ENV \
9+
S6_SERVICES_GRACETIME=240000 \
10+
UV_SYSTEM_PYTHON=true \
11+
UV_NO_CACHE=true
12+
13+
ARG QEMU_CPU
14+
15+
# Home Assistant S6-Overlay
16+
COPY rootfs /
17+
18+
# Needs to be redefined inside the FROM statement to be set for RUN commands
19+
ARG BUILD_ARCH
20+
# Get go2rtc binary
21+
RUN \
22+
case "${BUILD_ARCH}" in \
23+
"aarch64") go2rtc_suffix='arm64' ;; \
24+
"armhf") go2rtc_suffix='armv6' ;; \
25+
"armv7") go2rtc_suffix='arm' ;; \
26+
*) go2rtc_suffix=${BUILD_ARCH} ;; \
27+
esac \
28+
&& curl -L https://github.com/AlexxIT/go2rtc/releases/download/v1.9.9/go2rtc_linux_${go2rtc_suffix} --output /bin/go2rtc \
29+
&& chmod +x /bin/go2rtc \
30+
# Verify go2rtc can be executed
31+
&& go2rtc --version
32+
33+
# Install uv
34+
RUN pip3 install uv==0.7.1
35+
36+
WORKDIR /usr/src
37+
38+
RUN \
39+
uv pip install \
40+
-r requirements.txt
41+
42+
43+
WORKDIR /config

Dockerfile.dev

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
2+
3+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4+
5+
RUN \
6+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
7+
&& apt-get update \
8+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
9+
# Additional library needed by some tests and accordingly by VScode Tests Discovery
10+
bluez \
11+
ffmpeg \
12+
libudev-dev \
13+
libavformat-dev \
14+
libavcodec-dev \
15+
libavdevice-dev \
16+
libavutil-dev \
17+
libgammu-dev \
18+
libswscale-dev \
19+
libswresample-dev \
20+
libavfilter-dev \
21+
libpcap-dev \
22+
libturbojpeg0 \
23+
libyaml-dev \
24+
libxml2 \
25+
git \
26+
cmake \
27+
autoconf \
28+
&& apt-get clean \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Add go2rtc binary
32+
COPY --from=ghcr.io/alexxit/go2rtc:latest /usr/local/bin/go2rtc /bin/go2rtc
33+
34+
WORKDIR /usr/src
35+
36+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
37+
38+
RUN uv python install 3.13.2
39+
40+
USER vscode
41+
ENV VIRTUAL_ENV="/home/vscode/.local/ha-venv"
42+
RUN uv venv $VIRTUAL_ENV
43+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
44+
45+
WORKDIR /tmp
46+
47+
# Setup hass-release
48+
RUN git clone --depth 1 https://github.com/home-assistant/hass-release ~/hass-release \
49+
&& uv pip install -e ~/hass-release/
50+
51+
# Install Python dependencies from requirements
52+
COPY requirements.txt ./
53+
RUN uv pip install --prerelease=allow -r requirements.txt
54+
55+
WORKDIR /workspaces
56+
57+
# Set the default shell to bash instead of sh
58+
ENV SHELL=/bin/bash

scripts/bootstrap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
# Resolve all dependencies that the application requires to run.
3+
4+
# Stop on errors
5+
set -e
6+
7+
cd "$(dirname "$0")/.."
8+
9+
python3 -m pip install -r requirements.txt

0 commit comments

Comments
 (0)