cos-customizer: Add arm64 target for docker-credential-gcr

Since Bazel's --platforms flag doesn't work for us, we need to patch
docker-credential-gcr to offer an explicit arm64 target. The target
definition is very small and has few dependencies, so I expect this new
patch to be very low maintenance.

It probably doesn't make much sense to upstream because the --platforms
flag works in nearly all other use cases, and it would be strange for
docker-credential-gcr to have amd64 and arm64 targets, but not targets
for other architectures/operating systems.

This change makes no behavioral changes.

BUG=b/176990931
TEST=`bazel test`

Change-Id: I1d1e7d11d9950fc752207b887ef450dbcdc2d81d
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/25882
Cloud-Build: GCB Service account <228075978874@cloudbuild.gserviceaccount.com>
Reviewed-by: Roy Yang <royyang@google.com>
Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com>
diff --git a/WORKSPACE b/WORKSPACE
index 8cd183f..cc0ad52 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -73,6 +73,10 @@
     commit = "6093d30b51d725877bc6971aa6700153c1a364f1",
     remote = "https://github.com/GoogleCloudPlatform/docker-credential-gcr",
     shallow_since = "1613169008 -0800",
+    patches = [
+        "//src/third_party/docker_credential_gcr:0001-Add-explicit-targets-for-amd64-and-arm64.patch",
+    ],
+    patch_args = ["-p1"],
 )
 
 load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
diff --git a/src/cmd/provisioner/BUILD.bazel b/src/cmd/provisioner/BUILD.bazel
index ef22e4e..0518e0b 100644
--- a/src/cmd/provisioner/BUILD.bazel
+++ b/src/cmd/provisioner/BUILD.bazel
@@ -35,7 +35,7 @@
 
 genrule(
     name = "docker_credential_gcr",
-    srcs = ["@com_github_googlecloudplatform_docker_credential_gcr//:docker-credential-gcr"],
+    srcs = ["@com_github_googlecloudplatform_docker_credential_gcr//:docker-credential-gcr_amd64"],
     outs = ["docker-credential-gcr"],
     cmd = "cp $< $@",
 )
diff --git a/src/third_party/docker_credential_gcr/0001-Add-explicit-targets-for-amd64-and-arm64.patch b/src/third_party/docker_credential_gcr/0001-Add-explicit-targets-for-amd64-and-arm64.patch
new file mode 100644
index 0000000..d46a558
--- /dev/null
+++ b/src/third_party/docker_credential_gcr/0001-Add-explicit-targets-for-amd64-and-arm64.patch
@@ -0,0 +1,40 @@
+From 8a0f755c61b768621f180074ae96bae0911daefb Mon Sep 17 00:00:00 2001
+From: Robert Kolchmeyer <rkolchmeyer@google.com>
+Date: Mon, 6 Dec 2021 11:34:34 -0800
+Subject: [PATCH] Add explicit targets for amd64 and arm64.
+
+cos-customizer needs both in the same build, so bazel's --platforms flag
+doesn't work for us.
+---
+ BUILD | 18 ++++++++++++++++++
+ 1 file changed, 18 insertions(+)
+
+diff --git a/BUILD b/BUILD
+index a0e0629..e43e017 100644
+--- a/BUILD
++++ b/BUILD
+@@ -33,3 +33,21 @@ go_binary(
+     pure = "on",
+     visibility = ["//visibility:public"],
+ )
++
++go_binary(
++    name = "docker-credential-gcr_amd64",
++    embed = [":go_default_library"],
++    pure = "on",
++    goos = "linux",
++    goarch = "amd64",
++    visibility = ["//visibility:public"],
++)
++
++go_binary(
++    name = "docker-credential-gcr_arm64",
++    embed = [":go_default_library"],
++    pure = "on",
++    goos = "linux",
++    goarch = "arm64",
++    visibility = ["//visibility:public"],
++)
+-- 
+2.34.1.400.ga245620fadb-goog
+
diff --git a/src/third_party/docker_credential_gcr/BUILD.bazel b/src/third_party/docker_credential_gcr/BUILD.bazel
new file mode 100644
index 0000000..8e71575
--- /dev/null
+++ b/src/third_party/docker_credential_gcr/BUILD.bazel
@@ -0,0 +1,13 @@
+# Copyright 2021 Google LLC
+#
+# Licensed 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.