[CALCITE-2698] Use Docker Hub hooks to select Avatica version during image build and publish HSQLDB image
diff --git a/.travis.yml b/.travis.yml
index a0c493f..053ef99 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -42,12 +42,12 @@
   - docker pull $IMAGE
 install:
   # Print the Maven version, skip tests and javadoc
-  - $DOCKERRUN $IMAGE mvn -V install -DskipTests -Dmaven.javadoc.skip=true -Djavax.net.ssl.trustStorePassword=changeit -DskipDockerCheck
+  - $DOCKERRUN $IMAGE mvn -V install -DskipTests -Dmaven.javadoc.skip=true -Djavax.net.ssl.trustStorePassword=changeit
 script:
   # Print surefire output to the console instead of files
   # Ensure that IBM JDK and Jetty work together - -Dcom.ibm.jsse2.overrideDefaultTLS=true
   - unset _JAVA_OPTIONS
-  - $DOCKERRUN $IMAGE mvn -Dsurefire.useFile=false -Djavax.net.ssl.trustStorePassword=changeit -Dcom.ibm.jsse2.overrideDefaultTLS=true -DskipDockerCheck verify javadoc:javadoc javadoc:test-javadoc
+  - $DOCKERRUN $IMAGE mvn -Dsurefire.useFile=false -Djavax.net.ssl.trustStorePassword=changeit -Dcom.ibm.jsse2.overrideDefaultTLS=true verify javadoc:javadoc javadoc:test-javadoc
 git:
   depth: 10000
 sudo: required
diff --git a/appveyor.yml b/appveyor.yml
index cd397a2..09d78f8 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -35,9 +35,9 @@
     - JAVA_HOME: C:\Program Files\Java\jdk9
     - JAVA_HOME: C:\Program Files\Java\jdk10        
 build_script:
-  - mvn clean -V install -DskipTests -Dmaven.javadoc.skip=true -Djavax.net.ssl.trustStorePassword=changeit -DskipDockerCheck
+  - mvn clean -V install -DskipTests -Dmaven.javadoc.skip=true -Djavax.net.ssl.trustStorePassword=changeit
 test_script:
-  - mvn -Dsurefire.useFile=false -Djavax.net.ssl.trustStorePassword=changeit verify javadoc:javadoc javadoc:test-javadoc -DskipDockerCheck
+  - mvn -Dsurefire.useFile=false -Djavax.net.ssl.trustStorePassword=changeit verify javadoc:javadoc javadoc:test-javadoc
 cache:
   - C:\maven\
   - C:\Users\appveyor\.m2
diff --git a/docker.sh b/docker.sh
index 56e8f2c..c66fbc3 100755
--- a/docker.sh
+++ b/docker.sh
@@ -242,7 +242,7 @@
         select_gpg_key
         get_build_configuration
 
-        mvn -Dmaven.artifact.threads=20 -DdryRun=true -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$DEV_VERSION-SNAPSHOT -Dtag="avatica-$RELEASE_VERSION-rc$RC_NUMBER" -Papache-release -Duser.name=$ASF_USERNAME release:prepare -Darguments="-DskipDockerCheck -Dgpg.keyname=$SELECTED_GPG_KEY"
+        mvn -Dmaven.artifact.threads=20 -DdryRun=true -DreleaseVersion=$RELEASE_VERSION -DdevelopmentVersion=$DEV_VERSION-SNAPSHOT -Dtag="avatica-$RELEASE_VERSION-rc$RC_NUMBER" -Papache-release -Duser.name=$ASF_USERNAME release:prepare -Darguments=-Dgpg.keyname=$SELECTED_GPG_KEY
         ;;
 
     release)
@@ -264,7 +264,7 @@
 
     test)
         init_glibc
-        mvn clean verify -Dcheckstyle.skip -DskipDockerCheck
+        mvn clean verify -Dcheckstyle.skip
         ;;
 
     *)
diff --git a/docker/pom.xml b/docker/pom.xml
index 5548499..d1819ed 100644
--- a/docker/pom.xml
+++ b/docker/pom.xml
@@ -96,34 +96,5 @@
         </plugins>
       </build>
     </profile>
