rules_oci 项目教程
rules_ociBazel rules for building OCI containers项目地址:https://gitcode.com/gh_mirrors/ru/rules_oci
1. 项目的目录结构及介绍
rules_oci
项目的目录结构如下:
rules_oci/
├── examples/
├── tests/
├── WORKSPACE
├── defs.bzl
├── README.md
└── ...
examples/
: 包含一些使用rules_oci
的示例代码。tests/
: 包含项目的测试代码。WORKSPACE
: 项目的启动文件,用于定义项目的依赖和初始化设置。defs.bzl
: 包含项目的规则定义和函数。README.md
: 项目的介绍文档。
2. 项目的启动文件介绍
WORKSPACE
文件是 Bazel 项目的启动文件,用于定义项目的依赖和初始化设置。以下是一个示例:
workspace(name = "rules_oci")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_oci_bootstrap",
url = "https://github.com/DataDog/rules_oci_bootstrap/archive/75330296a80c4a5bfa228dc585ca9a9c3e56d45d.zip",
sha256 = "cc6c59ed7da6bb376552461e06068f883bbe335359c122c15dce3c24e19cd8e2",
strip_prefix = "rules_oci_bootstrap-75330296a80c4a5bfa228dc585ca9a9c3e56d45d",
)
load("@rules_oci_bootstrap//:defs.bzl", "oci_blob_pull")
oci_blob_pull(
name = "com_github_datadog_rules_oci",
digest = "sha256:cc6c59ed7da6bb376552461e06068f883bbe335359c122c15dce3c24e19cd8e2",
extract = True,
registry = "ghcr.io",
repository = "datadog/rules_oci/rules",
type = "tar.gz",
)
3. 项目的配置文件介绍
defs.bzl
文件包含项目的规则定义和函数。以下是一个示例:
def oci_image(name, base, **kwargs):
native.genrule(
name = name + "_manifest",
srcs = [base + ".manifest.json"],
outs = [name + ".manifest.json"],
cmd = "cp $< $@",
)
native.genrule(
name = name + "_config",
srcs = [base + ".config.json"],
outs = [name + ".config.json"],
cmd = "cp $< $@",
)
native.genrule(
name = name + "_layers",
srcs = [base + ".layers.tar"],
outs = [name + ".layers.tar"],
cmd = "cp $< $@",
)
native.genrule(
name = name,
srcs = [
":" + name + "_manifest",
":" + name + "_config",
":" + name + "_layers",
],
outs = [name + ".tar"],
cmd = "tar -cf $@ $^",
)
以上是 rules_oci
项目的基本教程,包含了项目的目录结构、启动文件和配置文件的介绍。希望对你有所帮助!
rules_ociBazel rules for building OCI containers项目地址:https://gitcode.com/gh_mirrors/ru/rules_oci