-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit creates a bazel rule that produces an OCI Image Format directory based on a provided OCI Image index. The OCI Image Layout is a standardized OCI format described in https://github.com/opencontainers/image-spec/blob/main/image-layout.md.
- Loading branch information
1 parent
4b76523
commit 1f2aaaf
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
load(":pull.bzl", _oci_pull = "oci_pull") | ||
load(":push.bzl", _oci_push = "oci_push") | ||
load(":image.bzl", _oci_image = "oci_image", _oci_image_index = "oci_image_index", _oci_image_layer = "oci_image_layer") | ||
load(":oci_image_layout.bzl", _oci_image_layout = "oci_image_layout") | ||
|
||
oci_pull = _oci_pull | ||
oci_push = _oci_push | ||
|
||
oci_image = _oci_image | ||
oci_image_index = _oci_image_index | ||
oci_image_layer = _oci_image_layer | ||
oci_image_layout = _oci_image_layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout") | ||
load("@com_github_datadog_rules_oci//oci:debug_flag.bzl", "DebugInfo") | ||
|
||
def _oci_image_layout_impl(ctx): | ||
toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"] | ||
|
||
layout = ctx.attr.manifest[OCILayout] | ||
|
||
out_dir = ctx.actions.declare_directory(ctx.label.name) | ||
|
||
ctx.actions.write( | ||
content = """#!/usr/bin/env bash | ||
set -euo pipefail | ||
{tool} \\ | ||
--layout {layout} \\ | ||
--debug={debug} \\ | ||
create-oci-image-layout \\ | ||
--layout-relative {root} \\ | ||
--desc {desc} \\ | ||
--registry {registry} \\ | ||
--repository {repository} \\ | ||
--out_dir {out_dir} | ||
""".format( | ||
root = ctx.bin_dir.path, | ||
tool = toolchain.sdk.ocitool.short_path, | ||
layout = layout.blob_index.short_path, | ||
desc = ctx.attr.manifest[OCIDescriptor].descriptor_file.short_path, | ||
registry = ctx.attr.registry, | ||
repository = ctx.attr.repository, | ||
out_dir = out_dir, | ||
debug = str(ctx.attr._debug[DebugInfo].debug), | ||
), | ||
output = ctx.outputs.executable, | ||
is_executable = True, | ||
) | ||
|
||
return DefaultInfo(files = depset([out_dir])) | ||
|
||
oci_image_layout = rule( | ||
doc = """ | ||
Writes an OCI Image Index and related blobs to an OCI Image Format | ||
directory. See https://github.com/opencontainers/image-spec/blob/main/image-layout.md | ||
for the specification of the OCI Image Format directory. Local blobs are | ||
used where available, and if a referenced blob is not present, it is | ||
fetched from the provided OCI repository and placed in the output. | ||
""", | ||
implementation = _oci_image_layout_impl, | ||
executable = True, | ||
attrs = { | ||
"manifest": attr.label( | ||
doc = """ | ||
An OCILayout index to be written to the OCI Image Format directory. | ||
""", | ||
providers = [OCILayout], | ||
), | ||
"registry": attr.string( | ||
doc = """ | ||
A registry host that contains images referenced by the OCILayout index, | ||
if not present consult the toolchain. | ||
""", | ||
), | ||
"repository": attr.string( | ||
doc = """ | ||
A repository that contains images referenced by the OCILayout index, | ||
if not present consult the toolchain. | ||
""", | ||
), | ||
"_debug": attr.label( | ||
default = "//oci:debug", | ||
providers = [DebugInfo], | ||
), | ||
}, | ||
provides = [ | ||
DefaultInfo, | ||
], | ||
toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"], | ||
) |