git » chasquid » commit d0c7c3d

tests: Reorder Dockerfile statements to allow caching

author Alberto Bertogli
2018-10-21 17:41:23 UTC
committer Alberto Bertogli
2018-11-30 10:03:48 UTC
parent 4ecc5461d3542f041967bd4fc9053d3054b5a181

tests: Reorder Dockerfile statements to allow caching

Docker creates intermediate layers on each command (for most commands),
but the COPY was invalidating them too early, every time it runs it was
generating a different layer.

This patch moves the COPY down to the bottom, and adds a bit more
organization to the commands below.

test/Dockerfile +16 -15

diff --git a/test/Dockerfile b/test/Dockerfile
index 146f0aa..6966aeb 100644
--- a/test/Dockerfile
+++ b/test/Dockerfile
@@ -12,40 +12,41 @@
 FROM golang:latest
 
 WORKDIR /go/src/blitiri.com.ar/go/chasquid
-COPY . .
 
 # Make debconf/frontend non-interactive, to avoid distracting output about the
 # lack of $TERM.
 ENV DEBIAN_FRONTEND noninteractive
 
-# Install the basics for the integration tests.
 RUN apt-get update -q
-RUN apt-get install -y -q python3 msmtp
 
-# Packages for the (optional) dovecot integration test.
-RUN apt-get install -y -q gettext-base dovecot-imapd
+# Install the required packages for the integration tests.
+RUN apt-get install -y -q python3 msmtp
 
-# Packages for the (optional) exim integration test.
-RUN apt-get install -y -q exim4-daemon-light
-RUN cd test/t-02-exim && mkdir -p .exim4 && ln -s /usr/sbin/exim4 .exim4/
+# Install the optional packages for the integration tests.
+RUN apt-get install -y -q \
+	gettext-base dovecot-imapd \
+	exim4-daemon-light \
+	dnsmasq
 
-# Packages for the (optional) TLS tracking test.
-RUN apt-get install -y -q dnsmasq
+# Prepare exim.
+RUN mkdir -p test/t-02-exim/.exim4 \
+	&& ln -s /usr/sbin/exim4 test/t-02-exim/.exim4
 
-# Packages for the (optional) DKIM integration test.
+# Install binaries for the (optional) DKIM integration test.
 RUN go get github.com/driusan/dkim/... \
 	&& go install github.com/driusan/dkim/cmd/dkimsign \
 	&& go install github.com/driusan/dkim/cmd/dkimverify \
 	&& go install github.com/driusan/dkim/cmd/dkimkeygen
 
+# Copy into the container. Everything below this line will not be cached.
+COPY . .
+
 # Install chasquid and its dependencies.
-RUN go get -d -v ./...
-RUN go install -v ./...
+RUN go get -d -v ./... && go install -v ./...
 
 # 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
-RUN chown -R chasquid:chasquid .
+RUN useradd -m chasquid && chown -R chasquid:chasquid .
 USER chasquid
 
 # Tests expect the $USER variable set.