Move homeassistant builder.

This commit is contained in:
Pascal Vizeli 2017-09-27 23:03:04 +02:00
parent 43b5281fd2
commit adb527f445
3 changed files with 45 additions and 170 deletions

View file

@ -1,8 +0,0 @@
#!/bin/bash
set -e
for arch in "amd64" "i386" "armhf" "aarch64"
do
./create_homeassistant_generic.sh -a $arch "$@" &
done
wait

View file

@ -1,142 +0,0 @@
#!/bin/bash
set -e
BUILD_CONTAINER_NAME=homeassistant-generic-build-$$
DOCKER_PUSH="true"
DOCKER_CACHE="false"
DOCKER_WITH_LATEST="true"
DOCKER_HUB=homeassistant
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
help () {
cat << EOF
Script for homeassistant base docker build
create_homeassistant_base [options]
Options:
-h, --help
Display this help and exit.
-d, --dockerhub hubname
Set user of dockerhub build.
-v, --version
HomeAssistant branch/tag to build.
-a, --arch
Arch type for HomeAssistant build.
-t, --test
Don't upload the build to docker hub.
EOF
}
# Parse arguments
while [[ $# -gt 0 ]]; do
key=$1
case $key in
-h|--help)
help
exit 0
;;
-d|--dockerhub)
DOCKER_HUB=$2
shift
;;
-v|--version)
DOCKER_TAG=$2
shift
;;
-a|--arch)
ARCH=$2
shift
;;
-t|--test)
DOCKER_PUSH="false"
;;
*)
echo "[WARNING] $0 : Argument '$1' unknown. Ignoring."
;;
esac
shift
done
# Sanity checks
if [ -z "$ARCH" ]; then
echo "[ERROR] please set a arch!"
help
exit 1
fi
if [ -z "$DOCKER_TAG" ]; then
echo "[ERROR] please set a version!"
help
exit 1
fi
# Get the absolute script location
pushd "$(dirname "$0")" > /dev/null 2>&1
SCRIPTPATH=$(pwd)
popd > /dev/null 2>&1
DOCKER_IMAGE="$DOCKER_HUB/${ARCH}-homeassistant"
BASE_IMAGE="homeassistant\/${ARCH}-homeassistant-base:latest"
BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH}
WORKSPACE=$BUILD_DIR/hass-$ARCH
HASS_GIT=$WORKSPACE/homeassistant
# setup docker
echo "[INFO] Setup docker for homeassistant"
mkdir -p "$BUILD_DIR"
mkdir -p "$WORKSPACE"
echo "[INFO] load homeassistant"
cp ../../homeassistant/generic/Dockerfile "$WORKSPACE/Dockerfile"
sed -i "s/%%BASE_IMAGE%%/${BASE_IMAGE}/g" "$WORKSPACE/Dockerfile"
git clone --depth 1 -b "$DOCKER_TAG" https://github.com/home-assistant/home-assistant "$HASS_GIT" > /dev/null 2>&1
DOCKER_TAG="$(python3 "$HASS_GIT/setup.py" -V | sed -e "s:^\(.\...\)\.0$:\1:g" -e "s:^\(.\...\)\.0.dev0$:\1-dev:g")"
if [ -z "$DOCKER_TAG" ]; then
echo "[ERROR] Can't read homeassistant version!"
exit 1
fi
echo "LABEL io.hass.version=\"$DOCKER_TAG\" io.hass.type=\"homeassistant\" io.hass.arch=\"$ARCH\"" >> "$WORKSPACE/Dockerfile"
echo "[INFO] prepare done for $DOCKER_IMAGE:$DOCKER_TAG"
# 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_PUSH=$DOCKER_PUSH \
-e DOCKER_CACHE=$DOCKER_CACHE \
-e DOCKER_WITH_LATEST=$DOCKER_WITH_LATEST \
-e DOCKER_IMAGE="$DOCKER_IMAGE" \
-e DOCKER_TAG="$DOCKER_TAG" \
--name $BUILD_CONTAINER_NAME \
--privileged \
homeassistant/docker-build-env \
/run-docker.sh
echo "[INFO] cleanup WORKSPACE"
cd "$BUILD_DIR"
rm -rf "$WORKSPACE"
cleanup "okay"
exit 0

