diff --git a/MODULE.bazel b/MODULE.bazel
index 663bc54..b0c3999 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -48,7 +48,7 @@ go_deps.module_override(
path = "github.com/containerd/containerd",
)
-oci_pull = use_repo_rule("//oci:defs.bzl", "oci_pull")
+oci_pull = use_repo_rule("//oci:repositories.bzl", "oci_pull")
oci_pull(
name = "ubuntu_noble",
diff --git a/bin/BUILD.bazel b/bin/BUILD.bazel
index 076e882..3e3abb4 100755
--- a/bin/BUILD.bazel
+++ b/bin/BUILD.bazel
@@ -1,14 +1,16 @@
+load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
load("//oci:toolchain.bzl", "create_compiled_oci_toolchains")
exports_files(glob(["*"]))
-filegroup(
- name = "bin-files",
+create_compiled_oci_toolchains(name = "oci_toolchain")
+
+pkg_files(
+ name = "files",
srcs = glob([
"*.bzl",
"*.bazel",
]),
- visibility = ["//visibility:public"],
+ prefix = "bin",
+ visibility = ["//release:__subpackages__"],
)
-
-create_compiled_oci_toolchains(name = "oci_toolchain")
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index b6ed035..92e4be1 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -1,12 +1,18 @@
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")
-exports_files(["docs.md"])
-
-# Sourced from https://github.com/bazelbuild/rules_go/pull/3000
-# For each doc file, generate MD from bzl_library, then perform diff test
stardoc_with_diff_test(
- name = "docs",
+ name = "defs",
bzl_library_target = "//oci:defs",
)
+stardoc_with_diff_test(
+ name = "providers",
+ bzl_library_target = "//oci:providers",
+)
+
+stardoc_with_diff_test(
+ name = "repositories",
+ bzl_library_target = "//oci:repositories",
+)
+
update_docs()
diff --git a/docs/docs.md b/docs/defs.md
similarity index 83%
rename from docs/docs.md
rename to docs/defs.md
index 4678429..82aa6fa 100644
--- a/docs/docs.md
+++ b/docs/defs.md
@@ -1,6 +1,6 @@
-public API
+public rules
@@ -122,30 +122,3 @@ Pushes a manifest or a list of manifests to an OCI registry.
| x_meta_headers | (optional) A list of key/values to to be sent to the registry as headers with an X-Meta- prefix. | Dictionary: String -> String | optional | `{}` |
-
-
-## oci_pull
-
-
-oci_pull(name, debug, digest, registry, repo_mapping, repository, shallow)
-
-
-**ATTRIBUTES**
-
-
-| Name | Description | Type | Mandatory | Default |
-| :------------- | :------------- | :------------- | :------------- | :------------- |
-| name | A unique name for this repository. | Name | required | |
-| debug | Enable ocitool debug output | Boolean | optional | `False` |
-| digest | - | String | required | |
-| registry | - | String | required | |
-| repo_mapping | In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.
For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).
This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | Dictionary: String -> String | optional | |
-| repository | - | String | required | |
-| shallow | - | Boolean | optional | `True` |
-
-**ENVIRONMENT VARIABLES**
-
-This repository rule depends on the following environment variables:
-* `OCI_CACHE_DIR`
-
-
diff --git a/docs/providers.md b/docs/providers.md
new file mode 100644
index 0000000..5ac632e
--- /dev/null
+++ b/docs/providers.md
@@ -0,0 +1,126 @@
+
+
+public providers
+
+
+
+## OCIDescriptor
+
+
+OCIDescriptor(file, descriptor_file, media_type, size, urls, digest, annotations)
+
+
+
+
+**FIELDS**
+
+
+| Name | Description |
+| :------------- | :------------- |
+| file | A file object of the content this descriptor describes |
+| descriptor_file | A file object with the information in this provider |
+| media_type | The MIME media type of the file |
+| size | The size in bytes of the file |
+| urls | Additional URLs where you can find the content of file |
+| digest | A digest, including the algorithm, of the file |
+| annotations | String map of aribtrary metadata |
+
+
+
+
+## OCIImageIndexManifest
+
+
+OCIImageIndexManifest(manifests, annotations)
+
+
+
+
+**FIELDS**
+
+
+| Name | Description |
+| :------------- | :------------- |
+| manifests | List of descriptors |
+| annotations | String map of arbitrary metadata |
+
+
+
+
+## OCIImageManifest
+
+
+OCIImageManifest(config, layers, annotations)
+
+
+
+
+**FIELDS**
+
+
+| Name | Description |
+| :------------- | :------------- |
+| config | Descriptor that points to a configuration object |
+| layers | List of descriptors |
+| annotations | String map of arbitrary metadata |
+
+
+
+
+## OCILayout
+
+
+OCILayout(blob_index, files)
+
+
+OCI Layout
+
+**FIELDS**
+
+
+| Name | Description |
+| :------------- | :------------- |
+| blob_index | - |
+| files | - |
+
+
+
+
+## OCIReferenceInfo
+
+
+OCIReferenceInfo(registry, repository, tag, tag_file, digest)
+
+
+Refers to any artifact represented by an OCI-like reference URI
+
+**FIELDS**
+
+
+| Name | Description |
+| :------------- | :------------- |
+| registry | the URI where the artifact is stored |
+| repository | a namespace for an artifact |
+| tag | a organizational reference within a repository |
+| tag_file | a file containing the organizational reference within a repository |
+| digest | a file containing the digest of the artifact |
+
+
+
+
+## OCISDK
+
+
+OCISDK(ocitool)
+
+
+The OCI SDK
+
+**FIELDS**
+
+
+| Name | Description |
+| :------------- | :------------- |
+| ocitool | - |
+
+
diff --git a/docs/repositories.md b/docs/repositories.md
new file mode 100644
index 0000000..92a0463
--- /dev/null
+++ b/docs/repositories.md
@@ -0,0 +1,31 @@
+
+
+public repository rules
+
+
+
+## oci_pull
+
+
+oci_pull(name, debug, digest, registry, repo_mapping, repository, shallow)
+
+
+**ATTRIBUTES**
+
+
+| Name | Description | Type | Mandatory | Default |
+| :------------- | :------------- | :------------- | :------------- | :------------- |
+| name | A unique name for this repository. | Name | required | |
+| debug | Enable ocitool debug output | Boolean | optional | `False` |
+| digest | - | String | required | |
+| registry | - | String | required | |
+| repo_mapping | In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.
For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).
This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | Dictionary: String -> String | optional | |
+| repository | - | String | required | |
+| shallow | - | Boolean | optional | `True` |
+
+**ENVIRONMENT VARIABLES**
+
+This repository rule depends on the following environment variables:
+* `OCI_CACHE_DIR`
+
+
diff --git a/tests/go-multiarch-image/BUILD.bazel b/examples/go-multiarch-image/BUILD.bazel
similarity index 76%
rename from tests/go-multiarch-image/BUILD.bazel
rename to examples/go-multiarch-image/BUILD.bazel
index 18a545a..5cb0f9b 100644
--- a/tests/go-multiarch-image/BUILD.bazel
+++ b/examples/go-multiarch-image/BUILD.bazel
@@ -1,4 +1,3 @@
-load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@com_github_datadog_rules_oci//oci:defs.bzl", "oci_push")
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load(":go.bzl", "go_multiarch_image")
@@ -33,13 +32,3 @@ oci_push(
registry = "ghcr.io",
repository = "datadog/rules_oci/hello-world",
)
-
-bzl_library(
- name = "go",
- srcs = ["go.bzl"],
- visibility = ["//visibility:public"],
- deps = [
- "@com_github_datadog_rules_oci//oci:defs",
- "@rules_go//go:def",
- ],
-)
diff --git a/tests/go-multiarch-image/go.bzl b/examples/go-multiarch-image/go.bzl
similarity index 100%
rename from tests/go-multiarch-image/go.bzl
rename to examples/go-multiarch-image/go.bzl
diff --git a/tests/go-multiarch-image/main.go b/examples/go-multiarch-image/main.go
similarity index 100%
rename from tests/go-multiarch-image/main.go
rename to examples/go-multiarch-image/main.go
diff --git a/go/pkg/ociutil/bazel.go b/go/pkg/ociutil/bazel.go
index 66352a2..a4dad16 100644
--- a/go/pkg/ociutil/bazel.go
+++ b/go/pkg/ociutil/bazel.go
@@ -26,10 +26,10 @@ func GenerateBuildFilesHandler(handler images.HandlerFunc, layoutRoot string, pr
blobBuildFiles[digest.SHA256] = rule.EmptyFile(algoBUILDPath(layoutRoot, digest.SHA256), "")
// Add load statements for all of the oci_* rules
- ldBlob := rule.NewLoad("@com_github_datadog_rules_oci//oci:blob.bzl")
+ ldBlob := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:blob.bzl")
ldBlob.Add("oci_blob")
- ldManifest := rule.NewLoad("@com_github_datadog_rules_oci//oci:manifests.bzl")
+ ldManifest := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:manifests.bzl")
ldManifest.Add("oci_image_index_manifest")
ldManifest.Add("oci_image_manifest")
@@ -42,7 +42,7 @@ func GenerateBuildFilesHandler(handler images.HandlerFunc, layoutRoot string, pr
// Top level build file for used as an index of the entire layout
layoutBuild := rule.EmptyFile(filepath.Join(layoutRoot, "BUILD.bazel"), "")
- ldLayout := rule.NewLoad("@com_github_datadog_rules_oci//oci:layout.bzl")
+ ldLayout := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:layout.bzl")
ldLayout.Add("oci_layout_index")
ldLayout.Insert(layoutBuild, 0)
diff --git a/oci/BUILD.bazel b/oci/BUILD.bazel
index eff474d..bfacc92 100644
--- a/oci/BUILD.bazel
+++ b/oci/BUILD.bazel
@@ -1,105 +1,66 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-load(":debug_flag.bzl", "debug_flag")
+load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
+load("//oci/private:debug_flag.bzl", "debug_flag")
# gazelle:lang go,starlark
-exports_files(["defs.bzl"])
+exports_files(
+ glob(["*.bzl"]),
+ visibility = ["//:__subpackages__"],
+)
toolchain_type(
name = "toolchain",
visibility = ["//visibility:public"],
)
-filegroup(
- name = "oci-files",
- srcs = glob([
- "*.bzl",
- "*.bazel",
- ]),
- visibility = ["//visibility:public"],
-)
-
debug_flag(
name = "debug",
build_setting_default = False,
visibility = ["//visibility:public"],
)
-bzl_library(
- name = "blob",
- srcs = ["blob.bzl"],
- visibility = ["//visibility:public"],
- deps = ["@com_github_datadog_rules_oci//oci:providers"],
-)
-
bzl_library(
name = "defs",
- srcs = ["defs.bzl"],
+ srcs = [
+ ":defs.bzl",
+ ],
visibility = ["//visibility:public"],
deps = [
- ":image",
- ":oci_image_layout",
- ":pull",
- ":push",
+ "//oci:providers.bzl",
+ "//oci/private:debug_flag.bzl",
+ "//oci/private:image.bzl",
+ "//oci/private:oci_image_layout.bzl",
+ "//oci/private:push.bzl",
+ "@aspect_bazel_lib//lib:stamping",
],
)
bzl_library(
- name = "image",
- srcs = ["image.bzl"],
- visibility = ["//visibility:public"],
- deps = ["@com_github_datadog_rules_oci//oci:providers"],
-)
-
-bzl_library(
- name = "layout",
- srcs = ["layout.bzl"],
- visibility = ["//visibility:public"],
- deps = ["@com_github_datadog_rules_oci//oci:providers"],
-)
-
-bzl_library(
- name = "manifests",
- srcs = ["manifests.bzl"],
+ name = "providers",
+ srcs = [
+ ":providers.bzl",
+ ],
visibility = ["//visibility:public"],
- deps = ["@com_github_datadog_rules_oci//oci:providers"],
)
bzl_library(
- name = "oci_image_layout",
- srcs = ["oci_image_layout.bzl"],
- visibility = ["//visibility:public"],
- deps = [
- "@com_github_datadog_rules_oci//oci:debug_flag",
- "@com_github_datadog_rules_oci//oci:providers",
+ name = "repositories",
+ srcs = [
+ ":repositories.bzl",
],
-)
-
-bzl_library(
- name = "push",
- srcs = ["push.bzl"],
visibility = ["//visibility:public"],
deps = [
- "@aspect_bazel_lib//lib:stamping",
- "@com_github_datadog_rules_oci//oci:debug_flag",
- "@com_github_datadog_rules_oci//oci:providers",
+ "//oci/private/repositories:pull.bzl",
],
)
-bzl_library(
- name = "debug_flag",
- srcs = ["debug_flag.bzl"],
- visibility = ["//visibility:public"],
-)
-
-bzl_library(
- name = "providers",
- srcs = ["providers.bzl"],
- visibility = ["//visibility:public"],
-)
-
-bzl_library(
- name = "pull",
- srcs = ["pull.bzl"],
- visibility = ["//visibility:public"],
+pkg_files(
+ name = "files",
+ srcs = glob([
+ "*.bzl",
+ "*.bazel",
+ ]),
+ prefix = "oci",
+ visibility = ["//release:__subpackages__"],
)
diff --git a/oci/defs.bzl b/oci/defs.bzl
index 5f461f4..f82b509 100644
--- a/oci/defs.bzl
+++ b/oci/defs.bzl
@@ -1,14 +1,16 @@
-""" public API """
+""" public rules """
-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")
-load(":pull.bzl", _oci_pull = "oci_pull")
-load(":push.bzl", _oci_push = "oci_push")
-
-oci_pull = _oci_pull
-oci_push = _oci_push
+load(
+ "//oci/private:image.bzl",
+ _oci_image = "oci_image",
+ _oci_image_index = "oci_image_index",
+ _oci_image_layer = "oci_image_layer",
+)
+load("//oci/private:oci_image_layout.bzl", _oci_image_layout = "oci_image_layout")
+load("//oci/private:push.bzl", _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
+oci_push = _oci_push
diff --git a/oci/private/BUILD.bazel b/oci/private/BUILD.bazel
new file mode 100644
index 0000000..bf21dcf
--- /dev/null
+++ b/oci/private/BUILD.bazel
@@ -0,0 +1,16 @@
+load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
+
+exports_files(
+ glob(["*.bzl"]),
+ visibility = ["//oci:__subpackages__"],
+)
+
+pkg_files(
+ name = "files",
+ srcs = glob([
+ "*.bzl",
+ "*.bazel",
+ ]),
+ prefix = "oci/private",
+ visibility = ["//release:__subpackages__"],
+)
diff --git a/oci/debug_flag.bzl b/oci/private/debug_flag.bzl
similarity index 100%
rename from oci/debug_flag.bzl
rename to oci/private/debug_flag.bzl
diff --git a/oci/image.bzl b/oci/private/image.bzl
similarity index 95%
rename from oci/image.bzl
rename to oci/private/image.bzl
index 8727bf1..b1cb5f3 100644
--- a/oci/image.bzl
+++ b/oci/private/image.bzl
@@ -1,6 +1,6 @@
""" image """
-load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout")
+load("//oci:providers.bzl", "OCIDescriptor", "OCILayout")
# buildifier: disable=function-docstring
def get_descriptor_file(ctx, desc):
@@ -22,7 +22,7 @@ def get_descriptor_file(ctx, desc):
return out
def _oci_image_layer_impl(ctx):
- toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"]
+ toolchain = ctx.toolchains["//oci:toolchain"]
descriptor_file = ctx.actions.declare_file("{}.descriptor.json".format(ctx.label.name))
@@ -71,14 +71,14 @@ oci_image_layer = rule(
allow_files = True,
),
},
- toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],
+ toolchains = ["//oci:toolchain"],
outputs = {
"layer": "%{name}-layer.tar.gz",
},
)
def _oci_image_index_impl(ctx):
- toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"]
+ toolchain = ctx.toolchains["//oci:toolchain"]
layout_files = depset(None, transitive = [m[OCILayout].files for m in ctx.attr.manifests])
@@ -138,11 +138,11 @@ oci_image_index = rule(
""",
),
},
- toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],
+ toolchains = ["//oci:toolchain"],
)
def _oci_image_impl(ctx):
- toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"]
+ toolchain = ctx.toolchains["//oci:toolchain"]
base_desc = get_descriptor_file(ctx, ctx.attr.base[OCIDescriptor])
base_layout = ctx.attr.base[OCILayout]
@@ -282,5 +282,5 @@ oci_image = rule(
then the value of annotations will be used instead.""",
),
},
- toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],
+ toolchains = ["//oci:toolchain"],
)
diff --git a/oci/oci_image_layout.bzl b/oci/private/oci_image_layout.bzl
similarity index 89%
rename from oci/oci_image_layout.bzl
rename to oci/private/oci_image_layout.bzl
index ce631d1..d8fc0ef 100644
--- a/oci/oci_image_layout.bzl
+++ b/oci/private/oci_image_layout.bzl
@@ -1,10 +1,10 @@
"""A rule to create a directory in OCI Image Layout format."""
-load("@com_github_datadog_rules_oci//oci:debug_flag.bzl", "DebugInfo")
-load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout")
+load("//oci:providers.bzl", "OCIDescriptor", "OCILayout")
+load(":debug_flag.bzl", "DebugInfo")
def _oci_image_layout_impl(ctx):
- toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"]
+ toolchain = ctx.toolchains["//oci:toolchain"]
layout = ctx.attr.manifest[OCILayout]
@@ -70,5 +70,5 @@ oci_image_layout = rule(
provides = [
DefaultInfo,
],
- toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],
+ toolchains = ["//oci:toolchain"],
)
diff --git a/oci/push.bzl b/oci/private/push.bzl
similarity index 94%
rename from oci/push.bzl
rename to oci/private/push.bzl
index 2a05ccc..bda0af3 100644
--- a/oci/push.bzl
+++ b/oci/private/push.bzl
@@ -1,11 +1,11 @@
""" push """
load("@aspect_bazel_lib//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
-load("@com_github_datadog_rules_oci//oci:debug_flag.bzl", "DebugInfo")
-load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout", "OCIReferenceInfo")
+load("//oci:providers.bzl", "OCIDescriptor", "OCILayout", "OCIReferenceInfo")
+load(":debug_flag.bzl", "DebugInfo")
def _oci_push_impl(ctx):
- toolchain = ctx.toolchains["@com_github_datadog_rules_oci//oci:toolchain"]
+ toolchain = ctx.toolchains["//oci:toolchain"]
layout = ctx.attr.manifest[OCILayout]
@@ -202,5 +202,5 @@ oci_push = rule(
provides = [
OCIReferenceInfo,
],
- toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],
+ toolchains = ["//oci:toolchain"],
)
diff --git a/oci/private/repositories/BUILD.bazel b/oci/private/repositories/BUILD.bazel
new file mode 100644
index 0000000..6bbce16
--- /dev/null
+++ b/oci/private/repositories/BUILD.bazel
@@ -0,0 +1,16 @@
+load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
+
+exports_files(
+ glob(["*.bzl"]),
+ visibility = ["//oci:__subpackages__"],
+)
+
+pkg_files(
+ name = "files",
+ srcs = glob([
+ "*.bzl",
+ "*.bazel",
+ ]),
+ prefix = "oci/private/repositories",
+ visibility = ["//release:__subpackages__"],
+)
diff --git a/oci/blob.bzl b/oci/private/repositories/blob.bzl
similarity index 100%
rename from oci/blob.bzl
rename to oci/private/repositories/blob.bzl
diff --git a/oci/layout.bzl b/oci/private/repositories/layout.bzl
similarity index 100%
rename from oci/layout.bzl
rename to oci/private/repositories/layout.bzl
diff --git a/oci/manifests.bzl b/oci/private/repositories/manifests.bzl
similarity index 90%
rename from oci/manifests.bzl
rename to oci/private/repositories/manifests.bzl
index 9fb298e..af02e58 100644
--- a/oci/manifests.bzl
+++ b/oci/private/repositories/manifests.bzl
@@ -1,6 +1,12 @@
""" manifests """
-load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCIImageIndexManifest", "OCIImageManifest", "OCILayout")
+load(
+ "@com_github_datadog_rules_oci//oci:providers.bzl",
+ "OCIDescriptor",
+ "OCIImageIndexManifest",
+ "OCIImageManifest",
+ "OCILayout",
+)
def _oci_image_manifest_impl(ctx):
return [OCIImageManifest(
diff --git a/oci/pull.bzl b/oci/private/repositories/pull.bzl
similarity index 100%
rename from oci/pull.bzl
rename to oci/private/repositories/pull.bzl
diff --git a/oci/providers.bzl b/oci/providers.bzl
index 7b992cd..d22ff88 100644
--- a/oci/providers.bzl
+++ b/oci/providers.bzl
@@ -1,4 +1,4 @@
-""" providers """
+""" public providers """
OCIReferenceInfo = provider(
doc = "Refers to any artifact represented by an OCI-like reference URI",
@@ -53,14 +53,9 @@ OCIImageIndexManifest = provider(
},
)
-# buildifier: disable=name-conventions
-OCIPlatform = provider(
- doc = "Platform describes the platform which the image in the manifest runs on",
+OCISDK = provider(
+ "The OCI SDK",
fields = {
- "architecture": "Architecture field specifies the CPU architecture, in the GOARCH format.",
- "os": "OS specifies the operating system, in the GOOS format.",
- "os_version": "OSVersion is an optional field specifying the operating system version",
- "os_features": "OSFeatures is an optional field specifying an array of strings, each listing a required OS feature",
- "variant": "Variant is an optional field specifying a variant of the CPU",
+ "ocitool": "",
},
)
diff --git a/oci/repositories.bzl b/oci/repositories.bzl
new file mode 100644
index 0000000..28c1ff6
--- /dev/null
+++ b/oci/repositories.bzl
@@ -0,0 +1,5 @@
+""" public repository rules """
+
+load("//oci/private/repositories:pull.bzl", _oci_pull = "oci_pull")
+
+oci_pull = _oci_pull
diff --git a/oci/toolchain.bzl b/oci/toolchain.bzl
index 4243006..d8811a9 100644
--- a/oci/toolchain.bzl
+++ b/oci/toolchain.bzl
@@ -1,5 +1,7 @@
""" toolchain """
+load(":providers.bzl", "OCISDK")
+
# Follow golang's conventions for naming os and arch
OS_CONSTRAINTS = {
"darwin": "@platforms//os:osx",
@@ -11,13 +13,6 @@ ARCH_CONSTRAINTS = {
"arm64": "@platforms//cpu:arm64",
}
-OCISDK = provider(
- "The OCI SDK",
- fields = {
- "ocitool": "",
- },
-)
-
def _oci_toolchain_impl(ctx):
return [platform_common.ToolchainInfo(
sdk = ctx.attr.sdk[OCISDK],
diff --git a/release/BUILD.bazel b/release/BUILD.bazel
index e8ed3b2..b5a81dd 100644
--- a/release/BUILD.bazel
+++ b/release/BUILD.bazel
@@ -1,15 +1,22 @@
-load(":release.bzl", "go_binary_multi", "release_rules_oci")
+load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
+load(":pkg_go_binary_multiple_platforms.bzl", "pkg_go_binary_multiple_platforms")
-go_binary_multi(
- name = "ocitool",
- embed = ["//go/cmd/ocitool:go_default_library"],
-)
-
-release_rules_oci(
+pkg_tar(
name = "release",
- binaries = [
- ":ocitool.all",
- "//bin:bin-files",
+ srcs = [
+ ":ocitool",
+ "//bin:files",
+ "//oci:files",
+ "//oci/private:files",
+ "//oci/private/repositories:files",
],
- rules = ["//oci:oci-files"],
+ empty_files = ["BUILD.bazel"],
+ extension = "tar.gz",
+)
+
+pkg_go_binary_multiple_platforms(
+ name = "ocitool",
+ go_binary = ["//go/cmd/ocitool:go_default_library"],
+ mode = "0755",
+ prefix = "bin",
)
diff --git a/release/pkg_go_binary_multiple_platforms.bzl b/release/pkg_go_binary_multiple_platforms.bzl
new file mode 100644
index 0000000..d63c604
--- /dev/null
+++ b/release/pkg_go_binary_multiple_platforms.bzl
@@ -0,0 +1,59 @@
+""" pkg_go_binary_multiple_platforms """
+
+load("@rules_go//go:def.bzl", _go_binary = "go_binary")
+load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
+
+_GOOSS = ["darwin", "linux"]
+_GOARCHS = ["amd64", "arm64"]
+
+# buildifier: disable=function-docstring
+def pkg_go_binary_multiple_platforms(
+ *,
+ name, # str
+ go_binary, # label
+ mode, # str
+ prefix, # str | None
+ **kwargs):
+ """ pkg_go_binary_multiple_platforms
+
+ Creates a pkg_files target called that includes multiple go binary
+ executables (one for each platform) based off the provided go binary target.
+
+ In other words, the following 4 exectuable will be included in the pkg_files
+ target called :
+ - -darwin-amd64
+ - -darwin-arm64
+ - -linux-amd64
+ - -linux-arm64
+
+ Args:
+ name:
+ - The name of the pkg_files target to create
+ - Also determines the names of the executables insde the pkg_files
+ target, which will be of the form "--".
+ go_binary: The go_binary target to embed multiple versions of
+ mode: The mode of the executables in pkg_files
+ prefix: The prefix to pass to pkg_files
+ **kwargs: Additional arguments to pass to pkg_files
+ """
+ all_binaries = []
+ for goos in _GOOSS:
+ for goarch in _GOARCHS:
+ bin_name = "{}-{}-{}".format(name, goos, goarch)
+ _go_binary(
+ name = bin_name,
+ embed = go_binary,
+ goos = goos,
+ goarch = goarch,
+ )
+ all_binaries.append(bin_name)
+
+ pkg_files(
+ name = name,
+ srcs = all_binaries,
+ attributes = pkg_attributes(
+ mode = mode,
+ ),
+ prefix = prefix,
+ **kwargs
+ )
diff --git a/release/release.bzl b/release/release.bzl
deleted file mode 100644
index e255076..0000000
--- a/release/release.bzl
+++ /dev/null
@@ -1,73 +0,0 @@
-""" release """
-
-load("@rules_go//go:def.bzl", "go_binary")
-load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
-
-DEFAULT_GOOSS = ["linux", "darwin"]
-DEFAULT_GOARCHS = ["amd64", "arm64"]
-
-# buildifier: disable=function-docstring
-def go_binary_multi(name, embed, gooss = DEFAULT_GOOSS, goarchs = DEFAULT_GOARCHS, **kwargs):
- if "goos" in kwargs or "goarch" in kwargs:
- fail("go_binary_multi does not allow goos or goarch in kwargs")
-
- go_binary(
- name = name,
- embed = embed,
- **kwargs
- )
-
- all_binaries = []
- for goos in gooss:
- for goarch in goarchs:
- bin_name = "{}-{}-{}".format(name, goos, goarch)
- go_binary(
- name = bin_name,
- embed = embed,
- goos = goos,
- goarch = goarch,
- tags = ["manual"],
- **kwargs
- )
- all_binaries.append(bin_name)
-
- all_bin_name = "{}.all".format(name)
- native.filegroup(
- name = all_bin_name,
- srcs = all_binaries,
- )
-
-# buildifier: disable=function-docstring
-def release_rules_oci(name, rules, binaries, **kwargs):
- top_name = "{}.top".format(name)
- pkg_tar(
- name = top_name,
- empty_files = ["BUILD.bazel"],
- package_dir = "",
- )
-
- rules_name = "{}.rules".format(name)
- pkg_tar(
- name = rules_name,
- srcs = rules,
- package_dir = "/oci",
- )
-
- binaries_name = "{}.bin".format(name)
- pkg_tar(
- name = binaries_name,
- srcs = binaries,
- mode = "0755",
- package_dir = "/bin",
- )
-
- pkg_tar(
- name = name,
- extension = "tar.gz",
- deps = [
- rules_name,
- binaries_name,
- top_name,
- ],
- **kwargs
- )