From 97d3f49bb83f385db78c9e46f23cd32469c3a303 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 20 Aug 2019 19:37:55 +0200 Subject: [PATCH] Docker ADR (#26085) * Migrate Docker image to Hass.io / Multiarch * Fix sudo * Update CODEOWNERS * Fix manifest * Add more logic * fix handling * Move dockerfile * Modify options --- .devcontainer/devcontainer.json | 7 +- CODEOWNERS | 4 - Dockerfile | 38 ------ .devcontainer/Dockerfile => Dockerfile.dev | 1 + azure-pipelines-release.yml | 58 ++++++++- script/hassfest/codeowners.py | 4 - virtualization/Docker/Dockerfile.dev | 64 --------- virtualization/Docker/scripts/libcec | 47 ------- virtualization/Docker/scripts/locales | 12 -- virtualization/Docker/scripts/openalpr | 32 ----- virtualization/Docker/scripts/ssocr | 24 ---- virtualization/Docker/scripts/tellstick | 17 --- virtualization/Docker/setup_docker_prereqs | 84 ------------ virtualization/vagrant/Vagrantfile | 24 ---- virtualization/vagrant/config/.placeholder | 0 .../vagrant/home-assistant@.service | 23 ---- virtualization/vagrant/provision.bat | 50 -------- virtualization/vagrant/provision.sh | 121 ------------------ 18 files changed, 62 insertions(+), 548 deletions(-) delete mode 100644 Dockerfile rename .devcontainer/Dockerfile => Dockerfile.dev (97%) delete mode 100644 virtualization/Docker/Dockerfile.dev delete mode 100755 virtualization/Docker/scripts/libcec delete mode 100755 virtualization/Docker/scripts/locales delete mode 100755 virtualization/Docker/scripts/openalpr delete mode 100755 virtualization/Docker/scripts/ssocr delete mode 100755 virtualization/Docker/scripts/tellstick delete mode 100755 virtualization/Docker/setup_docker_prereqs delete mode 100644 virtualization/vagrant/Vagrantfile delete mode 100644 virtualization/vagrant/config/.placeholder delete mode 100644 virtualization/vagrant/home-assistant@.service delete mode 100644 virtualization/vagrant/provision.bat delete mode 100755 virtualization/vagrant/provision.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ff2d586fc5a30..22bd4384b23e5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,11 +2,12 @@ { "name": "Home Assistant Dev", "context": "..", - "dockerFile": "Dockerfile", + "dockerFile": "../Dockerfile.dev", "postCreateCommand": "pip3 install -e .", "appPort": 8123, "runArgs": [ - "-e", "GIT_EDITOR=\"code --wait\"" + "-e", + "GIT_EDITOR=\"code --wait\"" ], "extensions": [ "ms-python.python", @@ -31,4 +32,4 @@ "!include_dir_merge_named scalar" ] } -} +} \ No newline at end of file diff --git a/CODEOWNERS b/CODEOWNERS index 1425c4764787e..3d17b4f91362c 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -9,10 +9,6 @@ homeassistant/*.py @home-assistant/core homeassistant/helpers/* @home-assistant/core homeassistant/util/* @home-assistant/core -# Virtualization -Dockerfile @home-assistant/docker -virtualization/Docker/* @home-assistant/docker - # Other code homeassistant/scripts/check_config.py @kellerza diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index ebd802374ebda..0000000000000 --- a/Dockerfile +++ /dev/null @@ -1,38 +0,0 @@ -# Notice: -# When updating this file, please also update virtualization/Docker/Dockerfile.dev -# This way, the development image and the production image are kept in sync. - -FROM python:3.7-buster -LABEL maintainer="Paulus Schoutsen " - -# Uncomment any of the following lines to disable the installation. -#ENV INSTALL_TELLSTICK no -#ENV INSTALL_OPENALPR no -#ENV INSTALL_FFMPEG no -#ENV INSTALL_LIBCEC no -#ENV INSTALL_SSOCR no -#ENV INSTALL_DLIB no -#ENV INSTALL_IPERF3 no -#ENV INSTALL_LOCALES no - -VOLUME /config - -WORKDIR /usr/src/app - -# Copy build scripts -COPY virtualization/Docker/ virtualization/Docker/ -RUN virtualization/Docker/setup_docker_prereqs - -# Install hass component dependencies -COPY requirements_all.txt requirements_all.txt -RUN pip3 install --no-cache-dir -r requirements_all.txt && \ - pip3 install --no-cache-dir mysqlclient psycopg2 cchardet cython tensorflow - -# Copy source -COPY . . - -EXPOSE 8123 -EXPOSE 8300 -EXPOSE 51827 - -CMD [ "python", "-m", "homeassistant", "--config", "/config" ] diff --git a/.devcontainer/Dockerfile b/Dockerfile.dev similarity index 97% rename from .devcontainer/Dockerfile rename to Dockerfile.dev index 3bfc7e94148dc..00f5576bdbb0f 100644 --- a/.devcontainer/Dockerfile +++ b/Dockerfile.dev @@ -16,6 +16,7 @@ RUN apt-get update \ WORKDIR /usr/src +# Setup hass-release RUN git clone --depth 1 https://github.com/home-assistant/hass-release \ && cd hass-release \ && pip3 install -e . diff --git a/azure-pipelines-release.yml b/azure-pipelines-release.yml index 13a031fda15d7..1b547d5c60960 100644 --- a/azure-pipelines-release.yml +++ b/azure-pipelines-release.yml @@ -60,7 +60,7 @@ stages: - script: | export TWINE_USERNAME="$(twineUser)" export TWINE_PASSWORD="$(twinePassword)" - + twine upload dist/* --skip-existing displayName: 'Upload pypi' - job: 'ReleaseDocker' @@ -150,3 +150,59 @@ stages: git commit -am "Bump Home Assistant $version" git push displayName: 'Update version files' + - job: 'ReleaseDocker' + pool: + vmImage: 'ubuntu-latest' + steps: + - script: | + set -e + export DOCKER_CLI_EXPERIMENTAL=enabled + + function create_manifest() { + local tag_l=$1 + local tag_r=$2 + + sudo docker manifest create homeassistant/home-assistant:${tag_l} \ + homeassistant/amd64-homeassistant:${tag_r} \ + homeassistant/i386-homeassistant:${tag_r} \ + homeassistant/armhf-homeassistant:${tag_r} \ + homeassistant/armv7-homeassistant:${tag_r} \ + homeassistant/aarch64-homeassistant:${tag_r} + + sudo docker manifest annotate homeassistant/home-assistant:${tag_l} \ + homeassistant/amd64-homeassistant:${tag_r} \ + --os linux --arch amd64 + + sudo docker manifest annotate homeassistant/home-assistant:${tag_l} \ + homeassistant/i386-homeassistant:${tag_r} \ + --os linux --arch i386 + + sudo docker manifest annotate homeassistant/home-assistant:${tag_l} \ + homeassistant/armhf-homeassistant:${tag_r} \ + --os linux --arch arm --variant=v6 + + sudo docker manifest annotate homeassistant/home-assistant:${tag_l} \ + homeassistant/armv7-homeassistant:${tag_r} \ + --os linux --arch arm --variant=v7 + + sudo docker manifest annotate homeassistant/home-assistant:${tag_l} \ + homeassistant/aarch64-homeassistant:${tag_r} \ + --os linux --arch arm64 --variant=v8 + + sudo docker manifest push --purge homeassistant/home-assistant:${tag_l} + } + + # Create version tag + create_manifest "$(Build.SourceBranchName)" "$(Build.SourceBranchName)" + + # Create general tags + if [[ "$version" =~ d ]]; then + create_manifest "dev" "$(Build.SourceBranchName)" + elif [[ "$version" =~ b ]]; then + create_manifest "beta" "$(Build.SourceBranchName)" + else + create_manifest "stable" "$(Build.SourceBranchName)" + create_manifest "latest" "$(Build.SourceBranchName)" + fi + + displayName: 'Create Meta-Image' diff --git a/script/hassfest/codeowners.py b/script/hassfest/codeowners.py index 07a1d827b33b7..1341bd75d1b0c 100755 --- a/script/hassfest/codeowners.py +++ b/script/hassfest/codeowners.py @@ -15,10 +15,6 @@ homeassistant/helpers/* @home-assistant/core homeassistant/util/* @home-assistant/core -# Virtualization -Dockerfile @home-assistant/docker -virtualization/Docker/* @home-assistant/docker - # Other code homeassistant/scripts/check_config.py @kellerza diff --git a/virtualization/Docker/Dockerfile.dev b/virtualization/Docker/Dockerfile.dev deleted file mode 100644 index 2e98c53cdf1b4..0000000000000 --- a/virtualization/Docker/Dockerfile.dev +++ /dev/null @@ -1,64 +0,0 @@ -# Dockerfile for development -# Based on the production Dockerfile, but with development additions. -# Keep this file as close as possible to the production Dockerfile, so the environments match. - -FROM python:3.7-buster -LABEL maintainer="Paulus Schoutsen " - -# Uncomment any of the following lines to disable the installation. -#ENV INSTALL_TELLSTICK no -#ENV INSTALL_OPENALPR no -#ENV INSTALL_FFMPEG no -#ENV INSTALL_LIBCEC no -#ENV INSTALL_COAP no -#ENV INSTALL_SSOCR no -#ENV INSTALL_DLIB no -#ENV INSTALL_IPERF3 no -#ENV INSTALL_LOCALES no - -VOLUME /config - -WORKDIR /usr/src/app - -# Copy build scripts -COPY virtualization/Docker/ virtualization/Docker/ -RUN virtualization/Docker/setup_docker_prereqs - -# Install hass component dependencies -COPY requirements_all.txt requirements_all.txt - -RUN pip3 install --no-cache-dir -r requirements_all.txt && \ - pip3 install --no-cache-dir mysqlclient psycopg2 cchardet cython - -# BEGIN: Development additions - -# Install git -RUN apt-get update \ - && apt-get install -y --no-install-recommends git \ - && rm -rf /var/lib/apt/lists/* - -# Install nodejs -RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - && \ - apt-get install -y nodejs - -# Install tox -RUN pip3 install --no-cache-dir tox - -# Copy over everything required to run tox -COPY requirements_test_all.txt setup.cfg setup.py tox.ini ./ -COPY homeassistant/const.py homeassistant/const.py - -# Prefetch dependencies for tox -COPY homeassistant/package_constraints.txt homeassistant/package_constraints.txt -RUN tox -e py37 --notest - -# END: Development additions - -# Copy source -COPY . . - -EXPOSE 8123 -EXPOSE 8300 -EXPOSE 51827 - -CMD [ "python", "-m", "homeassistant", "--config", "/config" ] diff --git a/virtualization/Docker/scripts/libcec b/virtualization/Docker/scripts/libcec deleted file mode 100755 index 481b3e700accb..0000000000000 --- a/virtualization/Docker/scripts/libcec +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -# Sets up libcec. -# Dependencies that need to be installed: -# apt-get install cmake libudev-dev libxrandr-dev swig - -# Stop on errors -set -e - -# Load required information about the current python environment -PYTHON_LIBDIR=$(python -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LIBDIR"))') -PYTHON_LDLIBRARY=$(python -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LDLIBRARY"))') -PYTHON_LIBRARY="${PYTHON_LIBDIR}/${PYTHON_LDLIBRARY}" -PYTHON_INCLUDE_DIR=$(python -c 'from distutils import sysconfig; print(sysconfig.get_python_inc())') - -cd /usr/src/app/ -mkdir -p build && cd build - -if [ ! -d libcec ]; then - git clone --branch release --depth 1 https://github.com/Pulse-Eight/libcec.git -fi - -cd libcec -git checkout release -git pull -git submodule update --init src/platform - -# Build libcec platform libs -( - mkdir -p src/platform/build - cd src/platform/build - cmake .. - make - make install -) - -# Build libcec -( - mkdir -p build && cd build - - cmake \ - -DPYTHON_LIBRARY="${PYTHON_LIBRARY}" \ - -DPYTHON_INCLUDE_DIR="${PYTHON_INCLUDE_DIR}" \ - .. - make -j$(nproc) - make install - ldconfig -) diff --git a/virtualization/Docker/scripts/locales b/virtualization/Docker/scripts/locales deleted file mode 100755 index cbbe03415751c..0000000000000 --- a/virtualization/Docker/scripts/locales +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# Sets up locales. - -# Stop on errors -set -e - -apt-get update -apt-get install -y --no-install-recommends locales - -# Set the locale -sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen -locale-gen diff --git a/virtualization/Docker/scripts/openalpr b/virtualization/Docker/scripts/openalpr deleted file mode 100755 index 38669f8175baa..0000000000000 --- a/virtualization/Docker/scripts/openalpr +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# Sets up openalpr. - -# Stop on errors -set -e - -PACKAGES=( - # homeassistant.components.image_processing.openalpr_local - libopencv-dev libtesseract-dev libleptonica-dev liblog4cplus-dev -) - -apt-get install -y --no-install-recommends ${PACKAGES[@]} - -cd /usr/src/app/ -mkdir -p build && cd build - -# Clone the latest code from GitHub -git clone --depth 1 https://github.com/openalpr/openalpr.git openalpr - -# Setup the build directory -cd openalpr/src/ -mkdir -p build -cd build - -# Setup the compile environment -cmake -DWITH_TESTS=FALSE -DWITH_BINDING_JAVA=FALSE --DWITH_BINDING_PYTHON=FALSE --DWITH_BINDING_GO=FALSE -DWITH_DAEMON=FALSE -DCMAKE_INSTALL_PREFIX:PATH=/usr/local .. - -# compile the library -make -j$(nproc) - -# Install the binaries/libraries to your local system (prefix is /usr/local) -make install diff --git a/virtualization/Docker/scripts/ssocr b/virtualization/Docker/scripts/ssocr deleted file mode 100755 index 6778bcab90d01..0000000000000 --- a/virtualization/Docker/scripts/ssocr +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# Sets up ssocr to support Seven Segments Display. - -# Stop on errors -set -e - -PACKAGES=( - libimlib2 libimlib2-dev -) - -apt-get install -y --no-install-recommends ${PACKAGES[@]} - -cd /usr/src/app/ -mkdir -p build && cd build - -# Clone the latest code from GitHub -git clone --depth 1 https://github.com/auerswal/ssocr.git ssocr -cd ssocr/ - -# Compile the library -make -j$(nproc) - -# Install the binaries/libraries to your local system (prefix is /usr/local) -make install diff --git a/virtualization/Docker/scripts/tellstick b/virtualization/Docker/scripts/tellstick deleted file mode 100755 index d35e1cac2dbd9..0000000000000 --- a/virtualization/Docker/scripts/tellstick +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# Sets up tellstick. - -# Stop on errors -set -e - -PACKAGES=( - # homeassistant.components.tellstick - libtelldus-core2 socat -) - -# Add Tellstick repository -echo "deb http://download.telldus.com/debian/ stable main" >> /etc/apt/sources.list.d/telldus.list -wget -qO - http://download.telldus.com/debian/telldus-public.key | apt-key add - - -apt-get update -apt-get install -y --no-install-recommends ${PACKAGES[@]} diff --git a/virtualization/Docker/setup_docker_prereqs b/virtualization/Docker/setup_docker_prereqs deleted file mode 100755 index 62ac73d366ec9..0000000000000 --- a/virtualization/Docker/setup_docker_prereqs +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -# Install requirements and build dependencies for Home Assistant in Docker. - -# Stop on errors -set -e - -INSTALL_TELLSTICK="${INSTALL_TELLSTICK:-yes}" -INSTALL_OPENALPR="${INSTALL_OPENALPR:-yes}" -INSTALL_LIBCEC="${INSTALL_LIBCEC:-yes}" -INSTALL_SSOCR="${INSTALL_SSOCR:-yes}" -INSTALL_DLIB="${INSTALL_DLIB:-yes}" -INSTALL_LOCALES="${INSTALL_LOCALES:-yes}" - -# Required debian packages for running hass or components -PACKAGES=( - # build-essential is required for python pillow module on non-x86_64 arch - build-essential - # homeassistant.components.image_processing.openalpr_local - libxrandr-dev - # homeassistant.components.device_tracker.nmap_tracker - nmap net-tools libcurl3-dev - # homeassistant.components.device_tracker.bluetooth_tracker - bluetooth libglib2.0-dev libbluetooth-dev - # homeassistant.components.device_tracker.owntracks - libsodium23 - # homeassistant.components.zwave - libudev-dev - # homeassistant.components.homekit_controller - libmpc-dev libmpfr-dev libgmp-dev - # homeassistant.components.ffmpeg - ffmpeg - # homeassistant.components.stream - libavformat-dev libavcodec-dev libavdevice-dev - libavutil-dev libswscale-dev libswresample-dev libavfilter-dev - # homeassistant.components.sensor.iperf3 - iperf3 -) - -# Required debian packages for building dependencies -PACKAGES_DEV=( - cmake - git - swig -) - -# Install packages -apt-get update -apt-get install -y --no-install-recommends ${PACKAGES[@]} ${PACKAGES_DEV[@]} - -# This is a list of scripts that install additional dependencies. If you only -# need to install a package from the official debian repository, just add it -# to the list above. Only create a script if you need compiling, manually -# downloading or a 3rd party repository. -if [ "$INSTALL_TELLSTICK" == "yes" ]; then - virtualization/Docker/scripts/tellstick -fi - -if [ "$INSTALL_OPENALPR" == "yes" ]; then - virtualization/Docker/scripts/openalpr -fi - -if [ "$INSTALL_LIBCEC" == "yes" ]; then - virtualization/Docker/scripts/libcec -fi - -if [ "$INSTALL_SSOCR" == "yes" ]; then - virtualization/Docker/scripts/ssocr -fi - -if [ "$INSTALL_DLIB" == "yes" ]; then - pip3 install --no-cache-dir "dlib>=19.5" -fi - -if [ "$INSTALL_LOCALES" == "yes" ]; then - virtualization/Docker/scripts/locales -fi - -# Remove packages -apt-get remove -y --purge ${PACKAGES_DEV[@]} -apt-get -y --purge autoremove - -# Cleanup -apt-get clean -rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/src/app/build/ diff --git a/virtualization/vagrant/Vagrantfile b/virtualization/vagrant/Vagrantfile deleted file mode 100644 index d3974d51a7aa3..0000000000000 --- a/virtualization/vagrant/Vagrantfile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant.configure(2) do |config| - config.vm.box = "debian/contrib-stretch64" - config.vm.synced_folder "../../", "/home-assistant" - config.vm.synced_folder "./config", "/root/.homeassistant" - config.vm.network "forwarded_port", guest: 8123, host: 8123 - config.vm.provision "fix-no-tty", type: "shell" do |shell| - shell.path = "provision.sh" - end - config.vm.provider :virtualbox do |vb| - vb.cpus = 2 - vb.customize ['modifyvm', :id, '--memory', '1024'] - end - config.vm.provider :hyperv do |h, override| - override.vm.box = "generic/debian9" - override.vm.hostname = "contrib-stretch" - h.vmname = "home-assistant" - h.cpus = 2 - h.memory = 1024 - h.maxmemory = 1024 - end -end diff --git a/virtualization/vagrant/config/.placeholder b/virtualization/vagrant/config/.placeholder deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/virtualization/vagrant/home-assistant@.service b/virtualization/vagrant/home-assistant@.service deleted file mode 100644 index 91b7307f30fc9..0000000000000 --- a/virtualization/vagrant/home-assistant@.service +++ /dev/null @@ -1,23 +0,0 @@ -# This is a simple service file for systems with systemd to tun HA as user. -# -# For details please check https://home-assistant.io/getting-started/autostart/ -# -[Unit] -Description=Home Assistant for %i -After=network.target - -[Service] -Type=simple -User=%i -# Enable the following line if you get network-related HA errors during boot -#ExecStartPre=/usr/bin/sleep 60 -# Use `whereis hass` to determine the path of hass -ExecStart=/usr/bin/hass --runner -SendSIGKILL=no -RestartForceExitStatus=100 - -# on vagrant (vboxfs), disable sendfile https://www.virtualbox.org/ticket/9069 -Environment=AIOHTTP_NOSENDFILE=1 - -[Install] -WantedBy=multi-user.target diff --git a/virtualization/vagrant/provision.bat b/virtualization/vagrant/provision.bat deleted file mode 100644 index c8174e939a198..0000000000000 --- a/virtualization/vagrant/provision.bat +++ /dev/null @@ -1,50 +0,0 @@ -@echo off -call:main %* -goto:eof - -:usage -echo.############################################################ -echo. -echo.Use `./provision.bat` to interact with HASS. E.g: -echo. -echo.- setup the environment: `./provision.bat start` -echo.- restart HASS process: `./provision.bat restart` -echo.- run test suit: `./provision.bat tests` -echo.- destroy the host and start anew: `./provision.bat recreate` -echo. -echo.Official documentation at https://home-assistant.io/docs/installation/vagrant/ -echo. -echo.############################################################' -goto:eof - -:main -if "%*"=="setup" ( - if exist setup_done del setup_done - vagrant up --provision - copy /y nul setup_done -) else ( -if "%*"=="tests" ( - copy /y nul run_tests - vagrant provision -) else ( -if "%*"=="restart" ( - copy /y nul restart - vagrant provision -) else ( -if "%*"=="start" ( - vagrant up --provision -) else ( -if "%*"=="stop" ( - vagrant halt -) else ( -if "%*"=="destroy" ( - vagrant destroy -f -) else ( -if "%*"=="recreate" ( - if exist setup_done del setup_done - if exist restart del restart - vagrant destroy -f - vagrant up --provision -) else ( - call:usage -))))))) diff --git a/virtualization/vagrant/provision.sh b/virtualization/vagrant/provision.sh deleted file mode 100755 index 1d2eecddc73f9..0000000000000 --- a/virtualization/vagrant/provision.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash -set -e - -readonly SETUP_DONE='/home-assistant/virtualization/vagrant/setup_done' -readonly RUN_TESTS='/home-assistant/virtualization/vagrant/run_tests' -readonly RESTART='/home-assistant/virtualization/vagrant/restart' - -usage() { - echo '############################################################ - -Use `./provision.sh` to interact with HASS. E.g: - -- setup the environment: `./provision.sh start` -- restart HASS process: `./provision.sh restart` -- run test suit: `./provision.sh tests` -- destroy the host and start anew: `./provision.sh recreate` - -Official documentation at https://home-assistant.io/docs/installation/vagrant/ - -############################################################' -} - -print_done() { - echo '############################################################ - - -HASS running => http://localhost:8123/ - -' -} - -setup_error() { - echo '############################################################ -Something is off... maybe setup did not complete properly? -Please ensure setup did run correctly at least once. - -To run setup again: `./provision.sh setup` - -############################################################' - exit 1 -} - -setup() { - local hass_path='/root/venv/bin/hass' - local systemd_bin_path='/usr/bin/hass' - # Setup systemd - cp /home-assistant/virtualization/vagrant/home-assistant@.service \ - /etc/systemd/system/home-assistant.service - systemctl --system daemon-reload - systemctl enable home-assistant - systemctl stop home-assistant - # Install packages - apt-get update - apt-get install -y git rsync python3-dev python3-pip libssl-dev libffi-dev - pip3 install --upgrade virtualenv - virtualenv ~/venv - source ~/venv/bin/activate - pip3 install --upgrade tox - /home-assistant/script/setup - if ! [ -f $systemd_bin_path ]; then - ln -s $hass_path $systemd_bin_path - fi - touch $SETUP_DONE - print_done - usage -} - -run_tests() { - rm -f $RUN_TESTS - echo '############################################################' - echo; echo "Running test suite, hang on..."; echo; echo - if ! systemctl stop home-assistant; then - setup_error - fi - source ~/venv/bin/activate - rsync -a --delete \ - --exclude='*.tox' \ - --exclude='*.git' \ - --exclude='.vagrant' \ - --exclude='lib64' \ - --exclude='bin/python' \ - --exclude='bin/python3' \ - /home-assistant/ /home-assistant-tests/ - cd /home-assistant-tests && tox || true - echo '############################################################' -} - -restart() { - echo "Restarting Home Assistant..." - if ! systemctl restart home-assistant; then - setup_error - else - echo "done" - fi - rm $RESTART -} - -main() { - # If a parameter is provided, we assume it's the user interacting - # with the provider script... - case $1 in - "setup") rm -f setup_done; vagrant up --provision && touch setup_done; exit ;; - "tests") touch run_tests; vagrant provision ; exit ;; - "restart") touch restart; vagrant provision ; exit ;; - "start") vagrant up --provision ; exit ;; - "stop") vagrant halt ; exit ;; - "destroy") vagrant destroy -f ; exit ;; - "recreate") rm -f setup_done restart; vagrant destroy -f; \ - vagrant up --provision; exit ;; - esac - # ...otherwise we assume it's the Vagrant provisioner - if [ $(hostname) != "contrib-jessie" ] && [ $(hostname) != "contrib-stretch" ]; then usage; exit; fi - if ! [ -f $SETUP_DONE ]; then setup; fi - if [ -f $RESTART ]; then restart; fi - if [ -f $RUN_TESTS ]; then run_tests; fi - if ! systemctl start home-assistant; then - setup_error - fi -} - -main $*