From ebae265aa868682050d0c13dbbb51ca52672cf33 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 20 Mar 2017 00:52:54 +0100 Subject: [PATCH] Script that build homeassistant docker for multible arch --- .../create_hassio_supervisor.sh | 5 +- .../homeassistant/create_homeassistant.sh | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 build-scripts/homeassistant/create_homeassistant.sh diff --git a/build-scripts/hassio-supervisor/create_hassio_supervisor.sh b/build-scripts/hassio-supervisor/create_hassio_supervisor.sh index f58e436fe..5368458dd 100755 --- a/build-scripts/hassio-supervisor/create_hassio_supervisor.sh +++ b/build-scripts/hassio-supervisor/create_hassio_supervisor.sh @@ -9,7 +9,7 @@ cleanup() { echo "[INFO] Cleanup." # Stop docker container - echo "[INFO] Cleaning up yocto-build container." + echo "[INFO] Cleaning up hassio-build container." docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true @@ -21,7 +21,7 @@ trap 'cleanup fail' SIGINT SIGTERM # Sanity checks if [ "$#" -ne 2 ]; then - echo "Usage: create_hassio_supervisor.sh |NONE" + echo "Usage: create_hassio_supervisor.sh |NONE" echo "Optional environment: BUILD_DIR" exit 1 fi @@ -65,6 +65,7 @@ docker run --rm \ /run-docker.sh echo "[INFO] cleanup WORKSPACE" +cd $BUILD_DIR rm -rf $WORKSPACE cleanup diff --git a/build-scripts/homeassistant/create_homeassistant.sh b/build-scripts/homeassistant/create_homeassistant.sh new file mode 100644 index 000000000..a0eb712d8 --- /dev/null +++ b/build-scripts/homeassistant/create_homeassistant.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +set -e + +BUILD_CONTAINER_NAME=homeassistant-build-$$ +DOCKER_REPO=pvizeli + +cleanup() { + echo "[INFO] Cleanup." + + # Stop docker container + echo "[INFO] Cleaning up homeassistant-build container." + docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true + docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true + + if [ "$1" == "fail" ]; then + exit 1 + fi +} +trap 'cleanup fail' SIGINT SIGTERM + +# Sanity checks +if [ "$#" -ne 2 ]; then + echo "Usage: create_homeassistant.sh " + echo "Optional environment: BUILD_DIR" + exit 1 +fi + +# Get the absolute script location +pushd `dirname $0` > /dev/null 2>&1 +SCRIPTPATH=`pwd` +popd > /dev/null 2>&1 + +HASS_VERS=$1 +MACHINE=$2 +BASE_IMAGE="resin\/${MACHINE}-python:3.6" +DOCKER_TAG=$1 +DOCKER_IMAGE=${MACHINE}-homeassistant +BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH} +WORKSPACE=${BUILD_DIR:=$SCRIPTPATH}/hass + +# setup docker +echo "[INFO] Setup docker for homeassistant" +mkdir -p $BUILD_DIR + +echo "[INFO] load homeassistant" +cd $BUILD_DIR && git clone https://github.com/home-assistant/home-assistant hass +cd hass && git checkout $HASS_VERS + +sed -i "s/FROM.*/${BASE_IMAGE}/g" Dockerfile + +# Run build +echo "[INFO] start docker build" +docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true +docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true +docker run --rm \ + -v $WORKSPACE:/docker \ + -v ~/.docker:/root/.docker \ + -e DOCKER_REPO=$DOCKER_REPO \ + -e DOCKER_IMAGE=$DOCKER_IMAGE \ + -e DOCKER_TAG=$DOCKER_TAG \ + --name $BUILD_CONTAINER_NAME \ + --privileged \ + pvizeli/docker-build-env \ + /run-docker.sh + +echo "[INFO] cleanup WORKSPACE" +cd $BUILD_DIR +rm -rf $WORKSPACE + +cleanup +exit 0