From 22d915ab446cdfcd5377683054f8a4b77d904413 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 26 Aug 2024 21:26:53 -0700 Subject: [PATCH] chore(docs): mention rules_multirun (#681) --- MODULE.bazel | 3 ++- WORKSPACE | 5 +++++ docs/load.md | 31 +++++++++++++++++++++++++++++++ docs/push.md | 39 +++++++++++++++++++++++++++++++++++++++ examples/push/BUILD.bazel | 34 +++++++++++++++++++++++++++++----- internal_deps.bzl | 13 +++++++++++++ oci/private/load.bzl | 31 +++++++++++++++++++++++++++++++ oci/private/push.bzl | 39 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 189 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 1cc10538..37eba0dc 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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() @@ -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) diff --git a/WORKSPACE b/WORKSPACE index fb94df19..8708aa9d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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") diff --git a/docs/load.md b/docs/load.md index 4de816e1..b79e4e37 100644 --- a/docs/load.md +++ b/docs/load.md @@ -57,6 +57,37 @@ filegroup( ) ``` +### 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 + **ATTRIBUTES** diff --git a/docs/push.md b/docs/push.md index 4c35d58b..39c1c7d1 100644 --- a/docs/push.md +++ b/docs/push.md @@ -111,6 +111,45 @@ oci_push( ) ``` +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 + **ATTRIBUTES** diff --git a/examples/push/BUILD.bazel b/examples/push/BUILD.bazel index a327bd6d..66f82dee 100644 --- a/examples/push/BUILD.bazel +++ b/examples/push/BUILD.bazel @@ -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( @@ -47,11 +48,34 @@ expand_template( ], ) -oci_push( - name = "push_image_index", - image = ":image_index", - remote_tags = ":stamped", - repository = "index.docker.io//image", +###### +# Demonstration of how to push to more than one repository +REPOS = { + "index": "index.docker.io//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( diff --git a/internal_deps.bzl b/internal_deps.bzl index 759ed424..97edf3e1 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -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", + ) diff --git a/oci/private/load.bzl b/oci/private/load.bzl index be62b202..f9b6874f 100644 --- a/oci/private/load.bzl +++ b/oci/private/load.bzl @@ -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 = { diff --git a/oci/private/push.bzl b/oci/private/push.bzl index 22b691dd..38961dbe 100644 --- a/oci/private/push.bzl +++ b/oci/private/push.bzl @@ -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//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