Thanks, you can help me please, config frondEnd enviroment ?
Unfortunately, I haven’t done any frontend development against the dev container. Hopefully someone else can contribute additional inputs.
On Windows, use:
"mounts": [
// custom component
"source=${localEnv:USERPROFILE}\\OneDrive\\Documents\\docs\\dev\\philips-airpurifier-coap\\custom_components\\philips_airpurifier_coap,target=${containerWorkspaceFolder}/config/custom_components/philips_airpurifier_coap,type=bind",
],
to mount a custom component, sitting on your windows partition on, e.g., OneDrive in a sub-folder.
Thanks for this guide! It saved me so much nerves while trying to debug something in HA! Seems debugging only works via debugpy. Without it the default debug config doesn’t work for me.
Glad to hear it worked for you! Strangely, I tried setting up the devcontainer for some debugging a few weeks ago, and could not the the debugger to stop on a breakpoint. Did you run into any issues like that?
Thanks for the guide, I feel that I’m missing something.
I am not certain what I actually have to do when updating to the latest tip of the dev branch to get my container working. I feel that every time there’s a new HA version, my devcontainer breaks and I waste a lot of time trying to get it to work again. Here’s what I do:
git checkout dev
git fetch upstream dev
git rebase upstream/dev
click 'Dev Container' in bottom left > rebuild container
script/setup
Then ctrl-shift-p Tasks:Run-task>Run Home Assistant Core
HA starts running, but I get lots of errors. e.g.
2022-09-13 20:23:36.560 ERROR (MainThread) [homeassistant.setup] Setup failed for analytics: Unable to import component: No module named 'sqlalchemy'
2022-09-13 20:23:39.021 INFO (MainThread) [homeassistant.setup] Setting up image
2022-09-13 20:23:39.022 INFO (MainThread) [homeassistant.setup] Setup of domain image took 0.0 seconds
2022-09-13 20:23:39.023 INFO (MainThread) [homeassistant.setup] Setting up person
2022-09-13 20:23:39.025 INFO (MainThread) [homeassistant.setup] Setup of domain person took 0.0 seconds
2022-09-13 20:23:39.026 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of onboarding. Setup failed for dependencies: analytics
2022-09-13 20:23:39.026 ERROR (MainThread) [homeassistant.setup] Setup failed for onboarding: (DependencyError(...), 'Could not setup dependencies: analytics')
2022-09-13 20:23:39.026 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of frontend. Setup failed for dependencies: onboarding
2022-09-13 20:23:39.027 ERROR (MainThread) [homeassistant.setup] Setup failed for frontend: (DependencyError(...), 'Could not setup dependencies: onboarding')
2022-09-13 20:23:39.027 INFO (MainThread) [homeassistant.bootstrap] Setting up recorder: {'recorder'}
2022-09-13 20:23:39.057 INFO (SyncWorker_0) [homeassistant.util.package] Attempting install of sqlalchemy==1.4.40
2022-09-13 20:23:42.550 INFO (SyncWorker_0) [homeassistant.util.package] Attempting install of fnvhash==0.1.0
2022-09-13 20:23:44.677 INFO (MainThread) [homeassistant.setup] Setting up recorder
2022-09-13 20:23:44.680 WARNING (Recorder) [homeassistant.components.recorder.util] The system could not validate that the sqlite3 database at //workspaces/core/config/home-assistant_v2.db was shutdown cleanly
2022-09-13 20:23:44.683 ERROR (Recorder) [homeassistant.components.recorder.util] Version 3.27.2 of SQLite is not supported; minimum supported version is 3.31.0. Starting with Home Assistant 2022.6 this prevents the recorder from starting. Please upgrade your database software
2022-09-13 20:23:44.686 INFO (MainThread) [homeassistant.setup] Setup of domain recorder took 0.0 seconds
2022-09-13 20:23:44.686 ERROR (MainThread) [homeassistant.setup] Setup failed for recorder: Integration failed to initialize.
Ok so something’s clearly wrong with some database software. But didn’t I just checkout the latest code and rebuild the dev container? So doesn’t that give me everything at the latest version? So why is it asking me to ‘Upgrade my database software’? What database software? I don’t even know how I’d check what version I have. SQLite doesn’t seem to be installed on the host machine or in the container.
Any ideas? Should what I’m doing work or am I missing a step?
Nope. No issues since I added debugpy in HA config and launching the debug config, which does the attach to a running HA instance. I am able to tldebug both custom components and HA internal code. Th breakpoints stop without any issues.
I’ve setup the dev container already a couple of time throughout the years, but when I did this on the weekend I encountered errors while launching the ‘Run’ task for the first time.
HA missed a lot of core integrations and launched in safe mode.i think I got the same errors as you.
I didn’t know what the problem was. I simply closed VS Code, reopened it again so the dev container started again and since then - no issues. So there’s something wrong with the recent dev container build in my opinion. I never had such issues before.
Oh one more thing: I do not use the git commands to rebuild my container since I didn’t know about this way I follow “my way” which is rebaselining my HA fork in GitHub.com, then syncing my Windows GitHub desktop with my GitHub account, and then I click “Open in VS Code”, so when it opens it asks if it should open in dev container. When I confirm - VS Code starts rebuilding the container automatically.
I guess it’s practically the same thing as using commands.
Ok, would be interested to know what I’m doing wrong at some point. Or if not for it to be fixed.
The git commands don’t rebuild the dev container, they just update the source files on the drive.
Then you could restart vscode to get it to prompt to rebuild, or just trigger the rebuild directly (I think these have the same effect).
If it’s still not working for you then scrap it and start over. Normally it handles all the needed things automatically. Better to wait and let it do its thing than to spend hours on googling. The whole container build takes not more than 10 minutes for me
Adding my 3 cents on this topic for people seeking a solution to debugging issues in the future.
It turns out that debugging within devcontainer is enabled by default, out of the box. Normally there’s no need to enable the debugpy
integration to debug the local devcontainer, developer instance.
However it didn’t work for me and since there was nothing about debugging in HA developer docs - I thought it’s not supported and some extra steps need to be taken - like the ones above.
When using the default devcontainer debugger I was getting this error: “Timed out waiting for launcher to connect.” (leaving the text for the search engines)
I goggled the problem, but didn’t find any solution that worked, but one thread pointed me to something that allowed my to solve/workaround this.
The trick that worked for me and allowed to use the “default” debugging way (that probably works for most of the people) is to edit and add this to your launch.json
file:
"console": "internalConsole"
So the entire config entry looks like this:
The effect is almost the same as enabling the debugpy
integration in HA configuration, but has one advantage: you may debug even line 1 of HA startup code + it launches Home Assistant for you, no need to run the ‘Run/Preview’ task first. The debugpy
way only allows debugging after Home Assistant was launched and after it loaded the debugpy
integration.
After applying this line in launch.json
the Home Assistant log will not be output in a new Terminal session, but instead VS Code Debug console window will be used.
The entire issue is probably related to some bugs in VS Code, but this solution works for me for real. I disabled it and debugging stopped working immediately. When I put it back it - it immediately started working again, so this really solves this.
Hope it helps someone in the future, who ran into the same issue as me or the OP.
I’ve tried scrapping it and starting over. That’s the problem, it doesn’t fix it. In my case, not talking about debug, just running HA. My current guess is that one of the following is true:
- Something is broken in the master dev container and everyone is having to fix it
- Something is wrong with my working copy which is causing the dev container to be wrong, or perhaps some caching I’m unaware of
- Something is wrong with VSCode in the way that it creates dev containers
- Something is wrong with my Host OS (Ubuntu) install, which is influencing the dev container
- My understanding of dev containers is flawed and they are not really giving the level of containerisation that I thought they were.
For me a key point is this error:
Version 3.27.2 of SQLite is not supported; minimum supported version is 3.31.0. Starting with Home Assistant 2022.6 this prevents the recorder from starting. Please upgrade your database software
My question: Where did Version 3.27.2 of SQLite come from? I didn’t install it. So if I get this appearing straight after deploying a fresh dev container as defined on the dev branch, then doesn’t it mean the container installed the wrong version?
I’m going to investigate more, just sharing where I got to.
I think I’ve got to the bottom of it. The devcontainer is using python 3.9, and bundled with python 3.9 is sqlite3 version 3.27.2.
Demonstration: rebuilt docker container.
root ➜ /workspaces/core (dev ✗) $ python3
Python 3.9.4 (default, Apr 10 2021, 15:31:19)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
Then modified Docker.dev first line, replacing
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.9
with
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.10
Rebuilt container again, now I get this:
root ➜ /workspaces/core (dev ✗) $ python3
Python 3.10.6 (main, Aug 23 2022, 08:25:41) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.34.1'
But here’s the problem, in homeassistant.components.recorder.util.py
we have MIN_VERSION_SQLITE = ... "3.31.0"
So my conclusion is that the Docker.dev file is using a python version that is too old for the for the MIN_VERSION_SQLITE
defined in the recorder component.
So it’s probably not just me seeing this error. It might be everyone running python 3.9.
Actually it looks like the microsoft image for python 3.9 might be what’s wrong.
According to the python 3.9.0 tag, the first sqlite3 version bundled in python 3.9.0 was 3.32.3 (which should be fine).
I have raised a ticket.
I’m trying to return to frontend development after some time, I’ve cloned the frontend repo, opened it in VS Code, then I was asked to reopen it in dev container, after a second I’ve tried following the steps (GitHub - home-assistant/frontend: Frontend for Home Assistant), but the first one gives me an error:
vscode ➜ /workspaces/frontend (fix-selector ✗) $ script/setup
➤ YN0000: ┌ Resolution step
➤ YN0002: │ @formatjs/intl-locale@npm:2.4.40 doesn't provide @types/node (p4040e), requested by @formatjs/intl-getcanonicallocales
➤ YN0002: │ @web/dev-server@npm:0.0.24 doesn't provide rollup (p8cfb8), requested by @rollup/plugin-node-resolve
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide @egjs/hammerjs (pc1ec5), requested by vis-network
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide @types/node (p7c56b), requested by @formatjs/intl-getcanonicallocales
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide component-emitter (pe6728), requested by vis-network
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide keycharm (p71c12), requested by vis-network
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide timsort (pc0292), requested by vis-network
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide uuid (p3a84b), requested by vis-data
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide uuid (p9d383), requested by vis-network
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide vis-util (p2581d), requested by vis-data
➤ YN0002: │ home-assistant-frontend@workspace:. doesn't provide vis-util (p014f8), requested by vis-network
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed in 0s 834ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 15s 792ms
➤ YN0000: ┌ Link step
➤ YN0001: │ Error: EPERM: operation not permitted, chmod '/workspaces/frontend/node_modules/@babel/core/node_modules/json5/lib/cli.js'
➤ YN0000: └ Completed in 7m 30s
➤ YN0000: Failed with errors in 7m 47s
vscode ➜ /workspaces/frontend (fix-selector ✗) $
especially this one:
Error: EPERM: operation not permitted, chmod '/workspaces/frontend/node_modules/@babel/core/node_modules/json5/lib/cli.js'
when I try to develop gallery and run cd gallery && script/develop_gallery
I get this errors:
./node_modules/.bin/gulp: 1: XSym: not found
./node_modules/.bin/gulp: 2: 0023: not found
./node_modules/.bin/gulp: 3: 687149e66e3e6360895d0ac20c73b31a: not found
./node_modules/.bin/gulp: 4: ../gulp-cli/bin/gulp.js: not found
I’m using Windows 10, VS Code 1.72.0 and Docker 4.7.0
Any ideas what might be wrong?
this is a great post, thanks a lot
I have updated the original post, as many steps (especially for debugging) were extremely out of date.
Hello,
when I debug my custom componentvin dev container if I made a mistake, after fixing it, I have to close VScode and reopen it for my fix to take effect.
Is there a way to make it faster
Thank’s
Great post, clear and concise
I created a mount folder for one of my custom components adding something like:
// Custom component
"source=${localEnv:HOME}/dev/ha-netro-watering/custom_components/netro_watering,target=${containerWorkspaceFolder}/config/custom_components/netro_watering,type=bind"
It works as expected - in terms of folder sync - but I cannot ignore it with github in despite the following configuration in .gitignore file
config
Did i miss something ?