-
Notifications
You must be signed in to change notification settings - Fork 15
added docker example #42
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,12 @@ load("@rules_ros//ros:launch.bzl", "ros_launch") | |
| load("@rules_ros//ros:test.bzl", "ros_test") | ||
| load("@rules_ros//ros:topic.bzl", "ros_topic") | ||
| load("@rules_ros//third_party:expand_template.bzl", "expand_template") | ||
| load( | ||
| "@rules_oci//oci:defs.bzl", | ||
| "oci_image", | ||
| "oci_load" | ||
| ) | ||
| load("@rules_pkg//pkg:pkg.bzl", "pkg_tar") | ||
|
|
||
| # Handling of ROS messages & services resembles to some extent Bazel's rules for | ||
| # handling protobuf messages (e.g. proto_library and cc_proto_library). | ||
|
|
@@ -127,3 +133,37 @@ ros_topic( | |
| name = "rostopic", | ||
| deps = [":chatter"], | ||
| ) | ||
|
|
||
|
|
||
| # packages up the nodes, launch file, and all the other required runfiles. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rules_oci have a good example for to structure python apps, see https://github.com/aspect-build/bazel-examples/tree/main/oci_python_image, py_layer.bzl file in particular. Maybe not for this PR, but it's a nice optimization. |
||
| # 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", | ||
| } | ||
|
Comment on lines
+148
to
+150
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you specify the workdir down below, you shoudn't need this symlink. Please double-check.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the symlink, an error occurs: RLException: Invalid roslaunch XML syntax: [Errno 2] No such file or directory: 'external/rules_ros~/third_party/ros/roslaunch/roscore.xml' Something is expecting all the runfiles to be in an 'external' directory below the working directory. |
||
| ) | ||
|
|
||
| # builds the oci image on top of the @rules_ros_base_image defined at the MODULE level. | ||
| oci_image( | ||
| name = "chatter_oci_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 //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"], | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is an overkill, as we need system python (-like app) to bootstrap the Bazel-managed Python. You could fetch https://raw.githubusercontent.com/buildbarn/bb-remote-execution/96c4fdce659fabfaba7ee2a60fd4e2ffab8352e2/cmd/fake_python/main.go with http_file, compile it using rules_go and inject it into the output image as e.g. /usr/bin/python3 (using ubuntu:22.04 image in this case should be sufficient).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps overkill.... but needing to replicate your suggestion in each and every repo feels way to repetitive. Could we bake this into rules_ros or better yet, rules_python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use
ubuntu:22.04as base image?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ubuntu:22.04 includes a python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? I thought it comes with 3.10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not appear that the image does.