mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 12:46:32 +00:00
Add cross-compile docker build env.
This commit is contained in:
parent
dd21da2e75
commit
4a8c9c0ac7
@ -2,6 +2,11 @@
|
||||
|
||||
You need a linux with [AUFS](https://docs.docker.com/engine/userguide/storagedriver/aufs-driver/) and docker support. You need to have the build user in docker group for he can run docker. It is not possible to run this process as root! You need also install `jq`
|
||||
|
||||
## Build env
|
||||
|
||||
- yocto-build-env: Allow us to build yocto resinos images
|
||||
- docker-build-env: Allow us to build docker image for all archs
|
||||
|
||||
## Create a server
|
||||
|
||||
First install ubuntu server 16.04.
|
||||
|
29
build-scripts/docker-build-env/Dockerfile
Normal file
29
build-scripts/docker-build-env/Dockerfile
Normal file
@ -0,0 +1,29 @@
|
||||
FROM ubuntu:16.04
|
||||
|
||||
RUN locale-gen en_US.UTF-8
|
||||
ENV LANG en_US.UTF-8
|
||||
|
||||
# Install docker
|
||||
# https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository
|
||||
RUN apt-get update && apt-get install -y \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
software-properties-common \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
VOLUME /var/lib/docker
|
||||
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
RUN apt-get update && apt-get install -y docker-ce && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# setup arm binary support
|
||||
RUN apt-get update && apt-get install -y \
|
||||
qemu-user-static \
|
||||
binfmt-support \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
RUN mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc \
|
||||
&& update-binfmts --enable qemu-arm
|
||||
|
||||
COPY run-docker.sh
|
||||
|
||||
WORKDIR /docker
|
31
build-scripts/docker-build-env/create_build_env.sh
Normal file
31
build-scripts/docker-build-env/create_build_env.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ev
|
||||
|
||||
DOCKER_REPO=pvizeli
|
||||
DOCKER_IMAGE=docker-build-env
|
||||
|
||||
# Get the absolute script location
|
||||
pushd `dirname $0` > /dev/null 2>&1
|
||||
SCRIPTPATH=`pwd`
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
# Sanity checks
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: create_build_env.sh [<REVISION> | NONE]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REVISION=$1
|
||||
|
||||
# Build
|
||||
docker build --pull --tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${REVISION} -f ${SCRIPTPATH}/Dockerfile ${SCRIPTPATH}
|
||||
|
||||
# Tag
|
||||
docker tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${REVISION} ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
|
||||
|
||||
if [ ${REVISION} != "NONE" ]; then
|
||||
# push
|
||||
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:${REVISION}
|
||||
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
|
||||
fi
|
59
build-scripts/docker-build-env/run-docker.sh
Normal file
59
build-scripts/docker-build-env/run-docker.sh
Normal file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DOCKER_TIMEOUT=20 # Wait 20 seconds for docker to start
|
||||
|
||||
cleanup() {
|
||||
echo "[INFO] Running cleanup..."
|
||||
|
||||
# Stop docker gracefully
|
||||
echo "[INFO] Stopping in container docker..."
|
||||
DOCKERPIDFILE=/var/run/docker.pid
|
||||
if [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; then
|
||||
kill $(cat $DOCKERPIDFILE)
|
||||
# Now wait for it to die
|
||||
STARTTIME=$(date +%s)
|
||||
ENDTIME=$(date +%s)
|
||||
while [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; do
|
||||
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
|
||||
sleep 1
|
||||
ENDTIME=$(date +%s)
|
||||
else
|
||||
echo "[ERROR] Timeout while waiting for in container docker to die."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "[WARN] Can't stop docker container."
|
||||
echo "[WARN] Your host might have been left with unreleased resources (ex. loop devices)."
|
||||
fi
|
||||
|
||||
if [ "$1" == "fail" ]; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
trap 'cleanup fail' SIGINT SIGTERM
|
||||
|
||||
# Start docker
|
||||
echo "[INFO] Starting docker."
|
||||
dockerd 2> /dev/null &
|
||||
echo "[INFO] 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 "[ERROR] Timeout while waiting for docker to come up."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "[INFO] Docker was initialized."
|
||||
|
||||
# Start barys with all the arguments requested
|
||||
echo "[INFO] Running build..."
|
||||
|
||||
cleanup
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user