Skip to content

Commit

Permalink
docs: simplify use of expand_template
Browse files Browse the repository at this point in the history
Also include the aspect_bazel_lib load statement since the bazel_skylib one is broken.
Fixes #512
  • Loading branch information
alexeagle committed Mar 26, 2024
1 parent ac7f6e2 commit ba8d2c3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 58 deletions.
15 changes: 4 additions & 11 deletions docs/push.md

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

12 changes: 2 additions & 10 deletions examples/env/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//oci:defs.bzl", "oci_image")
Expand All @@ -9,20 +8,13 @@ pkg_tar(
srcs = ["test.bash"],
)

write_file(
name = "env_tmpl",
out = "env.txt.tmpl",
content = ["BUILD_VERSION=EMBED_LABEL"],
)

# Use the value of --embed_label under --stamp, otherwise use a deterministic constant
# value to ensure cache hits for actions that depend on this.
expand_template(
name = "env",
out = "env.txt",
stamp_substitutions = {"EMBED_LABEL": "{{BUILD_EMBED_LABEL}}"},
substitutions = {"EMBED_LABEL": "1.2.3"},
template = "env_tmpl",
stamp_substitutions = {"1.2.3": "{{BUILD_EMBED_LABEL}}"},
template = ["BUILD_VERSION=1.2.3"],
)

oci_image(
Expand Down
18 changes: 5 additions & 13 deletions examples/labels/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//oci:defs.bzl", "oci_image")
Expand All @@ -9,23 +8,16 @@ pkg_tar(
srcs = ["test.bash"],
)

write_file(
name = "labels_tmpl",
out = "labels.txt.tmpl",
content = [
"org.opencontainers.image.version=BUILD_VERSION",
"org.opencontainers.image.source=https://github.com/bazel-contrib/rules_oci",
],
)

# Use the value of --embed_label under --stamp, otherwise use a deterministic constant
# value to ensure cache hits for actions that depend on this.
expand_template(
name = "labels",
out = "labels.txt",
stamp_substitutions = {"BUILD_VERSION": "{{BUILD_EMBED_LABEL}}"},
substitutions = {"BUILD_VERSION": "0.0.0"},
template = "labels_tmpl",
stamp_substitutions = {"0.0.0": "{{BUILD_EMBED_LABEL}}"},
template = [
"org.opencontainers.image.version=0.0.0",
"org.opencontainers.image.source=https://github.com/bazel-contrib/rules_oci",
],
)

oci_image(
Expand Down
18 changes: 5 additions & 13 deletions examples/push/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push")

oci_image(
Expand Down Expand Up @@ -36,23 +35,16 @@ oci_image_index(
],
)

write_file(
name = "tags_tmpl",
out = "tags.txt.tmpl",
content = [
"BUILD_VERSION",
"nightly",
],
)

# Use the value of --embed_label under --stamp, otherwise use a deterministic constant
# value to ensure cache hits for actions that depend on this.
expand_template(
name = "stamped",
out = "_stamped.tags.txt",
stamp_substitutions = {"BUILD_VERSION": "{{BUILD_EMBED_LABEL}}"},
substitutions = {"BUILD_VERSION": "0.0.0"},
template = "tags_tmpl",
stamp_substitutions = {"0.0.0": "{{BUILD_EMBED_LABEL}}"},
template = [
"0.0.0",
"nightly",
],
)

oci_push(
Expand Down
15 changes: 4 additions & 11 deletions oci/private/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ oci_push(
Push a multi-architecture image to github container registry with a semver tag
```starlark
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template_rule")
oci_image(name = "app_linux_arm64")
oci_image(name = "app_linux_amd64")
Expand All @@ -77,22 +79,13 @@ oci_image_index(
]
)
write_file(
name = "tags_tmpl",
out = "tags.txt.tmpl",
content = [
"BUILD_VERSION",
],
)
# Use the value of --embed_label under --stamp, otherwise use a deterministic constant
# value to ensure cache hits for actions that depend on this.
expand_template(
name = "stamped",
out = "_stamped.tags.txt",
template = "tags_tmpl",
substitutions = {"BUILD_VERSION": "0.0.0"},
stamp_substitutions = {"BUILD_VERSION": "{{BUILD_EMBED_LABEL}}"},
template = ["0.0.0"],
stamp_substitutions = {"0.0.0": "{{BUILD_EMBED_LABEL}}"},
)
oci_push(
Expand Down

0 comments on commit ba8d2c3

Please sign in to comment.