Skip to content

Commit

Permalink
chore(docs): mention rules_multirun (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored Aug 27, 2024
1 parent ec55eb4 commit 22d915a
Show file tree
Hide file tree
Showing 8 changed files with 189 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)
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ load("//oci:repositories.bzl", "oci_register_toolchains")

oci_register_toolchains(name = "oci")

# Transitive dep for rules_multirun
load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

## Setup bazel-lib
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")

Expand Down
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
13 changes: 13 additions & 0 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ def rules_oci_internal_deps():
"https://github.com/bazelbuild/stardoc/releases/download/0.5.6/stardoc-0.5.6.tar.gz",
],
)

http_archive(
name = "rules_multirun",
sha256 = "0e124567fa85287874eff33a791c3bbdcc5343329a56faa828ef624380d4607c",
url = "https://github.com/keith/rules_multirun/releases/download/0.9.0/rules_multirun.0.9.0.tar.gz",
)

http_archive(
name = "rules_python",
sha256 = "be04b635c7be4604be1ef20542e9870af3c49778ce841ee2d92fcb42f9d9516a",
strip_prefix = "rules_python-0.35.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.35.0/rules_python-0.35.0.tar.gz",
)
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 22d915a

Please sign in to comment.