build all in docker
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#! /bin/bash -e
|
||||
set -o errtrace
|
||||
|
||||
# build and test everything in a fresh docker installation
|
||||
img="ubuntu:latest"
|
||||
@@ -39,21 +40,21 @@ while test $# -gt 0; do
|
||||
echo " <os>:::<A>"
|
||||
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 " 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 " 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 "EXAMPLE:"
|
||||
echo
|
||||
echo "$0 -i mwaeckerlin/ubuntu:trusty-i386 \\"
|
||||
echo " -t deb \\"
|
||||
echo " -e ANDROID_HOME=/opt/local/android \\"
|
||||
echo " -d /opt/local/android \\"
|
||||
echo " -r universe \\"
|
||||
echo " -r https://dev.marc.waeckerlin.org/repository \\"
|
||||
echo " -k https://dev.marc.waeckerlin.org/repository/PublicKey \\"
|
||||
echo " -p mrw-c++"
|
||||
echo " -t deb \\"
|
||||
echo " -e ANDROID_HOME=/opt/local/android \\"
|
||||
echo " -d /opt/local/android \\"
|
||||
echo " -r universe \\"
|
||||
echo " -r https://dev.marc.waeckerlin.org/repository \\"
|
||||
echo " -k https://dev.marc.waeckerlin.org/repository/PublicKey \\"
|
||||
echo " -p mrw-c++"
|
||||
echo
|
||||
exit 0
|
||||
;;
|
||||
@@ -93,6 +94,38 @@ while test $# -gt 0; do
|
||||
shift
|
||||
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() {
|
||||
arg="$1"
|
||||
shift
|
||||
@@ -103,24 +136,29 @@ function ifthenelse() {
|
||||
os="${arg%%:::*}"
|
||||
thenpart="${arg#*:::}"
|
||||
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
|
||||
elsepart="${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
|
||||
}
|
||||
|
||||
set -x
|
||||
|
||||
docker pull $img
|
||||
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 upgrade -y --force-yes
|
||||
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 --force-yes software-properties-common apt-transport-https dpkg-dev lsb-release
|
||||
fi
|
||||
docker exec ${DOCKER_ID} apt-get upgrade -y
|
||||
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 software-properties-common apt-transport-https dpkg-dev lsb-release || \
|
||||
docker exec ${DOCKER_ID} apt-get install -y python-software-properties apt-transport-https dpkg-dev lsb-release;
|
||||
for repo in "${repos[@]}"; do
|
||||
ifthenelse "${repo}" "apt-add-repository ARG"
|
||||
done
|
||||
|
Reference in New Issue
Block a user