Add cross-compile docker build env.

This commit is contained in:
pvizeli
2017-03-15 10:48:32 +01:00
parent dd21da2e75
commit 4a8c9c0ac7
4 changed files with 124 additions and 0 deletions

View 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

View 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

View 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