-    <profile>
-      <!-- Need to verify that the URL we're pulling from in the Dockerfile is correct for this release -->
-      <id>check-dockerfile-version</id>
-      <activation>
-        <property>
-          <name>!skipDockerCheck</name>
-        </property>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>org.codehaus.gmaven</groupId>
-            <artifactId>groovy-maven-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>check-dockerhub-dockerfile-version</id>
-                <phase>validate</phase>
-                <goals>
-                  <goal>execute</goal>
-                </goals>
-                <configuration>
-                  <source>${project.basedir}/src/test/scripts/verify-dockerhub-dockerfile-version.groovy</source>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
   </profiles>
 </project>
diff --git a/docker/src/main/dockerhub/Dockerfile b/docker/src/main/dockerhub/Dockerfile
index 5308afa..f3a1004 100644
--- a/docker/src/main/dockerhub/Dockerfile
+++ b/docker/src/main/dockerhub/Dockerfile
@@ -20,8 +20,7 @@
 RUN addgroup -S avatica && adduser -S -G avatica avatica
 RUN mkdir -p /home/avatica/classpath
 
-# This line must be preserved. The Maven build will verify this version matches its version
-ARG AVATICA_VERSION="1.12.0"
+ARG AVATICA_VERSION
 
 # Dependencies
 ADD https://repository.apache.org/content/groups/public/org/apache/calcite/avatica/avatica-standalone-server/${AVATICA_VERSION}/avatica-standalone-server-${AVATICA_VERSION}-shaded.jar /home/avatica/classpath
diff --git a/docker/src/main/dockerhub-hypersql/Dockerfile b/docker/src/main/dockerhub/Dockerfile.hypersql
similarity index 97%
rename from docker/src/main/dockerhub-hypersql/Dockerfile
rename to docker/src/main/dockerhub/Dockerfile.hypersql
index 0ea57b3..8c8c82c 100644
--- a/docker/src/main/dockerhub-hypersql/Dockerfile
+++ b/docker/src/main/dockerhub/Dockerfile.hypersql
@@ -13,7 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ARG AVATICA_VERSION=1.12.0
+ARG AVATICA_VERSION
 FROM apache/calcite-avatica:$AVATICA_VERSION
 MAINTAINER Apache Avatica <dev@calcite.apache.org>
 
diff --git a/docker/src/main/dockerhub-hypersql/Dockerfile b/docker/src/main/dockerhub/hooks/build
similarity index 60%
copy from docker/src/main/dockerhub-hypersql/Dockerfile
copy to docker/src/main/dockerhub/hooks/build
index 0ea57b3..cfc048d 100644
--- a/docker/src/main/dockerhub-hypersql/Dockerfile
+++ b/docker/src/main/dockerhub/hooks/build
@@ -1,3 +1,5 @@
+#!/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.
@@ -13,17 +15,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ARG AVATICA_VERSION=1.12.0
-FROM apache/calcite-avatica:$AVATICA_VERSION
-MAINTAINER Apache Avatica <dev@calcite.apache.org>
-
-ARG HSQLDB_VERSION="2.4.1"
-
-# Dependencies
-ADD https://repo1.maven.org/maven2/net/hydromatic/scott-data-hsqldb/0.1/scott-data-hsqldb-0.1.jar /home/avatica/classpath/
-ADD https://repo1.maven.org/maven2/org/hsqldb/hsqldb/${HSQLDB_VERSION}/hsqldb-${HSQLDB_VERSION}.jar /home/avatica/classpath/
-
-# Add on to avatica-server's entrypoint
-CMD ["-u", "jdbc:hsqldb:res:scott"]
-
-# End Dockerfile
+docker build --build-arg AVATICA_VERSION="$DOCKER_TAG" -t $IMAGE_NAME .
\ No newline at end of file
diff --git a/docker/src/main/dockerhub-hypersql/Dockerfile b/docker/src/main/dockerhub/hooks/post_push
similarity index 60%
copy from docker/src/main/dockerhub-hypersql/Dockerfile
copy to docker/src/main/dockerhub/hooks/post_push
index 0ea57b3..c864128 100644
--- a/docker/src/main/dockerhub-hypersql/Dockerfile
+++ b/docker/src/main/dockerhub/hooks/post_push
@@ -1,3 +1,5 @@
+#!/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.
@@ -13,17 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ARG AVATICA_VERSION=1.12.0
-FROM apache/calcite-avatica:$AVATICA_VERSION
-MAINTAINER Apache Avatica <dev@calcite.apache.org>
+HSQLDB_IMAGE_NAME=apache/calcite-avatica-hypersql:$DOCKER_TAG
 