View file

@ -71,13 +71,15 @@ Options:
Internals:
--addon
Default on. Run all things for a addon build.
--base
Build our base images.
--supervisor
Build a hassio supervisor.
--homeassistant-base
Build a Home-Assistant base image.
--homeassistant-generic
Build the generic release for a Home-Assistant.
--homeassistant
Build the generic release for a Home-Assistant.
--homeassistant-machine
Build the machine based image for a release.
EOF
@ -270,6 +272,18 @@ function build_supervisor() {
}
function build_homeassistant() {
local build_arch=$1
local image="{arch}-homeassistant"
local build_from="homeassistant/${build_arch}-homeassistant-base:latest"
local docker_cli=()
# Start build
run_build "$TARGET" "$DOCKER_HUB" "$image" "$VERSION" \
"homeassistant" "$build_from" "$build_arch" docker_cli[@]
}
#### initialized cross-build ####
function init_crosscompile() {
@ -336,7 +350,7 @@ while [[ $# -gt 0 ]]; do
--no-cache)
DOCKER_CACHE="false"
;;
-d, --docker-hub)
-d|--docker-hub)
DOCKER_HUB=$2
shift
;;
@ -358,17 +372,22 @@ while [[ $# -gt 0 ]]; do
--addon)
BUILD_TYPE="addon"
;;
--base)
BUILD_TYPE="base"
;;
--supervisor)
BUILD_TYPE="supervisor"
;;
--homeassistant-base)
BUILD_TYPE="homeassistant-base"
;;
--homeassistant-generic)
BUILD_TYPE="homeassistant-generic"
;;
--homeassistant)
BUILD_TYPE="homeassistant"
DOCKER_CACHE="false"
;;
--homeassistant-machine)
BUILD_TYPE="homeassistant-machine"
DOCKER_CACHE="false"
;;
*)
@ -390,6 +409,17 @@ if [ "$BUILT_TYPE" != "addon" ] && [ -z "$DOCKER_HUB" ]; then
exit 1
fi
if [ "$BUILT_TYPE" == "homeassistant" ] && [ -z "$VERSION" ]; then
echo "[ERROR] Please set a version for home-assistant!"
exit 1
fi
if [ "$BUILT_TYPE" == "homeassistant-machine" ] && [ -z "$VERSION" ]; then
echo "[ERROR] Please set a version for home-assistant!"
exit 1
fi
#### Main ####
mkdir -p /data
@ -406,22 +436,17 @@ if [ ! -z "$GIT_REPOSITORY" ]; then
fi
# Select addon build
if [ "$BUILD_TYPE" == "addon" ]; then
echo "[INFO] Run addon build for: ${BUILD_LIST[*]}"
for arch in "${BUILD_LIST[@]}"; do
echo "[INFO] Run $BUILD_TYPE build for: ${BUILD_LIST[*]}"
for arch in "${BUILD_LIST[@]}"; do
if [ "$BUILD_TYPE" == "addon" ]; then
(build_addon "$arch") &
BUILD_TASKS+=($!)
done
fi
# Select addon build
if [ "$BUILD_TYPE" == "supervisor" ]; then
echo "[INFO] Run supervisor build for: ${BUILD_LIST[*]}"
for arch in "${BUILD_LIST[@]}"; do
elif [ "$BUILD_TYPE" == "supervisor" ]; then
(build_supervisor "$arch") &
BUILD_TASKS+=($!)
done
fi
elif [ "$BUILD_TYPE" == "homeassistant" ]; then
(build_homeassistant "$arch") &
fi
BUILD_TASKS+=($!)
done
# Wait until all build jobs are done
wait "${BUILD_TASKS[@]}"