mirror of
https://github.com/aljazceru/addons.git
synced 2026-01-31 18:55:32 +01:00
Simplify devcontainer setup (#1687)
* Simplify devcontainer setup * Add stable shellcheck * Fix observer port
This commit is contained in:
@@ -1,47 +1,34 @@
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/base:debian-10
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
|
||||
|
||||
WORKDIR /workspaces
|
||||
|
||||
# Default ENV
|
||||
ENV LANG C.UTF-8
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
# Set shell
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
# Install docker
|
||||
# https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
software-properties-common \
|
||||
gnupg \
|
||||
&& curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \
|
||||
&& add-apt-repository "deb https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends \
|
||||
docker-ce \
|
||||
docker-ce-cli \
|
||||
containerd.io \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# Set Docker daemon config
|
||||
RUN \
|
||||
mkdir -p /etc/docker \
|
||||
&& echo '{"storage-driver": "vfs"}' > /etc/docker/daemon.json
|
||||
|
||||
# Install tools
|
||||
ARG SHELLCHECK_VERSION=0.7.0
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
jq \
|
||||
# Installa aditional tools
|
||||
RUN \
|
||||
apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
dbus \
|
||||
network-manager \
|
||||
libpulse0 \
|
||||
git \
|
||||
tar \
|
||||
xz-utils \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
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 \
|
||||
\
|
||||
&& curl -SL "https://storage.googleapis.com/shellcheck/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar xJf - \
|
||||
&& cp "shellcheck-v${SHELLCHECK_VERSION}/shellcheck" /usr/bin/ \
|
||||
&& rm -rf shellcheck-v${SHELLCHECK_VERSION}
|
||||
&& 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
|
||||
|
||||
ENV DEBIAN_FRONTEND=dialog
|
||||
RUN rm /etc/machine-id && dbus-uuidgen --ensure=/etc/machine-id
|
||||
@@ -3,19 +3,14 @@
|
||||
"name": "Home Assistant Add-Ons",
|
||||
"context": "..",
|
||||
"dockerFile": "Dockerfile",
|
||||
"appPort": "7123:8123",
|
||||
"runArgs": [
|
||||
"-e",
|
||||
"GIT_EDITOR=code --wait",
|
||||
"--privileged"
|
||||
],
|
||||
"appPort": ["7123:8123", "7357:4357"],
|
||||
"postStartCommand": "service docker start",
|
||||
"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
|
||||
"extensions": [
|
||||
"timonwong.shellcheck",
|
||||
"esbenp.prettier-vscode"
|
||||
],
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/bin/bash"
|
||||
},
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/test_hassio/addons/local,type=bind,consistency=delegated",
|
||||
"workspaceFolder": "/workspaces/test_hassio/addons/local"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,58 +55,64 @@ function stop_docker() {
|
||||
}
|
||||
|
||||
|
||||
function install() {
|
||||
docker pull homeassistant/amd64-hassio-supervisor:dev
|
||||
}
|
||||
|
||||
function cleanup_hass_data() {
|
||||
rm -rf /workspaces/test_hassio/{apparmor,backup,config.json,dns,dns.json,homeassistant,homeassistant.json,ingress.json,share,ssl,tmp,updater.json}
|
||||
rm -rf /workspaces/test_hassio/addons/{core,data,git}
|
||||
}
|
||||
|
||||
function cleanup_docker() {
|
||||
echo "Cleaning up stopped containers..."
|
||||
docker rm "$(docker ps -a -q)"
|
||||
}
|
||||
|
||||
function cleanup_lastboot() {
|
||||
if [[ -f /workspaces/test_hassio/config.json ]]; then
|
||||
if [[ -f /tmp/supervisor_data/config.json ]]; then
|
||||
echo "Cleaning up last boot"
|
||||
cp /workspaces/test_hassio/config.json /tmp/config.json
|
||||
jq -rM 'del(.last_boot)' /tmp/config.json > /workspaces/test_hassio/config.json
|
||||
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 \
|
||||
-v /run/dbus:/run/dbus \
|
||||
-v "/workspaces/test_hassio":/data \
|
||||
-v /tmp/supervisor_data:/data \
|
||||
-v "/workspaces/addons":/data/addons/local \
|
||||
-v /etc/machine-id:/etc/machine-id:ro \
|
||||
-e SUPERVISOR_SHARE="/workspaces/test_hassio" \
|
||||
-e SUPERVISOR_SHARE="/tmp/supervisor_data" \
|
||||
-e SUPERVISOR_NAME=hassio_supervisor \
|
||||
-e SUPERVISOR_DEV=1 \
|
||||
-e SUPERVISOR_MACHINE="qemux86-64" \
|
||||
homeassistant/amd64-hassio-supervisor:dev
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"--cleanup")
|
||||
echo "Cleaning up old environment"
|
||||
cleanup_docker || true
|
||||
cleanup_hass_data || true
|
||||
exit 0;;
|
||||
*)
|
||||
echo "Creating development Supervisor environment"
|
||||
start_docker
|
||||
trap "stop_docker" ERR
|
||||
cleanup_docker || true
|
||||
cleanup_lastboot || true
|
||||
install
|
||||
run_supervisor
|
||||
stop_docker;;
|
||||
esac
|
||||
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
|
||||
}
|
||||
|
||||
echo "Start Test-Env"
|
||||
|
||||
start_docker
|
||||
trap "stop_docker" ERR
|
||||
|
||||
cleanup_lastboot
|
||||
cleanup_docker
|
||||
init_dbus
|
||||
run_supervisor
|
||||
stop_docker
|
||||
12
.vscode/tasks.json
vendored
12
.vscode/tasks.json
vendored
@@ -6,7 +6,7 @@
|
||||
{
|
||||
"label": "Start Home Assistant",
|
||||
"type": "shell",
|
||||
"command": "/workspaces/test_hassio/addons/local/.devcontainer/start_supervisor.sh",
|
||||
"command": "/workspaces/addons/.devcontainer/supervisor.sh",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true,
|
||||
@@ -16,16 +16,6 @@
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},{
|
||||
"label": "Cleanup stale Home Assistant environment",
|
||||
"type": "shell",
|
||||
"command": "/workspaces/test_hassio/addons/local/.devcontainer/start_supervisor.sh --cleanup",
|
||||
"group": "test",
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},{
|
||||
"label": "Run Home Assistant CLI",
|
||||
"type": "shell",
|
||||
|
||||
Reference in New Issue
Block a user