diff --git a/README.md b/README.md index 7ec73ddaf..b1a9754d0 100644 --- a/README.md +++ b/README.md @@ -120,14 +120,21 @@ docker_toolchain_configure( client_config="/path/to/docker/client/config", ) -# This is NOT needed when going through the language lang_image -# "repositories" function(s). load( "@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories", ) container_repositories() +# This is NOT needed when going through the language lang_image +# "repositories" function(s). +load( + "@io_bazel_rules_docker//repositories:go_repositories.bzl", + container_go_deps = "go_deps", +) + +container_go_deps() + load( "@io_bazel_rules_docker//container:container.bzl", "container_pull", @@ -325,6 +332,13 @@ for more details. To use `cc_image`, add the following to `WORKSPACE`: ```python +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//cc:image.bzl", _cc_image_repos = "repositories", @@ -375,6 +389,13 @@ and see go_image (custom base) example below. To use `py_image`, add the following to `WORKSPACE`: ```python +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//python:image.bzl", _py_image_repos = "repositories", @@ -518,7 +539,13 @@ npm_install( package_json = "//:package.json", ) -# Download base images, etc. +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//nodejs:image.bzl", _nodejs_image_repos = "repositories", @@ -558,16 +585,13 @@ To use `go_image`, add the following to `WORKSPACE`: ```python load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -# You *must* import the Go rules before setting up the go_image rules. -http_archive( - name = "io_bazel_rules_go", - # Replace with a real SHA256 checksum - sha256 = "{SHA256}" - # Replace with a real commit SHA - strip_prefix = "rules_go-{HEAD}", - urls = ["https://github.com/bazelbuild/rules_go/archive/{HEAD}.tar.gz"], +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", ) +container_repositories() + load( "@io_bazel_rules_docker//go:image.bzl", _go_image_repos = "repositories", @@ -662,6 +686,13 @@ go_image( To use `java_image`, add the following to `WORKSPACE`: ```python +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//java:image.bzl", _java_image_repos = "repositories", @@ -694,6 +725,13 @@ and see go_image (custom base) example. To use `war_image`, add the following to `WORKSPACE`: ```python +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//java:image.bzl", _java_image_repos = "repositories", @@ -752,6 +790,13 @@ load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") scala_repositories() +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//scala:image.bzl", _scala_image_repos = "repositories", @@ -802,6 +847,13 @@ load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_repositories") groovy_repositories() +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//groovy:image.bzl", _groovy_image_repos = "repositories", @@ -852,6 +904,13 @@ load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories") rust_repositories() +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//rust:image.bzl", _rust_image_repos = "repositories", @@ -901,6 +960,13 @@ load("@io_bazel_rules_d//d:d.bzl", "d_repositories") d_repositories() +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + load( "@io_bazel_rules_docker//d:image.bzl", _d_image_repos = "repositories", diff --git a/WORKSPACE b/WORKSPACE index 1300b3738..1446283f1 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -33,6 +33,13 @@ load( container_repositories() +load( + "//repositories:go_repositories.bzl", + container_go_deps = "go_deps", +) + +container_go_deps() + load( "//container:new_pull.bzl", "new_container_pull", @@ -253,26 +260,6 @@ load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_repositories") groovy_repositories() -# For our go_image test. -http_archive( - name = "io_bazel_rules_go", - sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains() - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") - -gazelle_dependencies() - # Have the go_image dependencies for testing. load( "//go:image.bzl", @@ -388,15 +375,3 @@ rbe_autoconfig( ) # gazelle:repo bazel_gazelle - -go_repository( - name = "com_github_google_go_containerregistry", - commit = "6991786f93129be24f857070fe94754a9ea02a0a", - importpath = "github.com/google/go-containerregistry", -) - -go_repository( - name = "com_github_pkg_errors", - commit = "27936f6d90f9c8e1145f11ed52ffffbfdb9e0af7", - importpath = "github.com/pkg/errors", -) diff --git a/cc/image.bzl b/cc/image.bzl index 98adad29e..e75dc19a4 100644 --- a/cc/image.bzl +++ b/cc/image.bzl @@ -25,8 +25,8 @@ load( "app_layer", ) load( - "//repositories:repositories.bzl", - _repositories = "repositories", + "//repositories:go_repositories.bzl", + _go_deps = "go_deps", ) # Load the resolved digests. @@ -35,10 +35,10 @@ load(":cc.bzl", "DIGESTS") def repositories(): """Import the dependencies for the cc_image rule. - Call the core "repositories" function to reduce boilerplate. This is + Call the core "go_deps" function to reduce boilerplate. This is idempotent if folks call it themselves. """ - _repositories() + _go_deps() excludes = native.existing_rules().keys() if "cc_image_base" not in excludes: diff --git a/container/go/cloudbuild.yaml b/container/go/cloudbuild.yaml index fa53268b0..d862062b8 100644 --- a/container/go/cloudbuild.yaml +++ b/container/go/cloudbuild.yaml @@ -14,7 +14,7 @@ # This cloudbuild.yaml file is used to release the go puller binary. -timeout: 21600s +timeout: 3600s options: machineType: "N1_HIGHCPU_32" diff --git a/go/image.bzl b/go/image.bzl index d2201f51b..8ef62dff1 100644 --- a/go/image.bzl +++ b/go/image.bzl @@ -29,8 +29,8 @@ load( "app_layer", ) load( - "//repositories:repositories.bzl", - _repositories = "repositories", + "//repositories:go_repositories.bzl", + _go_deps = "go_deps", ) # Load the resolved digests. @@ -39,10 +39,10 @@ load(":go.bzl", "DIGESTS") def repositories(): """Import the dependencies of the go_image rule. - Call the core "repositories" function to reduce boilerplate. This is + Call the core "go_deps" function to reduce boilerplate. This is idempotent if folks call it themselves. """ - _repositories() + _go_deps() excludes = native.existing_rules().keys() if "go_image_base" not in excludes: diff --git a/java/image.bzl b/java/image.bzl index a2d5ade3a..b6bd79513 100644 --- a/java/image.bzl +++ b/java/image.bzl @@ -31,8 +31,8 @@ load( lang_image = "image", ) load( - "//repositories:repositories.bzl", - _repositories = "repositories", + "//repositories:go_repositories.bzl", + _go_deps = "go_deps", ) # Load the resolved digests. @@ -48,10 +48,10 @@ load( def repositories(): """Import the dependencies of the java_image rule. - Call the core "repositories" function to reduce boilerplate. This is + Call the core "go_deps" function to reduce boilerplate. This is idempotent if folks call it themselves. """ - _repositories() + _go_deps() excludes = native.existing_rules().keys() if "java_image_base" not in excludes: diff --git a/nodejs/image.bzl b/nodejs/image.bzl index 601b205be..fefd1729a 100644 --- a/nodejs/image.bzl +++ b/nodejs/image.bzl @@ -28,8 +28,8 @@ load( lang_image = "image", ) load( - "//repositories:repositories.bzl", - _repositories = "repositories", + "//repositories:go_repositories.bzl", + _go_deps = "go_deps", ) # Load the resolved digests. @@ -38,10 +38,10 @@ load(":nodejs.bzl", "DIGESTS") def repositories(): """Import the dependencies of the nodejs_image rule. - Call the core "repositories" function to reduce boilerplate. This is + Call the core "go_deps" function to reduce boilerplate. This is idempotent if folks call it themselves. """ - _repositories() + _go_deps() excludes = native.existing_rules().keys() if "nodejs_image_base" not in excludes: diff --git a/python/image.bzl b/python/image.bzl index cfa43021c..34617e5e9 100644 --- a/python/image.bzl +++ b/python/image.bzl @@ -26,8 +26,8 @@ load( "filter_layer", ) load( - "//repositories:repositories.bzl", - _repositories = "repositories", + "//repositories:go_repositories.bzl", + _go_deps = "go_deps", ) # Load the resolved digests. @@ -36,10 +36,10 @@ load(":python.bzl", "DIGESTS") def repositories(): """Import the dependencies of the py_image rule. - Call the core "repositories" function to reduce boilerplate. This is + Call the core "go_deps" function to reduce boilerplate. This is idempotent if folks call it themselves. """ - _repositories() + _go_deps() # Register the default py_toolchain for containerized execution native.register_toolchains("@io_bazel_rules_docker//toolchains/python:container_py_toolchain") diff --git a/python3/image.bzl b/python3/image.bzl index 9e521cfd6..e1f77cc8d 100644 --- a/python3/image.bzl +++ b/python3/image.bzl @@ -25,8 +25,8 @@ load( "app_layer", ) load( - "//repositories:repositories.bzl", - _repositories = "repositories", + "//repositories:go_repositories.bzl", + _go_deps = "go_deps", ) # Load the resolved digests. @@ -35,10 +35,10 @@ load(":python3.bzl", "DIGESTS") def repositories(): """Import the dependencies of the py3_image rule. - Call the core "repositories" function to reduce boilerplate. This is + Call the core "go_deps" function to reduce boilerplate. This is idempotent if folks call it themselves. """ - _repositories() + _go_deps() # Register the default py_toolchain for containerized execution native.register_toolchains("@io_bazel_rules_docker//toolchains/python:container_py_toolchain") diff --git a/repositories/go_repositories.bzl b/repositories/go_repositories.bzl new file mode 100644 index 000000000..25fc0d5ba --- /dev/null +++ b/repositories/go_repositories.bzl @@ -0,0 +1,48 @@ +# Copyright 2016 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. + +# Once recursive workspace is implemented in Bazel, this file should cease +# to exist. +""" +Provides functions to pull all Go external package dependencies of this +repository. +""" + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + +def go_deps(): + """Pull in external Go packages needed by Go binaries in this repo. + + Pull in all dependencies needed to build the Go binaries in this + repository. This function assumes the repositories imported by the macro + 'repositories' in //repositories:repositories.bzl have been imported + already. + """ + go_rules_dependencies() + go_register_toolchains() + gazelle_dependencies() + excludes = native.existing_rules().keys() + if "com_github_google_go_containerregistry" not in excludes: + go_repository( + name = "com_github_google_go_containerregistry", + commit = "6991786f93129be24f857070fe94754a9ea02a0a", + importpath = "github.com/google/go-containerregistry", + ) + if "com_github_pkg_errors" not in excludes: + go_repository( + name = "com_github_pkg_errors", + commit = "27936f6d90f9c8e1145f11ed52ffffbfdb9e0af7", + importpath = "github.com/pkg/errors", + ) diff --git a/repositories/repositories.bzl b/repositories/repositories.bzl index 66364af46..2339130dd 100644 --- a/repositories/repositories.bzl +++ b/repositories/repositories.bzl @@ -104,6 +104,16 @@ def repositories(): # TODO(mattmoor): Remove all of this (copied from google/containerregistry) # once transitive workspace instantiation lands. + if "io_bazel_rules_go" not in excludes: + http_archive( + name = "io_bazel_rules_go", + sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", + "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", + ], + ) + if "httplib2" not in excludes: # TODO(mattmoor): Is there a clean way to override? http_archive( diff --git a/testing/custom_toolchain_auth/WORKSPACE b/testing/custom_toolchain_auth/WORKSPACE index adf408613..a95358795 100644 --- a/testing/custom_toolchain_auth/WORKSPACE +++ b/testing/custom_toolchain_auth/WORKSPACE @@ -14,8 +14,6 @@ workspace(name = "e2e_testing") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - # Placeholder repository definition to import rules_docker. To be replaced # with real path on bazel invocation using --override_repository local_repository( @@ -45,36 +43,12 @@ load( container_repositories() -http_archive( - name = "io_bazel_rules_go", - sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains() - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") - -gazelle_dependencies() - -go_repository( - name = "com_github_google_go_containerregistry", - commit = "6991786f93129be24f857070fe94754a9ea02a0a", - importpath = "github.com/google/go-containerregistry", +load( + "@io_bazel_rules_docker//repositories:go_repositories.bzl", + container_go_deps = "go_deps", ) -go_repository( - name = "com_github_pkg_errors", - commit = "27936f6d90f9c8e1145f11ed52ffffbfdb9e0af7", - importpath = "github.com/pkg/errors", -) +container_go_deps() load( "@io_bazel_rules_docker//container:container.bzl", diff --git a/testing/default_toolchain/WORKSPACE b/testing/default_toolchain/WORKSPACE index a92f261a8..b7346ceb3 100644 --- a/testing/default_toolchain/WORKSPACE +++ b/testing/default_toolchain/WORKSPACE @@ -14,8 +14,6 @@ workspace(name = "e2e_testing") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - # Placeholder repository definition to import rules_docker. To be replaced # with real path on bazel invocation using --override_repository local_repository( @@ -37,36 +35,12 @@ load( container_repositories() -http_archive( - name = "io_bazel_rules_go", - sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains() - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") - -gazelle_dependencies() - -go_repository( - name = "com_github_google_go_containerregistry", - commit = "6991786f93129be24f857070fe94754a9ea02a0a", - importpath = "github.com/google/go-containerregistry", +load( + "@io_bazel_rules_docker//repositories:go_repositories.bzl", + container_go_deps = "go_deps", ) -go_repository( - name = "com_github_pkg_errors", - commit = "27936f6d90f9c8e1145f11ed52ffffbfdb9e0af7", - importpath = "github.com/pkg/errors", -) +container_go_deps() load( "@io_bazel_rules_docker//container:container.bzl", diff --git a/testing/examples/WORKSPACE b/testing/examples/WORKSPACE index b75ff8188..375eb5659 100644 --- a/testing/examples/WORKSPACE +++ b/testing/examples/WORKSPACE @@ -28,6 +28,13 @@ load( container_repositories() +load( + "@io_bazel_rules_docker//repositories:go_repositories.bzl", + container_go_deps = "go_deps", +) + +container_go_deps() + load("@io_bazel_rules_docker//container:container.bzl", "container_pull") load("@io_bazel_rules_docker//contrib:dockerfile_build.bzl", "dockerfile_image") load("@io_bazel_rules_docker//java:image.bzl", _java_image_repos = "repositories") @@ -54,19 +61,6 @@ pip_import( requirements = "@base_images_docker//package_managers:requirements-pip.txt", ) -http_archive( - name = "io_bazel_rules_go", - sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") - -go_rules_dependencies() - container_pull( name = "alpine_linux_amd64", registry = "index.docker.io", diff --git a/testing/examples/run_instruction_arbitrary/cloudbuild.yaml b/testing/examples/run_instruction_arbitrary/cloudbuild.yaml index f58e464b3..fad3cf0c3 100644 --- a/testing/examples/run_instruction_arbitrary/cloudbuild.yaml +++ b/testing/examples/run_instruction_arbitrary/cloudbuild.yaml @@ -15,6 +15,7 @@ # Tests that verify the example manipulating arbitrary commands using # rules_docker and Dockerfile. +timeout: 1200s options: machineType: "N1_HIGHCPU_32" diff --git a/testing/java_image/BUILD b/testing/java_image/BUILD new file mode 100644 index 000000000..ab2767ed5 --- /dev/null +++ b/testing/java_image/BUILD @@ -0,0 +1,15 @@ +load("@io_bazel_rules_docker//java:image.bzl", "java_image") + +package(default_visibility = ["//visibility:public"]) + +java_image( + name = "java_image", + srcs = [":Runfiles.java"], + data = [ + ":foo", + ], + main_class = "examples.images.Runfiles", + deps = [ + "@bazel_tools//tools/java/runfiles", + ], +) diff --git a/testing/java_image/Runfiles.java b/testing/java_image/Runfiles.java new file mode 100644 index 000000000..3f3260dba --- /dev/null +++ b/testing/java_image/Runfiles.java @@ -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. + +package examples.images; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class Runfiles { + public static void main(String[] args) throws IOException { + String path = com.google.devtools.build.runfiles.Runfiles.create() + .rlocation("io_bazel_rules_docker/testdata/foo"); + byte[] encoded = Files.readAllBytes(Paths.get(path)); + System.out.println(new String(encoded, StandardCharsets.UTF_8)); + } +} diff --git a/testing/java_image/WORKSPACE b/testing/java_image/WORKSPACE new file mode 100644 index 000000000..d2c0ac069 --- /dev/null +++ b/testing/java_image/WORKSPACE @@ -0,0 +1,35 @@ +# 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. + +workspace(name = "java_image_example") + +local_repository( + name = "io_bazel_rules_docker", + path = "../../", +) + +# java_image rule dependencies. +load( + "@io_bazel_rules_docker//repositories:repositories.bzl", + container_repositories = "repositories", +) + +container_repositories() + +load( + "@io_bazel_rules_docker//java:image.bzl", + _java_image_repos = "repositories", +) + +_java_image_repos() diff --git a/testing/java_image/cloudbuild.yaml b/testing/java_image/cloudbuild.yaml new file mode 100644 index 000000000..11bbfd748 --- /dev/null +++ b/testing/java_image/cloudbuild.yaml @@ -0,0 +1,23 @@ +# 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. + +# Tests that verify the java_image example of rules_docker. +# This basic test verifies dependencies can be resolved correctly for a +# simple repo using java_image. + +steps: + # Test the java_image example. + - name: "l.gcr.io/google/bazel" + args: ["build", "//..."] + dir: "testing/java_image" diff --git a/testing/java_image/foo b/testing/java_image/foo new file mode 100644 index 000000000..5e40c0877 --- /dev/null +++ b/testing/java_image/foo @@ -0,0 +1 @@ +asdf \ No newline at end of file