Skip to content

Instantly share code, notes, and snippets.

@ludeeus
Last active October 24, 2023 00:15
Show Gist options
  • Save ludeeus/5b35e0b0e7b90622cb46fa601ed87660 to your computer and use it in GitHub Desktop.
Save ludeeus/5b35e0b0e7b90622cb46fa601ed87660 to your computer and use it in GitHub Desktop.
Devcontainer for Home Assistant Frontend & Core

Yeah yeah yeah I know.... but it works...

Usage:

  1. Create a new directory on your computer
  2. In that directory create a directory called '.devcontainer'
  3. Place both the initand the devcontainer.json files from this gist in that directory
  4. Open VS Code in the directory you created and enjoy
  5. Inital starup will take some time since it clones both the repositories and install the requirements to run them.

_If you are using Windows, the init command will fail if you do not set the lineendings of it to LF

The structure should be like this:

your_dir
  .devcontainer
    devcontainer.json
    init
{
"name": "Home Assistant Core & Frontend Development",
"image": "ludeeus/container:monster",
"context": "..",
"postCreateCommand": "bash .devcontainer/init",
"appPort": "8124:8123",
"extensions": [
"github.vscode-pull-request-github",
"tabnine.tabnine-vscode",
"dbaeumer.vscode-eslint",
"ms-vscode.vscode-typescript-tslint-plugin",
"esbenp.prettier-vscode",
"bierner.lit-html",
"runem.lit-plugin",
"ms-python.vscode-pylance"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 2,
"terminal.integrated.shell.linux": "/bin/bash",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
}
}
#!/bin/bash
# Helper init script to be used in a devcontainer for developing agains the HA frontend
# Set workspace
WORKSPACE=$(ls -d /workspaces/* |head -n 1)
# Create the config dir if needed
mkdir -p "${WORKSPACE}/config"
# Create configuration.yaml if needed
if [ ! -f "${WORKSPACE}/config/configuration.yaml" ]; then
tee -a "${WORKSPACE}/config/configuration.yaml" > /dev/null <<EOT
default_config:
demo:
frontend:
development_repo: ${WORKSPACE}/frontend/
# hassio:
# development_repo: ${WORKSPACE}/frontend/
EOT
fi
# Create aliases
tee -a ~/.bashrc > /dev/null <<EOT
alias hass="hass -c '${WORKSPACE}/config'"
alias develop="cd '${WORKSPACE}/frontend' && script/develop"
alias develop-hassio="cd '${WORKSPACE}/frontend/hassio' && script/develop"
echo "Use the command 'hass' to start HA core"
echo "Use the command 'develop' to start the HA frontend develop script"
echo "Use the command 'develop-hassio' to start the HA frontend/hassio develop script"
echo
EOT
# Add missing packages
apk add py3-virtualenv python3-dev
python3 -m pip install colorlog black
# Clone the frontend repo
git clone https://github.com/home-assistant/frontend.git
# Clone the core repo
git clone https://github.com/home-assistant/core.git
# Install frontend dependencies
cd "${WORKSPACE}/frontend"
script/bootstrap
# Install Home Assistant Core
cd "${WORKSPACE}/core"
python3 -m pip install -r requirements.txt
python3 setup.py develop
# Load the changed .bashrc file
source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment