build all in docker

master
Marc Wäckerlin 9 years ago
parent 4c467c73a2
commit daf8df2051
  1. 70
      scripts/build-in-docker.sh

@ -1,4 +1,5 @@
#! /bin/bash -e #! /bin/bash -e
set -o errtrace
# build and test everything in a fresh docker installation # build and test everything in a fresh docker installation
img="ubuntu:latest" img="ubuntu:latest"
@ -39,21 +40,21 @@ while test $# -gt 0; do
echo " <os>:::<A>" echo " <os>:::<A>"
echo " Read as: On linux type <os> use <A> else use <B>" echo " Read as: On linux type <os> use <A> else use <B>"
echo " That means: If the distributer ID or codename in lsb_release" echo " That means: If the distributer ID or codename in lsb_release"
echo " matches <os>, then <A> is replaced, else <B> is replaced." echo " matches regular expression <os>, then <A> is replaced, else <B> is replaced."
echo " The three colons are for splitting <os> from <A> and <B> part." echo " The three colons are for splitting <os> from <A> and <B> part."
echo " E.g.: Install package curl on wheezy and npm on olter systems:" echo " E.g.: Install package curl on wheezy and npm on olter systems:"
echo " $0 -p wheezy:::curl:::npm" echo " $0 -p Debian|precise:::curl:::npm"
echo echo
echo "EXAMPLE:" echo "EXAMPLE:"
echo echo
echo "$0 -i mwaeckerlin/ubuntu:trusty-i386 \\" echo "$0 -i mwaeckerlin/ubuntu:trusty-i386 \\"
echo " -t deb \\" echo " -t deb \\"
echo " -e ANDROID_HOME=/opt/local/android \\" echo " -e ANDROID_HOME=/opt/local/android \\"
echo " -d /opt/local/android \\" echo " -d /opt/local/android \\"
echo " -r universe \\" echo " -r universe \\"
echo " -r https://dev.marc.waeckerlin.org/repository \\" echo " -r https://dev.marc.waeckerlin.org/repository \\"
echo " -k https://dev.marc.waeckerlin.org/repository/PublicKey \\" echo " -k https://dev.marc.waeckerlin.org/repository/PublicKey \\"
echo " -p mrw-c++" echo " -p mrw-c++"
echo echo
exit 0 exit 0
;; ;;
@ -93,6 +94,38 @@ while test $# -gt 0; do
shift shift
done done
function traperror() {
set +x
local DOCKER_ID="$1"
local err=($2) # error status
local line="$3" # LINENO
local linecallfunc="$4"
local command="$5"
local funcstack="$6"
for e in ${err[@]}; do
if test -n "$e" -a "$e" != "0"; then
echo "<---"
echo "ERROR: line $line - command '$command' exited with status: $e (${err[@]})"
if [ "${funcstack}" != "main" -o "$linecallfunc" != "0" ]; then
echo -n " ... Error at ${funcstack} "
if [ "$linecallfunc" != "" ]; then
echo -n "called at line $linecallfunc"
fi
echo
fi
echo "**** Entering docker container ${DOCKER_ID}, exit with Ctrl-D"
echo -n " ... cleanup docker: "
docker rm -f "${DOCKER_ID}"
echo "returning status: $e"
echo "--->"
exit $e
fi
done
echo -n " SUCCESS ... cleanup docker: "
docker rm -f "${DOCKER_ID}"
exit 0
}
function ifthenelse() { function ifthenelse() {
arg="$1" arg="$1"
shift shift
@ -103,24 +136,29 @@ function ifthenelse() {
os="${arg%%:::*}" os="${arg%%:::*}"
thenpart="${arg#*:::}" thenpart="${arg#*:::}"
if test "${thenpart/:::/}" = "${thenpart}"; then if test "${thenpart/:::/}" = "${thenpart}"; then
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if test "${os//$(lsb_release -is)/}${os//$(lsb_release -cs)/}" != "${os}${os}"; then '"${cmd//ARG/${thenpart}}"'; fi' docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)" =~ ${os} ]]; then '"${cmd//ARG/${thenpart}}"'; fi'
else else
elsepart="${thenpart##*:::}" elsepart="${thenpart##*:::}"
thenpart="${thenpart%:::*}" thenpart="${thenpart%:::*}"
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if test "${os//$(lsb_release -is)/}${os//$(lsb_release -cs)/}" != "${os}${os}"; then '"${cmd//ARG/${thenpart}}"'; else '"${cmd//ARG/${elsepart}}"'; fi' if test -n "${thenpart}"; then
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)" =~ ${os} ]]; then '"${cmd//ARG/${thenpart}}"'; else '"${cmd//ARG/${elsepart}}"'; fi'
else
docker exec ${DOCKER_ID} bash -c 'os="'$os'"; if [[ "$(lsb_release -is)-$(lsb_release -cs)" =~ ${os} ]]; then true; else '"${cmd//ARG/${elsepart}}"'; fi'
fi
fi fi
fi fi
} }
set -x set -x
docker pull $img
DOCKER_ID=$(docker run -d ${dirs[@]} ${envs[@]} -w /workdir $img sleep infinity) DOCKER_ID=$(docker run -d ${dirs[@]} ${envs[@]} -w /workdir $img sleep infinity)
trap "docker rm -f ${DOCKER_ID}" INT TERM EXIT trap 'traperror '"${DOCKER_ID}"' "$? ${PIPESTATUS[@]}" $LINENO $BASH_LINENO "$BASH_COMMAND" "${FUNCNAME[@]}" "${FUNCTION}"' SIGINT INT TERM EXIT
docker exec ${DOCKER_ID} apt-get update docker exec ${DOCKER_ID} apt-get update
docker exec ${DOCKER_ID} apt-get upgrade -y --force-yes docker exec ${DOCKER_ID} apt-get upgrade -y
if ! docker exec ${DOCKER_ID} apt-get install -y --force-yes python-software-properties apt-transport-https dpkg-dev lsb-release; then docker exec ${DOCKER_ID} apt-get install -y python-software-properties software-properties-common apt-transport-https dpkg-dev lsb-release || \
docker exec ${DOCKER_ID} apt-get install -y --force-yes software-properties-common apt-transport-https dpkg-dev lsb-release docker exec ${DOCKER_ID} apt-get install -y software-properties-common apt-transport-https dpkg-dev lsb-release || \
fi docker exec ${DOCKER_ID} apt-get install -y python-software-properties apt-transport-https dpkg-dev lsb-release;
for repo in "${repos[@]}"; do for repo in "${repos[@]}"; do
ifthenelse "${repo}" "apt-add-repository ARG" ifthenelse "${repo}" "apt-add-repository ARG"
done done

Loading…
Cancel
Save