-ARG HSQLDB_VERSION="2.4.1"
-
-# Dependencies
-ADD https://repo1.maven.org/maven2/net/hydromatic/scott-data-hsqldb/0.1/scott-data-hsqldb-0.1.jar /home/avatica/classpath/
-ADD https://repo1.maven.org/maven2/org/hsqldb/hsqldb/${HSQLDB_VERSION}/hsqldb-${HSQLDB_VERSION}.jar /home/avatica/classpath/
-
-# Add on to avatica-server's entrypoint
-CMD ["-u", "jdbc:hsqldb:res:scott"]
-
-# End Dockerfile
+docker build --build-arg AVATICA_VERSION="$DOCKER_TAG" -f Dockerfile.hypersql -t $HSQLDB_IMAGE_NAME .
+docker push $HSQLDB_IMAGE_NAME
\ No newline at end of file
diff --git a/docker/src/test/scripts/verify-dockerhub-dockerfile-version.groovy b/docker/src/test/scripts/verify-dockerhub-dockerfile-version.groovy
deleted file mode 100644
index da7d4f3..0000000
--- a/docker/src/test/scripts/verify-dockerhub-dockerfile-version.groovy
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- */
-
-import java.io.File;
-import java.nio.file.Files;
-
-System.out.println("Verifying the included version in the Docker Hub Dockerfile");
-
-String expectedPrefix = "ARG AVATICA_VERSION=";
-String expectedVersion = project.getVersion();
-
-if (null == expectedVersion) {
-  throw new IllegalArgumentException("Did not find Maven project version");
-}
-
-def dockerfiles = ["src/main/dockerhub/Dockerfile", "src/main/dockerhub-hypersql/Dockerfile"]
-
-for (dockerfilePath in dockerfiles) {
-    File dockerfile = new File(basedir, dockerfilePath);
-    if (!dockerfile.isFile()) {
-      throw new FileNotFoundException("Could not file dockerhub Dockerfile at " + dockerfilePath);
-    }
-
-    List<String> lines = Files.readAllLines(dockerfile.toPath());
-    for (String line : lines) {
-      line = line.trim();
-      if (line.startsWith(expectedPrefix)) {
-        String value = line.substring(expectedPrefix.length());
-        // Trim leading and trailing quotation marks
-        value = value.substring(1, value.length() - 1);
-        if (expectedVersion.equals(value)) {
-          System.out.println("Found expected version in DockerHub dockerfile of " + value);
-          return true;
-        } else {
-          throw new IllegalArgumentException("Expected Avatica version of " + expectedVersion + " but got " + value);
-        }
-      }
-    }
-
-    throw new IllegalArgumentException("Could not extract Avatica version from " + dockerfile);
-}
diff --git a/pom.xml b/pom.xml
index f00b0d0..6197f0b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,7 +69,6 @@
     <docker-maven-plugin.version>1.1.1</docker-maven-plugin.version>
     <dropwizard-metrics.version>4.0.3</dropwizard-metrics.version>
     <forbiddenapis.version>2.6</forbiddenapis.version>
-    <groovy-maven-plugin.version>2.1</groovy-maven-plugin.version>
     <!-- We support guava versions as old as 14.0.1 (the version used by Hive)
          but prefer more recent versions. -->
     <guava.version>14.0.1</guava.version>
@@ -621,11 +620,6 @@
           <version>${build-helper-maven-plugin.version}</version>
         </plugin>
         <plugin>
-          <groupId>org.codehaus.gmaven</groupId>
-          <artifactId>groovy-maven-plugin</artifactId>
-          <version>${groovy-maven-plugin.version}</version>
-        </plugin>
-        <plugin>
           <groupId>org.eclipse.m2e</groupId>
           <artifactId>lifecycle-mapping</artifactId>
           <version>1.0.0</version>
