mirror of
https://github.com/mtan93/homeassistant-addons.git
synced 2026-03-08 05:21:51 +00:00
Another try w/ dev containers
This commit is contained in:
@@ -1,34 +0,0 @@
|
|||||||
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
|
|
||||||
|
|
||||||
WORKDIR /workspaces
|
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
||||||
|
|
||||||
# Set Docker daemon config
|
|
||||||
RUN \
|
|
||||||
mkdir -p /etc/docker \
|
|
||||||
&& echo '{"storage-driver": "vfs"}' > /etc/docker/daemon.json
|
|
||||||
|
|
||||||
# Installa aditional tools
|
|
||||||
RUN \
|
|
||||||
apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends \
|
|
||||||
dbus \
|
|
||||||
network-manager \
|
|
||||||
libpulse0 \
|
|
||||||
xz-utils
|
|
||||||
|
|
||||||
# Install docker
|
|
||||||
RUN curl -fsSL https://get.docker.com | sh -
|
|
||||||
|
|
||||||
# Install shellcheck
|
|
||||||
RUN \
|
|
||||||
curl -fLs \
|
|
||||||
"https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" \
|
|
||||||
| tar -xJ \
|
|
||||||
\
|
|
||||||
&& mv -f "./shellcheck-stable/shellcheck" "/usr/bin/shellcheck" \
|
|
||||||
&& rm -rf "./shellcheck-stable"
|
|
||||||
|
|
||||||
# Generate a machine-id for this container
|
|
||||||
RUN rm /etc/machine-id && dbus-uuidgen --ensure=/etc/machine-id
|
|
||||||
@@ -1,16 +1,25 @@
|
|||||||
// Based on https://github.com/issacg/hassio-addon-devcontainer
|
// Based on https://github.com/issacg/hassio-addon-devcontainer
|
||||||
{
|
{
|
||||||
"name": "Home Assistant Add-Ons",
|
"name": "Example devcontainer for add-on repositories",
|
||||||
"context": "..",
|
"image": "ghcr.io/home-assistant/devcontainer:addons",
|
||||||
"dockerFile": "Dockerfile",
|
|
||||||
"appPort": ["7123:8123", "7357:4357"],
|
"appPort": ["7123:8123", "7357:4357"],
|
||||||
"postStartCommand": "service docker start",
|
"postStartCommand": "bash devcontainer_bootstrap",
|
||||||
"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
|
"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
|
||||||
"extensions": [
|
"containerEnv": {
|
||||||
"timonwong.shellcheck",
|
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}"
|
||||||
"esbenp.prettier-vscode"
|
},
|
||||||
],
|
"extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"],
|
||||||
|
"mounts": [ "type=volume,target=/var/lib/docker" ],
|
||||||
"settings": {
|
"settings": {
|
||||||
"terminal.integrated.shell.linux": "/bin/bash"
|
"terminal.integrated.profiles.linux": {
|
||||||
|
"zsh": {
|
||||||
|
"path": "/usr/bin/zsh"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"terminal.integrated.defaultProfile.linux": "zsh",
|
||||||
|
"editor.formatOnPaste": false,
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.formatOnType": true,
|
||||||
|
"files.trimTrailingWhitespace": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -eE
|
|
||||||
|
|
||||||
DOCKER_TIMEOUT=30
|
|
||||||
DOCKER_PID=0
|
|
||||||
|
|
||||||
SUPERVISOR_VERSON="$(curl -s https://version.home-assistant.io/dev.json | jq -e -r '.supervisor')"
|
|
||||||
|
|
||||||
|
|
||||||
function start_docker() {
|
|
||||||
local starttime
|
|
||||||
local endtime
|
|
||||||
|
|
||||||
echo "Starting docker."
|
|
||||||
dockerd 2> /dev/null &
|
|
||||||
DOCKER_PID=$!
|
|
||||||
|
|
||||||
echo "Waiting for docker to initialize..."
|
|
||||||
starttime="$(date +%s)"
|
|
||||||
endtime="$(date +%s)"
|
|
||||||
until docker info >/dev/null 2>&1; do
|
|
||||||
if [ $((endtime - starttime)) -le $DOCKER_TIMEOUT ]; then
|
|
||||||
sleep 1
|
|
||||||
endtime=$(date +%s)
|
|
||||||
else
|
|
||||||
echo "Timeout while waiting for docker to come up"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo "Docker was initialized"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function stop_docker() {
|
|
||||||
local starttime
|
|
||||||
local endtime
|
|
||||||
|
|
||||||
echo "Stopping in container docker..."
|
|
||||||
if [ "$DOCKER_PID" -gt 0 ] && kill -0 "$DOCKER_PID" 2> /dev/null; then
|
|
||||||
starttime="$(date +%s)"
|
|
||||||
endtime="$(date +%s)"
|
|
||||||
|
|
||||||
# Now wait for it to die
|
|
||||||
kill "$DOCKER_PID"
|
|
||||||
while kill -0 "$DOCKER_PID" 2> /dev/null; do
|
|
||||||
if [ $((endtime - starttime)) -le $DOCKER_TIMEOUT ]; then
|
|
||||||
sleep 1
|
|
||||||
endtime=$(date +%s)
|
|
||||||
else
|
|
||||||
echo "Timeout while waiting for container docker to die"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo "Your host might have been left with unreleased resources"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function cleanup_lastboot() {
|
|
||||||
if [[ -f /tmp/supervisor_data/config.json ]]; then
|
|
||||||
echo "Cleaning up last boot"
|
|
||||||
cp /tmp/supervisor_data/config.json /tmp/config.json
|
|
||||||
jq -rM 'del(.last_boot)' /tmp/config.json > /tmp/supervisor_data/config.json
|
|
||||||
rm /tmp/config.json
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function cleanup_docker() {
|
|
||||||
echo "Cleaning up stopped containers..."
|
|
||||||
docker rm "$(docker ps -a -q)" || true
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_supervisor() {
|
|
||||||
mkdir -p /tmp/supervisor_data
|
|
||||||
docker run --rm --privileged \
|
|
||||||
--name hassio_supervisor \
|
|
||||||
--security-opt seccomp=unconfined \
|
|
||||||
--security-opt apparmor:unconfined \
|
|
||||||
-v /run/docker.sock:/run/docker.sock:rw \
|
|
||||||
-v /run/dbus:/run/dbus:ro \
|
|
||||||
-v /run/udev:/run/udev:ro \
|
|
||||||
-v /tmp/supervisor_data:/data:rw \
|
|
||||||
-v "/workspaces/addons":/data/addons/local:rw \
|
|
||||||
-v /etc/machine-id:/etc/machine-id:ro \
|
|
||||||
-e SUPERVISOR_SHARE="/tmp/supervisor_data" \
|
|
||||||
-e SUPERVISOR_NAME=hassio_supervisor \
|
|
||||||
-e SUPERVISOR_DEV=1 \
|
|
||||||
-e SUPERVISOR_MACHINE="qemux86-64" \
|
|
||||||
"homeassistant/amd64-hassio-supervisor:${SUPERVISOR_VERSON}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function init_dbus() {
|
|
||||||
if pgrep dbus-daemon; then
|
|
||||||
echo "Dbus is running"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Startup dbus"
|
|
||||||
mkdir -p /var/lib/dbus
|
|
||||||
cp -f /etc/machine-id /var/lib/dbus/machine-id
|
|
||||||
|
|
||||||
# cleanups
|
|
||||||
mkdir -p /run/dbus
|
|
||||||
rm -f /run/dbus/pid
|
|
||||||
|
|
||||||
# run
|
|
||||||
dbus-daemon --system --print-address
|
|
||||||
}
|
|
||||||
|
|
||||||
function init_udev() {
|
|
||||||
if pgrep systemd-udevd; then
|
|
||||||
echo "udev is running"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Startup udev"
|
|
||||||
|
|
||||||
# cleanups
|
|
||||||
mkdir -p /run/udev
|
|
||||||
|
|
||||||
# run
|
|
||||||
/lib/systemd/systemd-udevd --daemon
|
|
||||||
sleep 3
|
|
||||||
udevadm trigger && udevadm settle
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Start Test-Env"
|
|
||||||
|
|
||||||
start_docker
|
|
||||||
trap "stop_docker" ERR
|
|
||||||
|
|
||||||
docker system prune -f
|
|
||||||
|
|
||||||
cleanup_lastboot
|
|
||||||
cleanup_docker
|
|
||||||
init_dbus
|
|
||||||
init_udev
|
|
||||||
run_supervisor
|
|
||||||
stop_docker
|
|
||||||
17
.vscode/tasks.json
vendored
17
.vscode/tasks.json
vendored
@@ -1,31 +1,20 @@
|
|||||||
{
|
{
|
||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
||||||
// for the documentation about the tasks.json format
|
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"label": "Start Home Assistant",
|
"label": "Start Home Assistant",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "/workspaces/addons/.devcontainer/supervisor.sh",
|
"command": "supervisor_run",
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "test",
|
"kind": "test",
|
||||||
"isDefault": true,
|
"isDefault": true
|
||||||
},
|
},
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"reveal": "always",
|
"reveal": "always",
|
||||||
"panel": "new"
|
"panel": "new"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},{
|
|
||||||
"label": "Run Home Assistant CLI",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "docker exec -ti hassio_cli /usr/bin/cli.sh",
|
|
||||||
"group": "test",
|
|
||||||
"presentation": {
|
|
||||||
"reveal": "always",
|
|
||||||
"panel": "new"
|
|
||||||
},
|
|
||||||
"problemMatcher": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user