git » chasquid » commit 3aa7bb4

test: Adjust Dockerfile to support modules

author Alberto Bertogli
2019-10-18 22:04:19 UTC
committer Alberto Bertogli
2019-10-19 12:06:26 UTC
parent 80b4f7f8326b68d45932c9cf4dde720b179a52ea

test: Adjust Dockerfile to support modules

When modules are configured, go will now attempt to fetch them on build,
using the proxy.

That causes the integration tests run via Docker to fail, because go
build attempts to contact the proxy within the test environment, which
has the external DNS resolvers disabled.

This patch fixes the problem by adjusting the pre-run fetch to use the
new modules system. We fetch the dependencies to the cache so that when
they're needed within the environment, they are present and there's no
need to use the proxy.

test/Dockerfile +14 -9
test/util/docker_entrypoint.sh +4 -2

diff --git a/test/Dockerfile b/test/Dockerfile
index c01f4a1..24f79c7 100644
--- a/test/Dockerfile
+++ b/test/Dockerfile
@@ -46,16 +46,21 @@ RUN go get github.com/driusan/dkim/... \
 # Copy into the container. Everything below this line will not be cached.
 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
 
-# Tests expect the $USER variable set.
-#ENV USER chasquid
+# Update dependencies to the latest versions, and fetch them to the cache.
+# The fetch is important because once within the entrypoint, we no longer have
+# network access to the outside, so all modules need to be available.
+# Do it as chasquid because that is what the tests will run as.
+USER chasquid
+ENV GOPATH=
+RUN go get -v ./... && go mod download
+
+# Build the minidns server, which will be run from within the entrypoint.
+RUN go build -o /tmp/minidns ./test/util/minidns.go
+USER root
+
+# Custom entry point, which uses our own DNS server.
+ENTRYPOINT ["./test/util/docker_entrypoint.sh"]
diff --git a/test/util/docker_entrypoint.sh b/test/util/docker_entrypoint.sh
index 822267f..451aa77 100755
--- a/test/util/docker_entrypoint.sh
+++ b/test/util/docker_entrypoint.sh
@@ -20,8 +20,6 @@ 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.
@@ -40,6 +38,10 @@ echo "nameserver ::1" >> /etc/resolv.conf
 # Wait until the minidns resolver comes up.
 wait_until_ready 53
 
+# Disable the Go proxy, since now there is no external network access.
+# Modules should be already be made available in the environment.
+export GOPROXY=off
+
 # 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.