From 1b64604bdf58801d5e3bd772130f68e06c3dc664 Mon Sep 17 00:00:00 2001 From: Nicolas Lopez Date: Wed, 26 Jun 2019 23:43:28 -0400 Subject: [PATCH] add simple example that exersises minimal deps in WORKSPACE --- README.md | 4 --- cc/image.bzl | 13 --------- go/image.bzl | 10 ------- java/image.bzl | 13 --------- nodejs/image.bzl | 13 --------- python/image.bzl | 13 --------- python3/image.bzl | 13 --------- testing/java_image/BUILD | 15 +++++++++++ testing/java_image/Runfiles.java | 29 +++++++++++++++++++++ testing/java_image/WORKSPACE | 42 ++++++++++++++++++++++++++++++ testing/java_image/cloudbuild.yaml | 23 ++++++++++++++++ testing/java_image/foo | 1 + 12 files changed, 110 insertions(+), 79 deletions(-) create mode 100644 testing/java_image/BUILD create mode 100644 testing/java_image/Runfiles.java create mode 100644 testing/java_image/WORKSPACE create mode 100644 testing/java_image/cloudbuild.yaml create mode 100644 testing/java_image/foo diff --git a/README.md b/README.md index 31b728e89..83f94a610 100644 --- a/README.md +++ b/README.md @@ -120,16 +120,12 @@ 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", diff --git a/cc/image.bzl b/cc/image.bzl index 21cde6323..9ad126756 100644 --- a/cc/image.bzl +++ b/cc/image.bzl @@ -24,26 +24,13 @@ load( "//lang:image.bzl", "app_layer", ) -load( - "//repositories:go_repositories.bzl", - _go_deps = "go_deps", -) -load( - "//repositories:repositories.bzl", - _repositories = "repositories", -) # Load the resolved digests. load(":cc.bzl", "DIGESTS") def repositories(): """Import the dependencies for the cc_image rule. - - Call the core "repositories" 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/go/image.bzl b/go/image.bzl index b69b53939..d2b702b31 100644 --- a/go/image.bzl +++ b/go/image.bzl @@ -28,14 +28,6 @@ load( "//lang:image.bzl", "app_layer", ) -load( - "//repositories:go_repositories.bzl", - _go_deps = "go_deps", -) -load( - "//repositories:repositories.bzl", - _repositories = "repositories", -) # Load the resolved digests. load(":go.bzl", "DIGESTS") @@ -46,8 +38,6 @@ def repositories(): Call the core "repositories" 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 bb39d0970..465bfe1e2 100644 --- a/java/image.bzl +++ b/java/image.bzl @@ -30,14 +30,6 @@ load( "layer_file_path", lang_image = "image", ) -load( - "//repositories:go_repositories.bzl", - _go_deps = "go_deps", -) -load( - "//repositories:repositories.bzl", - _repositories = "repositories", -) # Load the resolved digests. load( @@ -51,12 +43,7 @@ load( def repositories(): """Import the dependencies of the java_image rule. - - Call the core "repositories" 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 e98d99574..22b2b3ca3 100644 --- a/nodejs/image.bzl +++ b/nodejs/image.bzl @@ -27,26 +27,13 @@ load( "app_layer", lang_image = "image", ) -load( - "//repositories:go_repositories.bzl", - _go_deps = "go_deps", -) -load( - "//repositories:repositories.bzl", - _repositories = "repositories", -) # Load the resolved digests. load(":nodejs.bzl", "DIGESTS") def repositories(): """Import the dependencies of the nodejs_image rule. - - Call the core "repositories" 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 e58e624dc..989ebbacc 100644 --- a/python/image.bzl +++ b/python/image.bzl @@ -25,26 +25,13 @@ load( "app_layer", "filter_layer", ) -load( - "//repositories:go_repositories.bzl", - _go_deps = "go_deps", -) -load( - "//repositories:repositories.bzl", - _repositories = "repositories", -) # Load the resolved digests. load(":python.bzl", "DIGESTS") def repositories(): """Import the dependencies of the py_image rule. - - Call the core "repositories" 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 0590cfabf..d70a1ee96 100644 --- a/python3/image.bzl +++ b/python3/image.bzl @@ -24,26 +24,13 @@ load( "//lang:image.bzl", "app_layer", ) -load( - "//repositories:go_repositories.bzl", - _go_deps = "go_deps", -) -load( - "//repositories:repositories.bzl", - _repositories = "repositories", -) # Load the resolved digests. load(":python3.bzl", "DIGESTS") def repositories(): """Import the dependencies of the py3_image rule. - - Call the core "repositories" 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/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..abf0c90fc --- /dev/null +++ b/testing/java_image/WORKSPACE @@ -0,0 +1,42 @@ +# 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 language rules. +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() + +load( + "@io_bazel_rules_docker//repositories:go_repositories.bzl", + container_go_deps = "go_deps", +) + +container_go_deps() diff --git a/testing/java_image/cloudbuild.yaml b/testing/java_image/cloudbuild.yaml new file mode 100644 index 000000000..6c35d70f1 --- /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 eexample of rules_docker. +# This basic test verifies dependencies can be resolved correctly for a +# simple repo using java_image. + +steps: + # Test the java_app 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