Skip to content

Make the rules easily reusable in workflows. #148

@hsyed

Description

@hsyed

We should be able to reuse the docker rules logic in other rules. Unless I am missing something we can't bazel run from within a bazel run. A lot of this work will be done for rules_k8s it would be great if the problem is addressed in a general way.

Use cases:

What I tried:

Tried to prototype a higher level rule that would get a "handle" to a docker_build runnable and then do something before or after incrementally loading the image.

ci_environment = rule(
  attrs = {
    "platform": attr.label(single_file = True ,executable=True, cfg = "host"),  # <-- docker_build target
  },
  executable=True,
  implementation = _impl
)

Somewhere in the rule

ctx.file_action(
  output=ctx.outputs.executable,
  content="./%s" % ctx.executable.platform.short_path,
  executable=True
)

Problems

It's not straight forward to setup the runtime context of the target rules. I tried to repurpose the logic by studying the internals and this but even if I had managed to get it to work it would not be the way forward as it depends on the internals.

What I hope for

A simple way to reuse the logic in the rules defined here. What would be nicest is a simple handle to the target that I can execute at some arbitrary point in a rule / genrule. If this is not possible some utility functions with examples would be usefull. --e.g.,

def _my_rule_impl(ctx):
  info = DefaultInfo()
  run_docker_build(ctx, ctx.attr.my_image, info)
  // my actions
  return info

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions