Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added docker example #42

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ bazel_dep(name = "lz4", version = "1.9.4")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_foreign_cc", version = "0.11.1")
bazel_dep(name = "rules_oci", version = "2.0.0")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "rules_ros_base_image",
image = "python:3.10-bookworm",
digest = "sha256:428430918ab72109921ef55d5f8bdd3a02a90734fd79ee920146cf385a13c110",
platforms = ["linux/amd64"],
)
use_repo(oci, "rules_ros_base_image", "rules_ros_base_image_linux_amd64")

bazel_dep(name = "rules_pkg", version = "1.0.1")
Comment on lines +16 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the refactorings made in #43, we might want to move this into examples/MODULE.bazel


bazel_dep(name = "rules_python", version = "0.33.2", dev_dependency = True)

Expand Down
42 changes: 42 additions & 0 deletions examples/chatter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- Defining a Bazel target for running ROS-topic introspection functionality.
"""

load(
"@rules_oci//oci:defs.bzl",
"oci_image",
"oci_load"
)
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
load("@rules_python//python:defs.bzl", "py_binary")
load("//ros:cc_defs.bzl", "cc_ros_binary")
load(
Expand Down Expand Up @@ -109,3 +115,39 @@ ros_topic(
name = "rostopic",
deps = [":chatter"],
)

# packages up the nodes, launch file, and all the other required runfiles.
# Note the symlink is required in order to place the files where ros_launch is
# expecting them to be.
pkg_tar(
name = "chatter_tar",
srcs = [
":chatter",
],
include_runfiles = True,
package_dir = "chatter",
symlinks = {
"/chatter/chatter.runfiles/_main/external": "/chatter/chatter.runfiles",
}
)

# builds the oci image on top of the @base-image defined at the MODULE level.
# Note that even though the version of python that the nodes run in is contained
# in the runfiles, a version of python is required at the system level in order
# to run the roslaunch command.
oci_image(
name = "chatter_oci_image",
base = "@com_github_mvukov_rules_ros_base_image",
Copy link
Contributor

@hofbi hofbi Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
base = "@com_github_mvukov_rules_ros_base_image",
base = "@rules_ros_base_image",

tars = [":chatter_tar"],
workdir = "/chatter/chatter.runfiles/_main",
entrypoint = ["/chatter/chatter"],
)

# loads the oci image into the docker daemon.
# Example usage: `bazel run //examples/chatter:chatter_oci_load`
# Then to run the container: `docker run -it --rm chatter:latest`
oci_load(
name = "chatter_oci_load",
image = ":chatter_oci_image",
repo_tags = ["chatter:latest"],
)