Skip to content

Commit

Permalink
refactor: rename new attribute on oci_tarball (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored Jan 3, 2024
1 parent e420a13 commit 6667c5e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/tarball.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions oci/private/tarball.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ attrs = {
allow_single_file = [".txt"],
mandatory = True,
),
"command": attr.label(
"loader": attr.label(
doc = """\
target for a container cli tool (i.e. docker or podman or other) that will be used to load the image into the local engine when using 'bazel run //my/image'.",
Alternative target for a container cli tool that will be
used to load the image into the local engine when using `bazel run` on this oci_tarball.
By default, we look for `docker` or `podman` on the PATH, and run the `load` command.
> Note that rules_docker has an "incremental loader" which has better performance, see
> Follow https://github.com/bazel-contrib/rules_oci/issues/454 for similar behavior in rules_oci.
See the _run_template attribute for the script that calls this loader tool.
""",
allow_single_file = True,
mandatory = False,
Expand All @@ -51,7 +59,10 @@ attrs = {
"_run_template": attr.label(
default = Label("//oci/private:tarball_run.sh.tpl"),
doc = """ \
The template used to load the container. The default template uses Docker, but this template could be replaced to use podman, runc, or another runtime. Please reference the default template to see available substitutions.
The template used to load the container when using `bazel run` on this oci_tarball.
See the `loader` attribute to replace the tool which is called.
Please reference the default template to see available substitutions.
""",
allow_single_file = True,
),
Expand Down Expand Up @@ -99,13 +110,13 @@ def _tarball_impl(ctx):
output = exe,
substitutions = {
"{{image_path}}": tarball.short_path,
"{{command}}": ctx.file.command.path if ctx.file.command else "",
"{{loader}}": ctx.file.loader.path if ctx.file.loader else "",
},
is_executable = True,
)
runfiles = [tarball]
if ctx.file.command:
runfiles.append(ctx.file.command)
if ctx.file.loader:
runfiles.append(ctx.file.loader)

return [
DefaultInfo(files = depset([tarball]), runfiles = ctx.runfiles(files = runfiles), executable = exe),
Expand Down
6 changes: 3 additions & 3 deletions oci/private/tarball_run.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
set -o pipefail -o errexit -o nounset

readonly IMAGE="{{image_path}}"
if [ -e "{{command}}" ]; then
CONTAINER_CLI="{{command}}"
if [ -e "{{loader}}" ]; then
CONTAINER_CLI="{{loader}}"
elif command -v docker &> /dev/null; then
CONTAINER_CLI="docker"
elif command -v podman &> /dev/null; then
CONTAINER_CLI="podman"
else
echo >&2 "Neither docker or podman could be found."
echo >&2 "If you wish to use another container runtime, you can pass an executable to the 'command' attribute."
echo >&2 "To use a different container runtime, pass an executable to the 'loader' attribute of oci_tarball."
exit 1
fi

Expand Down

0 comments on commit 6667c5e

Please sign in to comment.