THRIFT-3907 Skip Docker image build on CI when unchanged
diff --git a/build/docker/centos/Dockerfile b/build/docker/centos/Dockerfile
index a31492b..59bbfd6 100644
--- a/build/docker/centos/Dockerfile
+++ b/build/docker/centos/Dockerfile
@@ -138,5 +138,5 @@
 
 ENV THRIFT_ROOT /thrift
 RUN mkdir -p $THRIFT_ROOT/src
-COPY scripts $THRIFT_ROOT
+COPY Dockerfile $THRIFT_ROOT/
 WORKDIR $THRIFT_ROOT/src
diff --git a/build/docker/centos/scripts/keepit b/build/docker/centos/scripts/keepit
deleted file mode 100644
index cb885df..0000000
--- a/build/docker/centos/scripts/keepit
+++ /dev/null
@@ -1 +0,0 @@
-keep it
diff --git a/build/docker/centos6/Dockerfile b/build/docker/centos6/Dockerfile
index 4df75de..aa19731 100644
--- a/build/docker/centos6/Dockerfile
+++ b/build/docker/centos6/Dockerfile
@@ -50,5 +50,5 @@
 
 ENV THRIFT_ROOT /thrift
 RUN mkdir -p $THRIFT_ROOT/src
-COPY scripts $THRIFT_ROOT
+COPY Dockerfile $THRIFT_ROOT/
 WORKDIR $THRIFT_ROOT/src
diff --git a/build/docker/centos6/scripts/keepit b/build/docker/centos6/scripts/keepit
deleted file mode 100644
index cb885df..0000000
--- a/build/docker/centos6/scripts/keepit
+++ /dev/null
@@ -1 +0,0 @@
-keep it
diff --git a/build/docker/check_unmodified.sh b/build/docker/check_unmodified.sh
new file mode 100755
index 0000000..564e4c1
--- /dev/null
+++ b/build/docker/check_unmodified.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Download prebuilt docker image and compare Dockerfile hash values
+
+set -ex
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+DISTRO=$1
+SRC_IMG=thrift/thrift-build:$DISTRO
+
+function try_pull {
+  docker pull $SRC_IMG
+  cd ${SCRIPT_DIR}/$DISTRO
+  docker run $SRC_IMG bash -c 'cd .. && sha512sum Dockerfile' > .Dockerfile.sha512
+  sha512sum -c .Dockerfile.sha512
+}
+
+if try_pull; then
+  echo Dockerfile seems identical. No need to rebuild from scratch.
+else
+  echo Either Dockerfile has changed or pull failure. Need to build brand new one.
+  exit 1
+fi
diff --git a/build/docker/debian/Dockerfile b/build/docker/debian/Dockerfile
index 285c85b..99eda7a 100644
--- a/build/docker/debian/Dockerfile
+++ b/build/docker/debian/Dockerfile
@@ -186,5 +186,5 @@
 
 ENV THRIFT_ROOT /thrift
 RUN mkdir -p $THRIFT_ROOT/src
-COPY scripts $THRIFT_ROOT
+COPY Dockerfile $THRIFT_ROOT/
 WORKDIR $THRIFT_ROOT/src
diff --git a/build/docker/debian/scripts/dpkg.sh b/build/docker/scripts/dpkg.sh
similarity index 100%
rename from build/docker/debian/scripts/dpkg.sh
rename to build/docker/scripts/dpkg.sh
diff --git a/build/docker/ubuntu/Dockerfile b/build/docker/ubuntu/Dockerfile
index 2797a1c..7792aae 100644
--- a/build/docker/ubuntu/Dockerfile
+++ b/build/docker/ubuntu/Dockerfile
@@ -204,5 +204,5 @@
 
 ENV THRIFT_ROOT /thrift
 RUN mkdir -p $THRIFT_ROOT/src
-COPY scripts $THRIFT_ROOT
+COPY Dockerfile $THRIFT_ROOT/
 WORKDIR $THRIFT_ROOT/src
diff --git a/build/docker/ubuntu/scripts/dpkg.sh b/build/docker/ubuntu/scripts/dpkg.sh
deleted file mode 100755
index 3ba0cd4..0000000
--- a/build/docker/ubuntu/scripts/dpkg.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-set -ev
-
-dpkg-buildpackage -tc -us -uc
-ls -al ..