about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2019-03-17 19:39:00 +0800
committerkennytm <kennytm@gmail.com>2019-03-17 23:19:17 +0800
commit07aee1df4427bcc2be5e9f6be5c853a0f6987b40 (patch)
tree05ddc405f6076d3d6192ea81de0042fc65e893c9
parent7cf074a1e655ac07d04d045667278fa1a9970b93 (diff)
downloadrust-07aee1df4427bcc2be5e9f6be5c853a0f6987b40.tar.gz
rust-07aee1df4427bcc2be5e9f6be5c853a0f6987b40.zip
Calculate Docker cache hash precisely from Dockerfile's dependencies
`src/ci/docker`, so that when files under `dist-x86_64-linux` is changed,
its dependent image `dist-i686-linux` will also be rebuilt.

However, this ultraconservative solution caused the `dist-i686-linux` to
be rebuilt every time an irrelevant Dockerfile (e.g. the PowerPC ones) is
changed, which increases the building time beyond 3 hours and forcing
a spurious but expected failure.

This commit instead parses the Dockerfile itself and look for the actual
dependencies. The scripts needs to be copied into the Docker image, which
must be done with the COPY command, so we just need to find all lines with
a COPY command and add the source file into the hash calculator.

Note: this script only handles single-lined COPY command in the form
`COPY src1 src2 src3 dst`, since these are the only variant used inside
this repository.
-rwxr-xr-xsrc/ci/docker/run.sh13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh
index b4426bbfb96..ef151750af9 100755
--- a/src/ci/docker/run.sh
+++ b/src/ci/docker/run.sh
@@ -22,7 +22,18 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
       hash_key=/tmp/.docker-hash-key.txt
       rm -f "${hash_key}"
       echo $image >> $hash_key
-      find $docker_dir -type f | sort | xargs cat >> $hash_key
+
+      cat "$docker_dir/$image/Dockerfile" >> $hash_key
+      # Look for all source files involves in the COPY command
+      copied_files=/tmp/.docker-copied-files.txt
+      rm -f "$copied_files"
+      for i in $(sed -n -e 's/^COPY \(.*\) .*$/\1/p' "$docker_dir/$image/Dockerfile"); do
+        # List the file names
+        find "$docker_dir/$i" -type f >> $copied_files
+      done
+      # Sort the file names and cat the content into the hash key
+      sort $copied_files | xargs cat >> $hash_key
+
       docker --version >> $hash_key
       cksum=$(sha512sum $hash_key | \
         awk '{print $1}')