author | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-11-29 00:31:48 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-11-30 10:03:48 UTC |
parent | 57f5a099017888b21cfd3703974af5cf5b7c05ea |
test/Dockerfile | +8 | -2 |
test/util/docker_entrypoint.sh | +46 | -0 |
diff --git a/test/Dockerfile b/test/Dockerfile index 128f05c..a413e87 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -27,6 +27,9 @@ RUN apt-get install -y -q \ gettext-base dovecot-imapd \ exim4-daemon-light +# Install sudo, needed for the docker entrypoint. +RUN apt-get install -y -q sudo + # Prepare exim. RUN mkdir -p test/t-02-exim/.exim4 \ && ln -s /usr/sbin/exim4 test/t-02-exim/.exim4 @@ -43,10 +46,13 @@ COPY . . # Install chasquid and its dependencies. RUN go get -d -v ./... && go install -v ./... +# Custom entry point, which uses our own DNS server. +ENTRYPOINT ["./test/util/docker_entrypoint.sh"] + # Don't run the tests as root: it makes some integration tests more difficult, # as for example Exim has hard-coded protections against running as root. RUN useradd -m chasquid && chown -R chasquid:chasquid . -USER chasquid +#USER chasquid # Tests expect the $USER variable set. -ENV USER chasquid +#ENV USER chasquid diff --git a/test/util/docker_entrypoint.sh b/test/util/docker_entrypoint.sh new file mode 100755 index 0000000..578d895 --- /dev/null +++ b/test/util/docker_entrypoint.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# Script that is used as a Docker entrypoint. +# +# It starts minidns with a zone resolving "localhost", and overrides +# /etc/resolv.conf to use it. Then launches docker CMD. +# +# This is used for more hermetic Docker test environments. + +set -e +. $(dirname ${0})/../util/lib.sh + +init + +# Go to the root of the repository. +cd ../.. + +# Undo the EXIT trap, so minidns continues to run in the background. +trap - EXIT + +set -v + +go build -o /tmp/minidns "${UTILDIR}/minidns.go" + +# The DNS server resolves only "localhost"; tests will rely on this, as we +# $HOSTALIASES to point our test hostnames to localhost, so it needs to +# resolve. +echo " +localhost A 127.0.0.1 +localhost AAAA ::1 +" > /tmp/zones + +start-stop-daemon --start --background \ + --exec /tmp/minidns \ + -- --zones=/tmp/zones + +echo "nameserver 127.0.0.1" > /etc/resolv.conf +echo "nameserver ::1" >> /etc/resolv.conf + +# Launch arguments, which come from docker CMD, as "chasquid" user. +# Running tests as root makes some integration tests more difficult, as for +# example Exim has hard-coded protections against running as root. +sudo -u chasquid -g chasquid \ + --set-home \ + --preserve-env PATH=${PATH} \ + -- "$@"