Add gcloud to trusty and jessie (#282)

* adding gcloud to trusty and jessie bazel containers

* fixes

* Explicitly name gpg files

* buildify

* fix incorrect version of gcloud deb
diff --git a/container/common/gcloud/BUILD b/container/common/gcloud/BUILD
new file mode 100644
index 0000000..dfcedc7
--- /dev/null
+++ b/container/common/gcloud/BUILD
@@ -0,0 +1,29 @@
+# Copyright 2017 The Bazel Authors. All rights reserved.
+#
+# 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.
+
+licenses(["notice"])  # Apache 2.0
+
+package(default_visibility = ["//visibility:public"])
+
+load(
+    "//container/common/gcloud:version.bzl",
+    "GCLOUD_VERSION",
+)
+
+genrule(
+    name = "generate_gcloud_yaml",
+    srcs = ["gcloud.yaml.tpl"],
+    outs = ["gcloud.yaml"],
+    cmd = "sed 's|{_GCLOUD_VERSION}|" + GCLOUD_VERSION.rpartition("-")[0] + "|' <$< >$@",
+)
diff --git a/container/ubuntu16_04/layers/gcloud/gcloud.yaml.tpl b/container/common/gcloud/gcloud.yaml.tpl
similarity index 100%
rename from container/ubuntu16_04/layers/gcloud/gcloud.yaml.tpl
rename to container/common/gcloud/gcloud.yaml.tpl
diff --git a/container/ubuntu16_04/layers/gcloud/version.bzl b/container/common/gcloud/version.bzl
similarity index 100%
rename from container/ubuntu16_04/layers/gcloud/version.bzl
rename to container/common/gcloud/version.bzl
diff --git a/container/debian8/builders/bazel/BUILD b/container/debian8/builders/bazel/BUILD
index 19100f0..b9c7c93 100644
--- a/container/debian8/builders/bazel/BUILD
+++ b/container/debian8/builders/bazel/BUILD
@@ -53,6 +53,7 @@
         "//container/debian8/layers/bazel:bazel-tools",
         "//container/debian8/layers/bazel:bazel_%s-ltl" % bazel_version,
         "//container/debian8/layers/docker-17.12.0:docker-ltl",
+        "//container/debian8/layers/gcloud:gcloud-ltl",
     ],
 ) for bazel_version, _ in BAZEL_VERSION_SHA256S.items()]
 
@@ -78,6 +79,7 @@
         "//container/common:python2.yaml",
         "//container/common:python3.yaml",
         "//container/common/clang:clang.yaml",
+        "//container/common/gcloud:gcloud.yaml",
         "//container/common/bazel:bazel_%s.yaml" % bazel_version,
         "//container/common/bazel:bazel_tools.yaml",
         "//container/common/bazel:extra_tools.yaml",
diff --git a/container/debian8/layers/gcloud/BUILD b/container/debian8/layers/gcloud/BUILD
new file mode 100644
index 0000000..5f90fb8
--- /dev/null
+++ b/container/debian8/layers/gcloud/BUILD
@@ -0,0 +1,37 @@
+# Copyright 2017 The Bazel Authors. All rights reserved.
+#
+# 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.
+
+licenses(["notice"])  # Apache 2.0
+
+package(default_visibility = ["//visibility:public"])
+
+load("//rules/container:docker_toolchains.bzl", "language_tool_layer")
+load(
+    "//container/common/gcloud:version.bzl",
+    "GCLOUD_VERSION",
+)
+
+language_tool_layer(
+    name = "gcloud-ltl",
+    additional_repos = [
+        "deb http://packages.cloud.google.com/apt cloud-sdk-jessie main",
+    ],
+    base = "@debian8//image",
+    keys = [
+        "@gcloud_gpg//file",
+    ],
+    packages = [
+        "google-cloud-sdk=%s" % GCLOUD_VERSION,
+    ],
+)
diff --git a/container/ubuntu14_04/builders/bazel/BUILD b/container/ubuntu14_04/builders/bazel/BUILD
index 89aa93c..30ca678 100644
--- a/container/ubuntu14_04/builders/bazel/BUILD
+++ b/container/ubuntu14_04/builders/bazel/BUILD
@@ -53,6 +53,7 @@
         "//container/ubuntu14_04/layers/bazel:bazel-tools",
         "//container/ubuntu14_04/layers/bazel:bazel_%s-ltl" % bazel_version,
         "//container/ubuntu14_04/layers/docker-17.12.0:docker-ltl",
+        "//container/ubuntu14_04/layers/gcloud:gcloud-ltl",
     ],
 ) for bazel_version, _ in BAZEL_VERSION_SHA256S.items()]
 
@@ -77,6 +78,7 @@
         "//container/common:java.yaml",
         "//container/common:python2.yaml",
         "//container/common:python3.yaml",
+        "//container/common/gcloud:gcloud.yaml",
         "//container/common/bazel:bazel_%s.yaml" % bazel_version,
         "//container/common/bazel:bazel_tools.yaml",
         "//container/common/bazel:extra_tools.yaml",