diff --git a/site/_docs/howto.md b/site/_docs/howto.md
index c832731..1615cd1 100644
--- a/site/_docs/howto.md
+++ b/site/_docs/howto.md
@@ -67,15 +67,12 @@
 ## Running tests
 
 The test suite will run by default when you build, unless you specify
-`-DskipTests`:
-
-Note: During development, you should include `-DskipDockerCheck`, because the docker check checks to see if the dockerfile
-includes the correct version, which will fail unless you are making a release of Avatica.
+`-DskipTests`.
 
 ### Running tests in your environment
 
 {% highlight bash %}
-$ ./mvnw clean verify -Dcheckstyle.skip -DskipDockerCheck
+$ ./mvnw clean verify -Dcheckstyle.skip
 {% endhighlight %}
 
 By default, invoking the `verify` Maven lifecycle phase will also cause checkstyle
@@ -177,8 +174,7 @@
 
 * Set up signing keys as described above.
 * Make sure you are using JDK 8 (not 9 or 10).
-* Check that `README`, `site/_docs/howto.md`, `site/_docs/docker_images.md`,
-  and `docker/src/main/dockerhub/Dockerfile` have the correct version number.
+* Check that `README`, `site/_docs/howto.md`, `site/_docs/docker_images.md` have the correct version number.
 * Check that `NOTICE` has the current copyright year.
 * Set `version.major` and `version.minor` in `pom.xml`.
 * Add release notes to `site/_docs/history.md`. Include the commit history,
@@ -227,10 +223,10 @@
 # Typically we increment minor version: If X.Y.Z is 1.11.0, X2.Y2.Z2 is 1.12.0.
 # Note X.Y.Z is the current version we're trying to release, and X2.Y2.Z2 is the next development version.
 # For example, if I am currently building a release for 1.11.0, X.Y.Z would be 1.11.0 and X2.Y2.Z2 would be 1.12.0.
-./mvnw -DdryRun=true -DreleaseVersion=X.Y.Z -DdevelopmentVersion=X2.Y2.Z2-SNAPSHOT -Dtag=avatica-X.Y.Z-rcN -Papache-release -Duser.name=${asf.username} release:prepare -Darguments=-DskipDockerCheck 
+./mvnw -DdryRun=true -DreleaseVersion=X.Y.Z -DdevelopmentVersion=X2.Y2.Z2-SNAPSHOT -Dtag=avatica-X.Y.Z-rcN -Papache-release -Duser.name=${asf.username} release:prepare
 
 # If you have multiple GPG keys, you can select the key used to sign the release by appending `-Dgpg.keyname=${your.key.id}` to `-Darguments`:
-./mvnw -DdryRun=true -DreleaseVersion=X.Y.Z -DdevelopmentVersion=X2.Y2.Z2-SNAPSHOT -Dtag=avatica-X.Y.Z-rcN -Papache-release -Duser.name=${asf.username} release:prepare -Darguments="-DskipDockerCheck -Dgpg.keyname=${your.key.id}"
+./mvnw -DdryRun=true -DreleaseVersion=X.Y.Z -DdevelopmentVersion=X2.Y2.Z2-SNAPSHOT -Dtag=avatica-X.Y.Z-rcN -Papache-release -Duser.name=${asf.username} release:prepare -Darguments=-Dgpg.keyname=${your.key.id}
 {% endhighlight %}
 
 ### To perform the dry-run in docker:
@@ -511,6 +507,10 @@
 * In the line with "orgapachecalcite-xxxx", check the box
 * Press "Release" button
 
+Tip: Push the git tag only after the staged nexus artifacts are promoted in the repository. This is because pushing the
+tag triggers Docker Hub to start building the docker images immediately and the build will pull in the promoted artifacts.
+If the artifacts are not yet available, the build on Docker Hub will fail.
+ 
 Copy the Git tag:
 
 {% highlight bash %}
@@ -553,8 +553,6 @@
 The old releases will remain available in the
 [release archive](http://archive.apache.org/dist/calcite/).
 
-Publish the [Docker images](docker.html).
-
 Add a release note by copying
 [site/_posts/2016-11-01-release-1.9.0.md]({{ site.sourceRoot }}/site/_posts/2016-11-01-release-1.9.0.md),
 generate the javadoc and copy to `site/target/avatica/apidocs`