Skip to content

Commit

Permalink
add simple example that exersises minimal deps in WORKSPACE
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Lopez committed Jun 27, 2019
1 parent 431d0b6 commit 1b64604
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 79 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 0 additions & 13 deletions cc/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 0 additions & 10 deletions go/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions java/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions nodejs/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions python/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 0 additions & 13 deletions python3/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions testing/java_image/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
29 changes: 29 additions & 0 deletions testing/java_image/Runfiles.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
42 changes: 42 additions & 0 deletions testing/java_image/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions testing/java_image/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions testing/java_image/foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asdf

0 comments on commit 1b64604

Please sign in to comment.