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

Add back examples for archiving binaries and assembling Docker images #10

Open
mvukov opened this issue Mar 4, 2024 · 4 comments · May be fixed by #42
Open

Add back examples for archiving binaries and assembling Docker images #10

mvukov opened this issue Mar 4, 2024 · 4 comments · May be fixed by #42

Comments

@mvukov
Copy link
Owner

mvukov commented Mar 4, 2024

No description provided.

@outrider-ksilva
Copy link

I'm investigating using Bazel for some ROS builds and this repo has been extremely helpful! I've been able to get builds to work for interfaces, libraries, and launch-files, but I have not been able to get the container_image example to work.

I just saw that you've started making updates to this repo again. Do you know if the examples for docker images will look similar to the previous examples using container_image, or do you think they'll use a different strategy like oci_image? Do you have a timeline when you think the examples will be re-added?

I'm still learning Bazel, but let me know if there's anything I can do to help implement or test these changes.

@mvukov
Copy link
Owner Author

mvukov commented Mar 26, 2024

Hi, indeed, the idea is to use https://github.com/bazel-contrib/rules_oci . It should be fairly straightforward to set up an example for creating a ROS app deployment image using e.g. https://github.com/aspect-build/bazel-examples/tree/main/oci_python_image. I'll try to add this soon. If you manage to put together an example before me, please open a PR. It can be even simpler than that mentioned example: we don't need to split the layers (that's an optimization). We could create a single layer and point out how to split layers for more efficiency.

@JohnRudolfLewis
Copy link

I started looking into this. Looking at the example you reference, it appears as though each project would need to create a py_layer.bzl or similar in their project. Wouldn't it be nice to reduce that code duplication and include a function in this library to do all the heavy lifting for the users?

@JohnRudolfLewis
Copy link

JohnRudolfLewis commented Jul 31, 2024

I found a solution that works. A bit of a hack, but it works. Also, no layering with this solution either.

I could not get rules_pkg:pkg_tar to package up the runfiles, they've removed (hidden private actually) the previously accessible but undocumented include_runfiles argument. I was hoping to be able to use that, plus their ability to create symlinks to package up my tar properly. But no.

I found aspect_bazel_lib:tar includes the runfiles, but they are arranged in such a way that roslaunch will fail:

RLException: Invalid roslaunch XML syntax: [Errno 2] No such file or directory: 'external/com_github_mvukov_rules_ros~/third_party/ros/roslaunch/roscore.xml'
The traceback for the exception was written to the log file

A symlink can fix the problem, but this rule does not have any provision to create the needed symlink.

But this is easily fixed. I added a run.sh script to create the missing symlink, cd into the proper directory, then run the launch command.

#!/bin/sh
ln -s /chatter/chatter_launch.runfiles /chatter/chatter_launch.runfiles/_main/external
cd /chatter/chatter_launch.runfiles/_main
/chatter/chatter_launch

Add the following to your MODULE.bazel

bazel_dep(name = "aspect_bazel_lib", version = "2.7.9")
bazel_dep(name = "rules_oci", version = "1.8.0")
archive_override(
    module_name = "rules_oci",
    strip_prefix = "rules_oci-e389ddeed00139eaec9ca24689fa71079725d8ab",
    urls = "https://github.com/bazel-contrib/rules_oci/archive/e389ddeed00139eaec9ca24689fa71079725d8ab.zip",
)
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
    name = "base-image",
    image = "public.ecr.aws/docker/library/python:3.10",
    platforms = ["linux/amd64"],
)
use_repo(oci, "base-image", "base-image_linux_amd64")

And then in your BUILD.bazel

load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load(
    "@rules_oci//oci:defs.bzl", 
    "oci_image", 
    "oci_load"
)

tar(
    name = "chatter_tar",
    srcs = [":chatter_launch", "run.sh"],
)

oci_image(
    name = "chatter_oci_image",
    base = "@base-image",
    tars = [":chatter_tar"],
    cmd = ["/chatter/run.sh"]
)

oci_load(
    name = "chatter_oci_load",
    image = ":chatter_oci_image",
    repo_tags = ["chatter:latest"],
)

To generate the image:

bazel run //chatter:chatter_oci_load

And to run that image locally:

docker run -ti --rm chatter:latest

Too much of an ugly hack to publish a PR with this, but hope this helps someone.

@JohnRudolfLewis JohnRudolfLewis linked a pull request Aug 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants