From 01a6e074a5670d434ef13481d91d06b89d39bb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 12 Jan 2021 13:50:11 +0100 Subject: [PATCH] Adjust development tasks (#2425) * Adjust development tasks * add development --- .devcontainer/Dockerfile | 5 ++ .vscode/tasks.json | 22 ++++-- README.md | 29 ++++---- scripts/build-supervisor.sh | 28 ++++++++ scripts/common.sh | 58 ++++++++++++++++ scripts/run-supervisor.sh | 81 ++++++++++++++++++++++ scripts/test_env.sh | 135 ------------------------------------ 7 files changed, 203 insertions(+), 155 deletions(-) create mode 100755 scripts/build-supervisor.sh create mode 100644 scripts/common.sh create mode 100755 scripts/run-supervisor.sh delete mode 100755 scripts/test_env.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d8a04fcf3..2beec3d93 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,6 +2,11 @@ FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.8 WORKDIR /workspaces +# Set Docker daemon config +RUN \ + mkdir -p /etc/docker \ + && echo '{"storage-driver": "vfs"}' > /etc/docker/daemon.json + # Install Node/Yarn for Frontent RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4e416daa8..97b66ee21 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,9 +2,9 @@ "version": "2.0.0", "tasks": [ { - "label": "Run Testenv", + "label": "Run Supervisor", "type": "shell", - "command": "./scripts/test_env.sh", + "command": "./scripts/run-supervisor.sh", "group": { "kind": "test", "isDefault": true @@ -16,7 +16,21 @@ "problemMatcher": [] }, { - "label": "Run Testenv CLI", + "label": "Build Supervisor", + "type": "shell", + "command": "./scripts/build-supervisor.sh", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + }, + { + "label": "Run Supervisor CLI", "type": "shell", "command": "docker exec -ti hassio_cli /usr/bin/cli.sh", "group": { @@ -30,7 +44,7 @@ "problemMatcher": [] }, { - "label": "Update UI", + "label": "Update Supervisor Panel", "type": "shell", "command": "./scripts/update-frontend.sh", "group": { diff --git a/README.md b/README.md index c4be92149..9e8269264 100644 --- a/README.md +++ b/README.md @@ -10,26 +10,23 @@ network settings or installing and updating software. ## Installation -Installation instructions can be found at https://home-assistant.io/hassio. +Installation instructions can be found at https://home-assistant.io/getting-started. ## Development -The development of the Supervisor is not difficult but tricky. - -- You can use the builder to create your Supervisor: https://github.com/home-assistant/hassio-builder -- Access a HassOS device or VM and pull your Supervisor. -- Set the developer modus with the CLI tool: `ha supervisor options --channel=dev` -- Tag it as `homeassistant/xy-hassio-supervisor:latest` -- Restart the service with `systemctl restart hassos-supervisor | journalctl -fu hassos-supervisor` -- Test your changes - -For small bugfixes or improvements, make a PR. For significant changes open a RFC first, please. Thanks. +For small changes and bugfixes you can just follow this, but for significant changes open a RFC first. +Development instructions can be found [here][development]. ## Release -Follow is the relase circle process: +Releases are done in 3 stages (channels) with this structure: -1. Merge master into dev / make sure version stay on dev -2. Merge dev into master -3. Bump the release on master -4. Create a GitHub Release from master with the right version tag +1. Pull requests are merged to the `main` branch +2. A new build is pushed to the `dev` stage. +3. Releases are published +4. A new build is pushed to the `beta` stage. +5. The [`stable.json][stable] file is updated +6. The build that was pushed to `beta` will now be pushed to `stable` + +[development]: https://developers.home-assistant.io/docs/supervisor/development +[stable]: https://github.com/home-assistant/version/blob/master/stable.json diff --git a/scripts/build-supervisor.sh b/scripts/build-supervisor.sh new file mode 100755 index 000000000..7ecd60eb4 --- /dev/null +++ b/scripts/build-supervisor.sh @@ -0,0 +1,28 @@ +#!/bin/bash +source "${BASH_SOURCE[0]%/*}/common.sh" + +set -eE + +DOCKER_TIMEOUT=30 +DOCKER_PID=0 + +function build_supervisor() { + docker pull homeassistant/amd64-builder:dev + + docker run --rm \ + --privileged \ + -v /run/docker.sock:/run/docker.sock \ + -v "$(pwd):/data" \ + homeassistant/amd64-builder:dev \ + --generic latest \ + --target /data \ + --test \ + --amd64 \ + --no-cache +} + +echo "Build Supervisor" +start_docker +trap "stop_docker" ERR + +build_supervisor diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 000000000..05126bb7d --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +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 /workspaces/test_supervisor/config.json ]]; then + echo "Cleaning up last boot" + cp /workspaces/test_supervisor/config.json /tmp/config.json + jq -rM 'del(.last_boot)' /tmp/config.json > /workspaces/test_supervisor/config.json + rm /tmp/config.json + fi +} diff --git a/scripts/run-supervisor.sh b/scripts/run-supervisor.sh new file mode 100755 index 000000000..c746ef588 --- /dev/null +++ b/scripts/run-supervisor.sh @@ -0,0 +1,81 @@ +#!/bin/bash +source "${BASH_SOURCE[0]%/*}/common.sh" +source "${BASH_SOURCE[0]%/*}/build-supervisor.sh" + +set -eE + +DOCKER_TIMEOUT=30 +DOCKER_PID=0 + + +function cleanup_docker() { + echo "Cleaning up stopped containers..." + docker rm $(docker ps -a -q) || true +} + + +function run_supervisor() { + mkdir -p /workspaces/test_supervisor + + echo "Start Supervisor" + docker run --rm --privileged \ + --name hassio_supervisor \ + --privileged \ + --security-opt seccomp=unconfined \ + --security-opt apparmor:unconfined \ + -v /run/docker.sock:/run/docker.sock \ + -v /run/dbus:/run/dbus \ + -v "/workspaces/test_supervisor":/data \ + -v /etc/machine-id:/etc/machine-id:ro \ + -v /workspaces/supervisor:/usr/src/supervisor \ + -e SUPERVISOR_SHARE="/workspaces/test_supervisor" \ + -e SUPERVISOR_NAME=hassio_supervisor \ + -e SUPERVISOR_DEV=1 \ + -e SUPERVISOR_MACHINE="qemux86-64" \ + homeassistant/amd64-hassio-supervisor:latest + +} + + +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 "Run Supervisor" + +start_docker +trap "stop_docker" ERR + + +if [ "$( docker container inspect -f '{{.State.Status}}' hassio_supervisor )" == "running" ]; then + echo "Restarting Supervisor" + docker rm -f hassio_supervisor + init_dbus + cleanup_lastboot + run_supervisor + stop_docker + +else + echo "Starting Supervisor" + docker system prune -f + build_supervisor + cleanup_lastboot + cleanup_docker + init_dbus + run_supervisor + stop_docker +fi \ No newline at end of file diff --git a/scripts/test_env.sh b/scripts/test_env.sh deleted file mode 100755 index 08c52a535..000000000 --- a/scripts/test_env.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/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 build_supervisor() { - docker pull homeassistant/amd64-builder:dev - - docker run --rm --privileged \ - -v /run/docker.sock:/run/docker.sock -v "$(pwd):/data" \ - homeassistant/amd64-builder:dev \ - --generic dev -t /data --test --amd64 --no-cache -} - - -function cleanup_lastboot() { - if [[ -f /workspaces/test_supervisor/config.json ]]; then - echo "Cleaning up last boot" - cp /workspaces/test_supervisor/config.json /tmp/config.json - jq -rM 'del(.last_boot)' /tmp/config.json > /workspaces/test_supervisor/config.json - rm /tmp/config.json - fi -} - - -function cleanup_docker() { - echo "Cleaning up stopped containers..." - docker rm $(docker ps -a -q) || true -} - - -function setup_test_env() { - mkdir -p /workspaces/test_supervisor - - echo "Start 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_supervisor":/data \ - -v /etc/machine-id:/etc/machine-id:ro \ - -e SUPERVISOR_SHARE="/workspaces/test_supervisor" \ - -e SUPERVISOR_NAME=hassio_supervisor \ - -e SUPERVISOR_DEV=1 \ - -e SUPERVISOR_MACHINE="qemux86-64" \ - homeassistant/amd64-hassio-supervisor:latest - -} - - -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 - -docker system prune -f - -build_supervisor -cleanup_lastboot -cleanup_docker -init_dbus -setup_test_env -stop_docker