Add --no-cache option to Gerrit build command

Always using the cache can be a problem in CI.

Specifically, Gerrit's e2e test [1] runs a daily job where it gets a war
file from a link that always points to the last successful build. The
link doesn't change even if a new build succeeds. In this case, Docker
would not notice that the artifact has changed, and would keep using the
one in the cached build instead of the new one.

Add the `GERRIT_BUILD_NO_CACHE` option to allow Docker to rebuild the
image with the new war file.

[1] https://gerrit-ci.gerritforge.com/job/gatling-gerrit-test/

Bug: Issue 306202742
Change-Id: I387e8589f46d1d0edef388768605926b6eafb9e8
diff --git a/Configuration.md b/Configuration.md
index 753001a..4bd418e 100644
--- a/Configuration.md
+++ b/Configuration.md
@@ -25,6 +25,8 @@
 * `HOSTED_ZONE_NAME`: Optional. Name of the hosted zone. `mycompany.com` by default.
 * `GERRIT_KEY_PREFIX` : Optional. Secrets prefix used during the [Import into AWS Secret Manager](#import-into-aws-secret-manager).
   `gerrit_secret` by default.
+* `GERRIT_BUILD_NO_CACHE`: Optional. Don't use the Docker build cache when building the Gerrit image.
+  Any non-zero length string will set this. Unset by default, so the cache is used.
 
 #### Scheduled Git Garbage Collection
 
diff --git a/gerrit/Makefile b/gerrit/Makefile
index e2a3bd4..9455b01 100644
--- a/gerrit/Makefile
+++ b/gerrit/Makefile
@@ -44,7 +44,13 @@
 	done
 
 gerrit-build: check-gerrit-version-vs-war-url
-	docker build \
+	if [[ "$(GERRIT_BUILD_NO_CACHE)" ]]; \
+	then \
+		export build_args="--no-cache"; \
+	else \
+		export build_args=""; \
+	fi; \
+	docker build $${build_args} \
 		--build-arg withXRay="$(XRAY_ENABLED)" \
 		--build-arg GERRIT_VERSION=$(GERRIT_VERSION) \
 		--build-arg GERRIT_PATCH=$(GERRIT_PATCH) \