-
Notifications
You must be signed in to change notification settings - Fork 696
Description
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:
- Minikube environment variables injection pre incremental loading Add support for minikube rules_k8s#9.
- Authentication pre (and post) hook for pull and push rules (authentication). #147 (although this should probably have support in the rules).
- Building CI systems.
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