Skip to content

Commit 940bd34

Browse files
committed
Distribute rules via http_archive
1 parent 8c5b324 commit 940bd34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2095
-444
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
examples
12
node_modules

.github/workflows/main.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ on:
44
branches: [main]
55
pull_request:
66
workflow_dispatch:
7+
env:
8+
CI: 1
79
jobs:
810
ci:
911
runs-on: ubuntu-latest
1012
steps:
1113
- uses: actions/checkout@v2
1214
- uses: bazelbuild/setup-bazelisk@v1
13-
- run: bazel test --config=ci //...
14-
- run: bazel run //:gazelle -- -mode diff || exit 1
15+
- uses: extractions/setup-just@6e1de3cc407de738551abd6c0923bd5ed5608042
16+
with:
17+
just-version: "1.38.0"
18+
- run: just test

BUILD.bazel

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
1+
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
22
load("@npm//:defs.bzl", "npm_link_all_packages")
33
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
44

@@ -20,6 +20,17 @@ gazelle(
2020
gazelle = ":gazelle-binary",
2121
)
2222

23+
gazelle(
24+
name = "gazelle-update-repos",
25+
args = [
26+
"-build_file_proto_mode=disable",
27+
"-from_file=go.mod",
28+
"-prune=true",
29+
"-to_macro=oci/private/repositories/go_repositories.bzl%go_repositories",
30+
],
31+
command = "update-repos",
32+
)
33+
2334
gazelle_binary(
2435
name = "gazelle-binary",
2536
languages = DEFAULT_LANGUAGES + [
@@ -38,6 +49,7 @@ pkg_tar(
3849
"//oci:files",
3950
"//oci/private:files",
4051
"//oci/private/repositories:files",
52+
"//oci/repositories:files",
4153
],
4254
empty_files = ["BUILD.bazel"],
4355
extension = "tar.gz",

MODULE.bazel

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,55 @@ module(
33
repo_name = "com_github_datadog_rules_oci",
44
)
55

6+
# 2024-05-08
67
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
8+
9+
# 2024-12-04
710
bazel_dep(name = "aspect_rules_js", version = "2.1.2")
11+
12+
# 2024-12
813
bazel_dep(name = "aspect_rules_lint", version = "1.0.8")
14+
15+
# 2024-04-25
916
bazel_dep(name = "bazel_skylib", version = "1.6.1")
10-
bazel_dep(name = "gazelle", version = "0.38.0")
17+
18+
# 2024-08-01
19+
bazel_dep(name = "gazelle", version = "0.38.0", repo_name = "bazel_gazelle")
20+
21+
# 2024-05-06
1122
bazel_dep(name = "rules_go", version = "0.47.1", repo_name = "io_bazel_rules_go")
23+
24+
# 2024-11-06
1225
bazel_dep(name = "rules_nodejs", version = "6.3.2")
26+
27+
# 2024-02-08
1328
bazel_dep(name = "rules_pkg", version = "0.10.1")
29+
30+
# 2023-08-11
1431
bazel_dep(name = "stardoc", version = "0.6.2")
1532

33+
# 2024-04-25
1634
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.6.1", dev_dependency = True)
35+
36+
# 2024-08-27
1737
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)
1838

39+
single_version_override(
40+
module_name = "bazel_skylib_gazelle_plugin",
41+
patch_strip = 2,
42+
patches = [
43+
"//third_party/com_github_bazelbuild_bazel-skylib:01-pr-535-support-resolve.patch",
44+
],
45+
)
46+
1947
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
2048
go_sdk.download(
2149
name = "go_sdk",
2250
version = "1.22.5",
2351
)
2452
use_repo(go_sdk, "go_sdk")
2553

26-
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
54+
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
2755
go_deps.from_file(go_mod = "//:go.mod")
2856
use_repo(
2957
go_deps,
@@ -36,7 +64,6 @@ use_repo(
3664
"com_github_sirupsen_logrus",
3765
"com_github_stretchr_testify",
3866
"com_github_urfave_cli_v2",
39-
"land_oras_oras_go",
4067
)
4168
go_deps.module_override(
4269
patch_strip = 1,
@@ -46,7 +73,7 @@ go_deps.module_override(
4673
path = "github.com/containerd/containerd",
4774
)
4875

49-
oci_pull = use_repo_rule("//oci:repositories.bzl", "oci_pull")
76+
oci_pull = use_repo_rule("//oci:defs.bzl", "oci_pull")
5077

5178
oci_pull(
5279
name = "ubuntu_noble",

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 41 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,58 @@
1-
## `rules_oci` - blazing fast Bazel rules for building OCI Images
1+
## `rules_oci` - Bazel rules for building OCI Images
22

33
RULES_OCI IS HIGHLY EXPERIMENTAL WITH PLANNED BREAKING CHANGES, PLEASE DO NOT
44
DEPEND ON FOR PRODUCTION USE-CASES.
55

66
A Bazel rule-set for extending, creating and publishing OCI artifacts, including image
7-
manifests, image indexes (multi-arch images) and custom artifacts
8-
([ORAS](https://github.com/oras-project)), with a focus on:
7+
manifests and image indexes (multi-arch images), with a focus on:
98

10-
- **Speed**, only pulling artifacts that are needed at build-time (no more long image pull times)
11-
- **Extensibility**, creating custom artifacts to leverage standard OCI distribution
12-
APIs
9+
- **Extensibility**, creating custom artifacts to leverage standard OCI distribution APIs
1310
- **Multi-arch images**, compiling and building multi-arch images with a single Bazel invocation
1411

15-
In addition to Bazel rules, we offer many helpers for interacting with OCI
16-
artifacts under the `go/pkg` directory and a CLI tool for creating new OCI
17-
artifacts.
18-
19-
`rules_oci` makes an effort to support Docker media types, but there is no
20-
guarantee of long-term support. Most CRI support the OCI types or there are
21-
tools available to convert [between the
22-
specifications](https://github.com/opencontainers/image-spec/blob/v1.0.2/conversion.md).
23-
2412
### Setup
2513

26-
```
27-
# Load OCI Bootstrapping rules or copy the rule into your repository.
28-
git_repository(
29-
name = "rules_oci_bootstrap",
30-
remote = "https://github.com/DataDog/rules_oci_bootstrap.git",
31-
commit = "75330296a80c4a5bfa228dc585ca9a9c3e56d45d",
32-
)
14+
```starlark
15+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3316

34-
load("@rules_oci_bootstrap//:defs.bzl", "oci_blob_pull")
35-
oci_blob_pull(
17+
http_archive(
3618
name = "com_github_datadog_rules_oci",
37-
digest = "sha256:cc6c59ed7da6bb376552461e06068f883bbe335359c122c15dce3c24e19cd8e2",
38-
extract = True,
39-
registry = "ghcr.io",
40-
repository = "datadog/rules_oci/rules",
41-
type = "tar.gz",
19+
sha256 = "<SHA256>",
20+
strip_prefix = "rules_oci-<COMMIT>",
21+
url = "https://github.com/DataDog/rules_oci/archive/<COMMIT>.tar.gz",
4222
)
43-
```
4423

45-
### Docs
24+
load(
25+
"@com_github_datadog_rules_oci//oci/repositories:01_direct_dependencies.bzl",
26+
"rules_oci_direct_dependencies",
27+
)
4628

47-
[Rule API](docs/docs.md)
29+
rules_oci_direct_dependencies()
4830

49-
Examples can be found in the `tests` directory.
31+
load("@com_github_datadog_rules_oci//oci/repositories:02_toolchains.bzl", "rules_oci_toolchains")
5032

51-
### How it works at a high level
33+
rules_oci_toolchains(
34+
# Only set this if you have not already registered a go toolchain
35+
register_go_toolchain_version = "1.22.5",
5236

53-
At fetch-time we only pull down the manifest json that represents the
54-
structure of the image, rather than pull down everything -- we call this a shallow
55-
pull. We then modify the manifest and republish it with just the changed layers
56-
at "bazel run"-time.
37+
# Only set this if you have not already registered a rust toolchain
38+
register_rust_toolchain_version = "1.82.0",
39+
)
5740

58-
This is perfect for the use-case of creating "application images", aka images
59-
where you just plop a binary on top of a base image. Some additional small
60-
changes can be done such as injecting a shared library or a config file.
41+
load(
42+
"@com_github_datadog_rules_oci//oci/repositories:03_third_party_go_and_rust_libraries.bzl",
43+
"rules_oci_third_party_go_and_rust_libraries",
44+
)
6145

62-
We've found in most cases we don't need to pull these additional layers as they
63-
were pushed there previously or can copy (via the mount api) within the same
64-
registry.
46+
rules_oci_third_party_go_and_rust_libraries()
47+
```
6548

66-
This has the downside that there is no verification of all of the content
67-
in the image, but this trade-off is worth the speed of not downloaded many GBs of
68-
base images.
49+
### Docs
6950

70-
### Roadmap
51+
- [rules](docs/defs.md)
52+
- [providers](docs/providers.md)
53+
- [pull repository rule](docs/pull.md)
7154

72-
- [ ] Flesh out code for non-shallow pulls and cases where the layers are coming
73-
from a different registry.
74-
- [ ] Full Starlark DSL for creating custom artifacts, it's currently looks
75-
a bit wonky
76-
- [ ] Support for the ORAS Artifact Spec
77-
- [ ] Support for custom artifact crawlers to pull artifacts that have children
78-
not represented by the OCI Image Spec. Ex pulling a full CNAB bundle and all
79-
dependencies.
80-
- [ ] Benchmark against `rules_docker` and raw `docker build`.
55+
Examples can be found in the `examples` directory.
8156

8257
### FAQ
8358

@@ -94,12 +69,12 @@ base images.
9469

9570
### Developing
9671

97-
| action | command |
98-
| ------------------------ | ------------------------------------- |
99-
| Run the tests | `just test` |
100-
| Run the formatter | `just format` |
101-
| Run gazelle | `just gazelle` |
102-
| Update the docs | `just update-docs` |
103-
| Update go dependencies | `bazel run //:go -- get <DEPENDENCY>` |
104-
| Update rust dependencies | `just update-crates` |
105-
| Publish a new release | `just release` |
72+
| action | command |
73+
| ------------------------ | -------------------------------------------------------- |
74+
| Run the tests | `just test` |
75+
| Run the formatter | `just format` |
76+
| Run gazelle | `just gazelle` |
77+
| Update the docs | `just update-docs` |
78+
| Update go dependencies | Modify `go.mod` and run `just update-go-3rd-party` |
79+
| Update rust dependencies | Modify `Cargo.toml` and run `just update-rust-3rd-party` |
80+
| Publish a new release | `just release` |

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rust_register_toolchains(
2929
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
3030

3131
crates_repository(
32-
name = "crate_index",
32+
name = "com_github_datadog_rules_oci_crate_index",
3333
cargo_lockfile = "//:Cargo.lock",
3434
lockfile = "//:cargo-bazel-lock.json",
3535
manifests = [
@@ -39,6 +39,6 @@ crates_repository(
3939
rust_version = _RUSTC_VERSION,
4040
)
4141

42-
load("@crate_index//:defs.bzl", "crate_repositories")
42+
load("@com_github_datadog_rules_oci_crate_index//:defs.bzl", "crate_repositories")
4343

4444
crate_repositories()

cargo-bazel-lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "030e153464f00aa0a15a3162aa3e206b5e42faf52412bf783ec58f62406c22bc",
2+
"checksum": "bcebbb48f8aa8d2b6ef3a9c5b2cb5c8698f2f2eaa50fdd72a9e863b4b3314d6e",
33
"crates": {
44
"aho-corasick 1.1.3": {
55
"name": "aho-corasick",

docs/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ stardoc_with_diff_test(
1111
)
1212

1313
stardoc_with_diff_test(
14-
name = "repositories",
15-
bzl_library_target = "//oci:repositories",
14+
name = "pull",
15+
bzl_library_target = "//oci/repositories:pull",
1616
)
1717

1818
update_docs()

docs/defs.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -106,35 +106,3 @@ oci_image_layer
106106
| <a id="oci_image_layer-kwargs"></a>kwargs | Additional arguments to pass to the rule, e.g. `tags` or `visibility` | none |
107107

108108

109-
<a id="oci_pull"></a>
110-
111-
## oci_pull
112-
113-
<pre>
114-
oci_pull(<a href="#oci_pull-name">name</a>, <a href="#oci_pull-debug">debug</a>, <a href="#oci_pull-digest">digest</a>, <a href="#oci_pull-registry">registry</a>, <a href="#oci_pull-repo_mapping">repo_mapping</a>, <a href="#oci_pull-repository">repository</a>, <a href="#oci_pull-scheme">scheme</a>, <a href="#oci_pull-shallow">shallow</a>)
115-
</pre>
116-
117-
**ATTRIBUTES**
118-
119-
120-
| Name | Description | Type | Mandatory | Default |
121-
| :------------- | :------------- | :------------- | :------------- | :------------- |
122-
| <a id="oci_pull-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
123-
| <a id="oci_pull-debug"></a>debug | Deprecated. Does nothing | Boolean | optional | `False` |
124-
| <a id="oci_pull-digest"></a>digest | The digest or tag of the manifest file | String | required | |
125-
| <a id="oci_pull-registry"></a>registry | Remote registry host to pull from, e.g. `gcr.io` or `index.docker.io` | String | required | |
126-
| <a id="oci_pull-repo_mapping"></a>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.<br><br>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`).<br><br>This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | |
127-
| <a id="oci_pull-repository"></a>repository | Image path beneath the registry, e.g. `distroless/static` | String | required | |
128-
| <a id="oci_pull-scheme"></a>scheme | scheme portion of the URL for fetching from the registry | String | optional | `"https"` |
129-
| <a id="oci_pull-shallow"></a>shallow | Deprecated. Does nothing | Boolean | optional | `False` |
130-
131-
**ENVIRONMENT VARIABLES**
132-
133-
This repository rule depends on the following environment variables:
134-
* `DOCKER_CONFIG`
135-
* `REGISTRY_AUTH_FILE`
136-
* `XDG_RUNTIME_DIR`
137-
* `HOME`
138-
* `OCI_ENABLE_OAUTH2_SUPPORT`
139-
140-

0 commit comments

Comments
 (0)