--- /dev/null
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id E26906DE01D0\r
+ for <notmuch@notmuchmail.org>; Tue, 16 Aug 2016 14:15:22 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.229\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.229 tagged_above=-999 required=5 tests=[AWL=0.238, \r
+ HEADER_FROM_DIFFERENT_DOMAINS=0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 53uTBg0t8v8G for <notmuch@notmuchmail.org>;\r
+ Tue, 16 Aug 2016 14:15:21 -0700 (PDT)\r
+X-Greylist: delayed 424 seconds by postgrey-1.35 at arlo;\r
+ Tue, 16 Aug 2016 14:15:21 PDT\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 127A06DE0134\r
+ for <notmuch@notmuchmail.org>; Tue, 16 Aug 2016 14:15:21 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id B063C1000B3; Wed, 17 Aug 2016 00:07:52 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Cc: tomi.ollila@iki.fi\r
+Subject: [RFC PATCH] test: add devel/test-in-docker.sh\r
+Date: Wed, 17 Aug 2016 00:07:51 +0300\r
+Message-Id: <1471381671-21134-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 2.8.2\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.22\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 16 Aug 2016 21:15:23 -0000\r
+\r
+With this user can try and test notmuch in docker container,\r
+in fixed environment where it should compile and tests should pass...\r
+\r
+Currently provided container environments are Debian 8.5 and\r
+Ubuntu 16.04 based. Host OS could be any Linux environment with\r
+modern enough docker; Perhaps this works on macOS (with docker 1.12+)\r
+too (in Windows this script probably fails).\r
+---\r
+\r
+Currently quite a few tests FAIL -- due to missing prerequisite tests.\r
+It would be easy to add some packages, like gdb, emacs(-nox), dtach,\r
+but I left those out just to tease you >;)\r
+\r
+ devel/test-in-docker.sh | 193 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 193 insertions(+)\r
+ create mode 100755 devel/test-in-docker.sh\r
+\r
+diff --git a/devel/test-in-docker.sh b/devel/test-in-docker.sh\r
+new file mode 100755\r
+index 000000000000..f9537c177ad9\r
+--- /dev/null\r
++++ b/devel/test-in-docker.sh\r
+@@ -0,0 +1,193 @@\r
++#!/bin/sh\r
++# -*- mode: shell-script; sh-basic-offset: 8; tab-width: 8 -*-\r
++\r
++case ${BASH_VERSION-} in *.*) PATH=/ shopt -s xpg_echo; esac\r
++case ${ZSH_VERSION-} in *.*) PATH=/ emulate ksh; esac\r
++\r
++set -u # expanding unset variable makes non-interactive shell exit immediately\r
++set -f # disable pathname expansion by default -- makes e.g. eval more robust\r
++set -e # exit on error -- know potential false negatives and positives !\r
++#et -x # s/#/s/ may help debugging (or run /bin/sh -x ... on command line)\r
++\r
++LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8; export LANG LC_ALL\r
++\r
++#PATH='/sbin:/usr/sbin:/bin:/usr/bin'; export PATH\r
++\r
++# XXX If bash finds *this* script by searching PATH...\r
++case $0 in */*) ;; *)\r
++ echo "'$0' does not contain '/'s. try './$0'" >&2; exit 1\r
++esac\r
++\r
++saved_IFS=$IFS; readonly saved_IFS\r
++\r
++warn () { for l; do echo "$l"; done; } >&2\r
++die () { for l; do echo "$l"; done; exit 1; } >&2\r
++\r
++x () { echo + "$@" >&2; "$@"; }\r
++x_env () { echo + "$@" >&2; env "$@"; }\r
++x_eval () { echo + "$*" >&2; eval "$*"; }\r
++x_exec () { echo + "$@" >&2; exec "$@"; die "exec '$*' failed"; }\r
++\r
++test $# -gt 0 || {\r
++ exec >&2; echo\r
++ echo Usage: $0 '(debian8|ubuntu1604)'\r
++ echo\r
++ echo After everything set up a user shell to the given container\r
++ echo is started "(cwd='$HOME'; X11 should work)."\r
++ echo\r
++ echo If container is already running, new shell is started.\r
++ echo If container exists but is not running it is restarted.\r
++ echo If image exists but no container, new container is created.\r
++ echo If image does not exist. It is built.\r
++ echo Build files are stored in /root/.docker-setup/ in the container.\r
++ echo\r
++ exit 1\r
++}\r
++\r
++case $1\r
++in debian|debian8)\r
++ shift; set debian8 "$@"\r
++ name='debian8-notmuch'\r
++;; ubuntu|ubuntu16|ubuntu1604)\r
++ shift; set ubuntu1604 "$@"\r
++ name='ubuntu1604-notmuch'\r
++;; *)\r
++ die "'$1': unsupported container name"\r
++esac\r
++\r
++if status=`exec docker inspect -f '{{.State.Status}}' $name 2>&1`\r
++then\r
++ if test "$status" = running\r
++ then x_exec docker exec -it "$name" /bin/bash --login\r
++ else x_exec docker start -i "$name"\r
++ fi\r
++fi\r
++\r
++run ()\r
++{\r
++ test -d /tmp/.X11-unix &&\r
++ xv='-v /tmp/.X11-unix:/tmp/.X11-unix:ro' || xv=\r
++\r
++ x_exec docker run -it -e DISPLAY -e _USER="$USER" --name "$name" \\r
++ -h "$name" -v $HOME:/home/$USER ${v:+-v "$v"} --ipc=host "$name"\r
++}\r
++\r
++case $status in *parsing*error*.State.Status*) run; esac\r
++\r
++# Here if above docker inspect -f '{{.State.Status}}' did not match above, but\r
++# Error: No such image or container: ...\r
++\r
++case $1\r
++in debian8)\r
++ FROM_HASH=1b01529cc499d51767c62f9fc8083043610546b4e050898809ec54e00dbb1a34\r
++ FROM_REF=debian:8.5\r
++;; ubuntu1604)\r
++ FROM_HASH=42118e3df429f09ca581a9deb3df274601930e428e452f7e4e9f1833c56a100a\r
++ FROM_REF=ubuntu:16.04\r
++esac\r
++\r
++TRUNC_HASH=${FROM_HASH%????????????????????????????????????????????????????}\r
++\r
++rmtmps () { rm -rf _docker_wip; trap - 0; }\r
++rmtmps\r
++mkdir _docker_wip\r
++\r
++# outcomment next line when debugging build\r
++trap rmtmps 0 INT HUP TERM\r
++exec 3>&1 > _docker_wip/Dockerfile.gen\r
++\r
++cat <<EOF\r
++\r
++# Ensure that FROM_REF & FROM_HASH are in sync; hash wins if not...\r
++#FROM $FROM_REF (is $TRUNC_HASH...)\r
++FROM $FROM_HASH\r
++\r
++# Note: The result of docker build with this Dockerfile is not entirely\r
++# reproducable as packages installed from remote sources may get\r
++# updated...\r
++\r
++ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8\r
++\r
++EOF\r
++\r
++case $1 in debian*|ubuntu*)\r
++\r
++cat <<'EOF'\r
++# Set locale in a way that is both ubuntu and debian compatible\r
++RUN set -xeu \\r
++ && export DEBIAN_FRONTEND=noninteractive \\r
++ && apt-get update && apt-get install -y -q locales \\r
++ && if test -f /etc/locale.gen; then \\r
++ sed -i '/en_US.UTF-8/ s/^. *//' /etc/locale.gen; fi \\r
++ && locale-gen en_US.UTF-8 \\r
++ && echo 'LANG="en_US.UTF-8"' > /etc/default/locale \\r
++ && apt-get install -y -q build-essential git libxapian-dev libgmime-2.6-dev libtalloc-dev zlib1g-dev \\r
++ && apt-get -y autoremove && apt-get -y clean # rm -rf /var/lib/apt/lists/\r
++\r
++EOF\r
++\r
++esac\r
++\r
++# all containers (more may be added...)\r
++\r
++cat <<'EOF'\r
++RUN set -xeu \\r
++ && chmod 755 /root \\r
++ && exec 3>&1 >>/root/.bash_profile && echo \\r
++ && echo 'test ! -f /root/.docker-setup/bash-as-user.sh ||' \\r
++ && echo ' . /root/.docker-setup/bash-as-user.sh' \\r
++ && exec >>/etc/bash.bashrc && echo \\r
++ && echo '# emulate zsh printexitvalue (written from Dockerfile)' \\r
++ && echo 'trap '\''echo -n bash: exit $? \\ \\ ; fc -nl -1 -1'\'' ERR' \\r
++ && exec 1>&3 3>&- \\r
++ && umask 077 \\r
++ && mkdir -p /etc/sudoers.d \\r
++ && echo '%root ALL= NOPASSWD: ALL' >/etc/sudoers.d/55-wheel-allmighty\r
++\r
++ADD bash-as-user.sh Dockerfile.gen /root/.docker-setup/\r
++\r
++CMD ["/bin/bash", "--login" ]\r
++\r
++EOF\r
++\r
++exec >&3 3>&-\r
++\r
++cat >_docker_wip/bash-as-user.sh <<'EOF'\r
++# This file is supposed to be loaded from /root/.bash_profile\r
++# when bash is started as login shell (-l or --login).\r
++\r
++user=${_USER-}\r
++unset _USER\r
++\r
++if test "$user" && test -d /home/"$user"\r
++then\r
++ case $user in *[!-a-z0-9_]*) exit 1; esac\r
++ grep -q "^$user:" /etc/passwd || {\r
++ duid=`exec stat -c %u /home/"$user"`\r
++ useradd -d /home/"$user" -M -u $duid -U -G 0 -s /bin/bash \\r
++ -c "user $user" "$user" 2>/dev/null || :\r
++ }\r
++fi\r
++\r
++# Simple change user which may work as well as gosu(1) if not (better).\r
++test -z "$user" || exec perl -e '\r
++ my @user = getpwnam $ARGV[0];\r
++ chdir $user[7];\r
++ $ENV{HOME} = $user[7];\r
++ $ENV{USER} = $ARGV[0];\r
++ $( = $) = "$user[3] $user[3] 0";\r
++ $< = $> = $user[2]; die "setting uids: $!\n" if $!;\r
++ exec qw"/bin/bash --login";' "$user"\r
++unset user\r
++EOF\r
++\r
++( cd _docker_wip\r
++ # TIME is used by (GNU) /usr/bin/time (TIMEFORMAT by bash builtin)\r
++ export TIME='%Us user, %Ss system, %P cpu, %E total (max resident mem %Mk)'\r
++ export SHELL=/bin/sh\r
++ x command time docker build -f Dockerfile.gen -t $name .\r
++ x_exec docker history $name )\r
++\r
++rmtmps\r
++# run() does exec; auto-eliminating traps\r
++run\r
+-- \r
+2.8.2\r
+\r