mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 13:14:21 +01:00
Add devcontainer (#1040)
* Add devcontainer (generic add-on devcontainer also available at https://github.com/issacg/hassio-addon-devcontainer) * remove example code (https://github.com/home-assistant/hassio-addons/pull/1040#discussion_r374373037) * Run start_hassio.sh from inside .devcontainer (https://github.com/home-assistant/hassio-addons/pull/1040#discussion_r374373323)
This commit is contained in:
34
.devcontainer/Dockerfile
Normal file
34
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
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 \
|
||||
dbus \
|
||||
software-properties-common \
|
||||
gpg-agent \
|
||||
git \
|
||||
sudo \
|
||||
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - \
|
||||
&& add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends \
|
||||
docker-ce \
|
||||
docker-ce-cli \
|
||||
containerd.io
|
||||
# This is a development container. Don't bother to clean up apt cache, this way we have it handy later
|
||||
|
||||
# Generate a machine-id for this container
|
||||
RUN rm /etc/machine-id && dbus-uuidgen --ensure=/etc/machine-id
|
||||
|
||||
ENV DEBIAN_FRONTEND=dialog
|
||||
17
.devcontainer/devcontainer.json
Normal file
17
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,17 @@
|
||||
// Based on https://github.com/issacg/hassio-addon-devcontainer
|
||||
{
|
||||
"name": "Hass.io Community Add-Ons",
|
||||
"context": "..",
|
||||
"dockerFile": "Dockerfile",
|
||||
"appPort": 8123,
|
||||
"runArgs": [
|
||||
"-e",
|
||||
"GIT_EDITOR=code --wait",
|
||||
"--privileged"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
103
.devcontainer/start_hassio.sh
Normal file
103
.devcontainer/start_hassio.sh
Normal file
@@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
set -eE
|
||||
|
||||
DOCKER_TIMEOUT=30
|
||||
DOCKER_PID=0
|
||||
|
||||
|
||||
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 install() {
|
||||
docker pull homeassistant/amd64-hassio-supervisor:dev
|
||||
docker pull homeassistant/amd64-hassio-cli: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 run_supervisor() {
|
||||
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 /etc/machine-id:/etc/machine-id:ro \
|
||||
-e SUPERVISOR_SHARE="/workspaces/test_hassio" \
|
||||
-e SUPERVISOR_NAME=hassio_supervisor \
|
||||
-e SUPERVISOR_DEV=1 \
|
||||
-e HOMEASSISTANT_REPOSITORY="homeassistant/qemux86-64-homeassistant" \
|
||||
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 Hass.io environment"
|
||||
start_docker
|
||||
trap "stop_docker" ERR
|
||||
cleanup_docker || true
|
||||
install
|
||||
run_supervisor
|
||||
stop_docker;;
|
||||
esac
|
||||
41
.vscode/tasks.json
vendored
Normal file
41
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Start Hass.io",
|
||||
"type": "shell",
|
||||
"command": "/workspaces/test_hassio/addons/local/.devcontainer/start_hassio.sh",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true,
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},{
|
||||
"label": "Cleanup stale Hass.io environment",
|
||||
"type": "shell",
|
||||
"command": "/workspaces/test_hassio/addons/local/.devcontainer/start_hassio.sh --cleanup",
|
||||
"group": "test",
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},{
|
||||
"label": "Run Hass.io CLI",
|
||||
"type": "shell",
|
||||
"command": "docker run --rm -ti -v /etc/machine-id:/etc/machine-id --network=hassio --add-host hassio:172.30.32.2 homeassistant/amd64-hassio-cli:dev",
|
||||
"group": "test",
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user