Skip to content

Commit

Permalink
chore(docs): mention rules_multirun
Browse files Browse the repository at this point in the history
We get this question a lot so the answer belongs in the docs.
  • Loading branch information
alexeagle committed Aug 25, 2024
1 parent a32f3bf commit 748fbef
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 6 deletions.
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module(
)

bazel_dep(name = "aspect_bazel_lib", version = "2.7.2")
bazel_dep(name = "bazel_features", version = "1.10.0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "bazel_features", version = "1.10.0")

oci = use_extension("//oci:extensions.bzl", "oci")
oci.toolchains()
Expand All @@ -34,3 +34,4 @@ use_repo(bazel_lib, "bsd_tar_toolchains", "jq_toolchains")
bazel_dep(name = "rules_go", version = "0.46.0", dev_dependency = True, repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.35.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "rules_multirun", version = "0.9.0", dev_dependency = True)
31 changes: 31 additions & 0 deletions docs/load.md

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

39 changes: 39 additions & 0 deletions docs/push.md

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

34 changes: 29 additions & 5 deletions examples/push/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@rules_multirun//:defs.bzl", "command", "multirun")
load("//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push")

oci_image(
Expand Down Expand Up @@ -47,11 +48,34 @@ expand_template(
],
)

oci_push(
name = "push_image_index",
image = ":image_index",
remote_tags = ":stamped",
repository = "index.docker.io/<ORG>/image",
######
# Demonstration of how to push to more than one repository
REPOS = {
"index": "index.docker.io/<ORG>/image",
"ECR": "aws_account_id.dkr.ecr.us-west-2.amazonaws.com",
}

[
oci_push(
name = "push_image_" + k,
image = ":image_index",
remote_tags = ":stamped",
repository = v,
)
for (k, v) in REPOS.items()
]

[
command(
name = k,
command = "push_image_" + k,
)
for k in REPOS.keys()
]

multirun(
name = "push_all",
commands = REPOS.keys(),
)

sh_test(
Expand Down
31 changes: 31 additions & 0 deletions oci/private/load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ filegroup(
output_group = "tarball",
)
```
### Multiple images
To load more than one image into the daemon,
use [rules_multirun] to group multiple oci_load targets into one executable target.
This might be useful with a docker-compose workflow, for example.
```starlark
load("@rules_multirun//:defs.bzl", "command", "multirun")
IMAGES = {
"webservice": "//path/to/web-service:image.load",
"backend": "//path/to/backend-service:image.load",
}
[
command(
name = k,
command = v,
)
for (k, v) in IMAGES.items()
]
multirun(
name = "load_all",
commands = IMAGES.keys(),
)
```
[rules_multirun]: https://github.com/keith/rules_multirun
"""

attrs = {
Expand Down
39 changes: 39 additions & 0 deletions oci/private/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,45 @@ oci_push(
remote_tags = ":stamped",
)
```
To push to more than one registry, or using multiple remote tags,
use [rules_multirun] to group multiple oci_push targets into one executable target.
For example:
```starlark
load("@rules_multirun//:defs.bzl", "command", "multirun")
REPOS = {
"index": "index.docker.io/<ORG>/image",
"ECR": "aws_account_id.dkr.ecr.us-west-2.amazonaws.com",
}
[
oci_push(
name = "push_image_" + k,
image = ":image_index",
remote_tags = ":stamped",
repository = v,
)
for (k, v) in REPOS.items()
]
[
command(
name = k,
command = "push_image_" + k,
)
for k in REPOS.keys()
]
multirun(
name = "push_all",
commands = REPOS.keys(),
)
```
[rules_multirun]: https://github.com/keith/rules_multirun
"""

# Helper rule for ensuring that the crane and yq toolchains are actually
Expand Down

0 comments on commit 748fbef

Please sign in to comment.