mirror of
https://github.com/home-assistant/operating-system.git
synced 2025-12-19 18:08:29 +00:00
Clean up hassio build scripts (#4394)
Extract some of the parts of the "image import" to the script creating the data partition to separate concerns. The Docker data directory is now passed as a daemon option, instead of only mounting the data partition's folder to the default directory, to be closer to the deployment setup. Also trap the exit and error signals to remove the build container and unmount the data partition, as failed or cancelled build have been leaking the containers/mounts when building interactively (attached to the build container shell).
This commit is contained in:
@@ -7,6 +7,9 @@ channel=$3
|
||||
docker_version=$4
|
||||
|
||||
data_img="${dst_dir}/data.ext4"
|
||||
data_dir="${build_dir}/data"
|
||||
|
||||
APPARMOR_URL="https://version.home-assistant.io/apparmor.txt"
|
||||
|
||||
# Make image
|
||||
rm -f "${data_img}"
|
||||
@@ -14,23 +17,28 @@ truncate --size="1280M" "${data_img}"
|
||||
mkfs.ext4 -L "hassos-data" -E lazy_itable_init=0,lazy_journal_init=0 "${data_img}"
|
||||
|
||||
# Mount / init file structs
|
||||
mkdir -p "${build_dir}/data/"
|
||||
sudo mount -o loop,discard "${data_img}" "${build_dir}/data/"
|
||||
mkdir -p "${data_dir}"
|
||||
sudo mount -o loop,discard "${data_img}" "${data_dir}"
|
||||
|
||||
trap 'docker rm -f ${container} > /dev/null; sudo umount ${data_dir} || true' ERR EXIT
|
||||
|
||||
# Use official Docker in Docker images
|
||||
# We use the same version as Buildroot is using to ensure best compatibility
|
||||
container=$(docker run --privileged -e DOCKER_TLS_CERTDIR="" \
|
||||
-v "${build_dir}/data/":/data \
|
||||
-v "${build_dir}/data/docker/":/var/lib/docker \
|
||||
-v "${build_dir}":/build \
|
||||
-d "docker:${docker_version}-dind" --feature containerd-snapshotter)
|
||||
-v "${data_dir}":/mnt/data \
|
||||
-v "${build_dir}":/build \
|
||||
-d "docker:${docker_version}-dind" --feature containerd-snapshotter --data-root /mnt/data/docker)
|
||||
|
||||
docker exec "${container}" sh /build/dind-import-containers.sh "${channel}"
|
||||
|
||||
docker stop "${container}"
|
||||
docker exec "${container}" sh /build/dind-import-containers.sh
|
||||
|
||||
sudo bash -ex <<EOF
|
||||
# Indicator for docker-prepare.service to use the containerd snapshotter
|
||||
sudo touch "${build_dir}/data/.docker-use-containerd-snapshotter"
|
||||
touch "${data_dir}/.docker-use-containerd-snapshotter"
|
||||
|
||||
# Unmount data image
|
||||
sudo umount "${build_dir}/data/"
|
||||
# Setup AppArmor
|
||||
mkdir -p "${data_dir}/supervisor/apparmor"
|
||||
curl -fsL -o "${data_dir}/supervisor/apparmor/hassio-supervisor" "${APPARMOR_URL}"
|
||||
|
||||
# Persist build-time updater channel
|
||||
jq -n --arg channel "${channel}" '{"channel": \$channel}' > "${data_dir}/supervisor/updater.json"
|
||||
EOF
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
channel=$1
|
||||
|
||||
APPARMOR_URL="https://version.home-assistant.io/apparmor.txt"
|
||||
|
||||
# Make sure we can talk to the Docker daemon
|
||||
echo "Waiting for Docker daemon..."
|
||||
while ! docker version 2> /dev/null > /dev/null; do
|
||||
@@ -25,9 +21,3 @@ done
|
||||
supervisor=$(docker images --filter "label=io.hass.type=supervisor" --quiet)
|
||||
arch=$(docker inspect --format '{{ index .Config.Labels "io.hass.arch" }}' "${supervisor}")
|
||||
docker tag "${supervisor}" "ghcr.io/home-assistant/${arch}-hassio-supervisor:latest"
|
||||
|
||||
# Setup AppArmor
|
||||
mkdir -p "/data/supervisor/apparmor"
|
||||
wget -O "/data/supervisor/apparmor/hassio-supervisor" "${APPARMOR_URL}"
|
||||
|
||||
echo "{ \"channel\": \"${channel}\" }" > /data/supervisor/updater.json
|
||||
|
||||
Reference in New Issue
Block a user