diff --git a/container/ubuntu14_04/layers/gcloud/BUILD b/container/ubuntu14_04/layers/gcloud/BUILD
new file mode 100644
index 0000000..855e7fa
--- /dev/null
+++ b/container/ubuntu14_04/layers/gcloud/BUILD
@@ -0,0 +1,37 @@
+# Copyright 2017 The Bazel Authors. All rights reserved.
+#
+# 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.
+
+licenses(["notice"])  # Apache 2.0
+
+package(default_visibility = ["//visibility:public"])
+
+load("//rules/container:docker_toolchains.bzl", "language_tool_layer")
+load(
+    "//container/common/gcloud:version.bzl",
+    "GCLOUD_VERSION",
+)
+
+language_tool_layer(
+    name = "gcloud-ltl",
+    additional_repos = [
+        "deb http://packages.cloud.google.com/apt cloud-sdk-trusty main",
+    ],
+    base = "@trusty//image",
+    keys = [
+        "@gcloud_gpg//file",
+    ],
+    packages = [
+        "google-cloud-sdk=%s" % GCLOUD_VERSION,
+    ],
+)
diff --git a/container/ubuntu16_04/builders/bazel_docker_gcloud/BUILD b/container/ubuntu16_04/builders/bazel_docker_gcloud/BUILD
index b7aed9e..4bbe9a5 100644
--- a/container/ubuntu16_04/builders/bazel_docker_gcloud/BUILD
+++ b/container/ubuntu16_04/builders/bazel_docker_gcloud/BUILD
@@ -72,11 +72,11 @@
         "//container/common:python2.yaml",
         "//container/common:python3_rbe.yaml",
         "//container/common/clang:clang.yaml",
+        "//container/common/gcloud:gcloud.yaml",
         "//container/common/bazel:bazel_%s.yaml" % bazel_version,
         "//container/common/bazel:bazel_tools.yaml",
         "//container/common/bazel:extra_tools.yaml",
         "//container/ubuntu16_04:ubuntu16_04.yaml",
-        "//container/ubuntu16_04/layers/gcloud:gcloud.yaml",
     ],
     image = ":bazel_%s_docker_gcloud" % bazel_version,
     verbose = True,
diff --git a/container/ubuntu16_04/layers/gcloud/BUILD b/container/ubuntu16_04/layers/gcloud/BUILD
index e0e1a2c..ae23e01 100644
--- a/container/ubuntu16_04/layers/gcloud/BUILD
+++ b/container/ubuntu16_04/layers/gcloud/BUILD
@@ -18,17 +18,10 @@
 
 load("//rules/container:docker_toolchains.bzl", "language_tool_layer")
 load(
-    "//container/ubuntu16_04/layers/gcloud:version.bzl",
+    "//container/common/gcloud:version.bzl",
     "GCLOUD_VERSION",
 )
 
-genrule(
-    name = "generate_gcloud_yaml",
-    srcs = ["gcloud.yaml.tpl"],
-    outs = ["gcloud.yaml"],
-    cmd = "sed 's|{_GCLOUD_VERSION}|" + GCLOUD_VERSION.rpartition("-")[0] + "|' <$< >$@",
-)
-
 language_tool_layer(
     name = "gcloud-ltl",
     additional_repos = [
diff --git a/repositories/repositories.bzl b/repositories/repositories.bzl
index 2e8a734..f88f873 100644
--- a/repositories/repositories.bzl
+++ b/repositories/repositories.bzl
@@ -100,6 +100,7 @@
     if "bazel_gpg" not in excludes:
         http_file(
             name = "bazel_gpg",
+            downloaded_file_path = "bazel_gpg",
             sha256 = "30af2ca7abfb65987cd61802ca6e352aadc6129dfb5bfc9c81f16617bc3a4416",
             urls = ["https://bazel.build/bazel-release.pub.gpg"],
         )
@@ -108,6 +109,7 @@
     if "docker_gpg" not in excludes:
         http_file(
             name = "docker_gpg",
+            downloaded_file_path = "docker_gpg",
             sha256 = "1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570",
             urls = ["https://download.docker.com/linux/ubuntu/gpg"],
         )
@@ -116,6 +118,7 @@
     if "gcloud_gpg" not in excludes:
         http_file(
             name = "gcloud_gpg",
+            downloaded_file_path = "gcloud_gpg",
             sha256 = "226ba1072f20e4ff97ee4f94e87bf45538a900a6d9b25399a7ac3dc5a2f3af87",
             urls = ["https://packages.cloud.google.com/apt/doc/apt-key.gpg"],
         )
@@ -124,6 +127,7 @@
     if "launchpad_openjdk_gpg" not in excludes:
         http_file(
             name = "launchpad_openjdk_gpg",
+            downloaded_file_path = "launchpad_openjdk_gpg",
             sha256 = "54b6274820df34a936ccc6f5cb725a9b7bb46075db7faf0ef7e2d86452fa09fd",
             urls = ["http://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0xEB9B1D8886F44E2A"],
         )