Skip to content

Commit 6c657ba

Browse files
committed
rename files to match rules
1 parent cefb088 commit 6c657ba

File tree

13 files changed

+153
-140
lines changed

13 files changed

+153
-140
lines changed

go/pkg/ociutil/bazel.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ func GenerateBuildFilesHandler(handler images.HandlerFunc, layoutRoot string, pr
2626
blobBuildFiles[digest.SHA256] = rule.EmptyFile(algoBUILDPath(layoutRoot, digest.SHA256), "")
2727

2828
// Add load statements for all of the oci_* rules
29-
ldBlob := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:blob.bzl")
29+
ldBlob := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:oci_blob.bzl")
3030
ldBlob.Add("oci_blob")
3131

32-
ldManifest := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:manifests.bzl")
33-
ldManifest.Add("oci_image_index_manifest")
34-
ldManifest.Add("oci_image_manifest")
32+
ldImageManifest := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:oci_image_manifest.bzl")
33+
ldImageManifest.Add("oci_image_manifest")
34+
35+
ldImageIndexManifest := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:oci_image_index_manifest.bzl")
36+
ldImageIndexManifest.Add("oci_image_index_manifest")
3537

3638
for algo, f := range blobBuildFiles {
3739
ldBlob.Insert(f, 0)
38-
ldManifest.Insert(f, 0)
40+
ldImageManifest.Insert(f, 0)
41+
ldImageIndexManifest.Insert(f, 0)
3942
f.Save(algoBUILDPath(layoutRoot, algo))
4043
}
4144

4245
// Top level build file for used as an index of the entire layout
4346
layoutBuild := rule.EmptyFile(filepath.Join(layoutRoot, "BUILD.bazel"), "")
4447

45-
ldLayout := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:layout.bzl")
48+
ldLayout := rule.NewLoad("@com_github_datadog_rules_oci//oci/private/repositories:oci_layout_index.bzl")
4649
ldLayout.Add("oci_layout_index")
4750
ldLayout.Insert(layoutBuild, 0)
4851

oci/BUILD.bazel

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ bzl_library(
2828
visibility = ["//visibility:public"],
2929
deps = [
3030
"//oci:providers.bzl",
31+
"//oci/private:common.bzl",
3132
"//oci/private:debug_flag.bzl",
32-
"//oci/private:image.bzl",
33+
"//oci/private:oci_image.bzl",
34+
"//oci/private:oci_image_index.bzl",
3335
"//oci/private:oci_image_layer.bzl",
3436
"//oci/private:oci_image_layout.bzl",
35-
"//oci/private:push.bzl",
37+
"//oci/private:oci_push.bzl",
3638
"@aspect_bazel_lib//lib:stamping",
3739
],
3840
)
@@ -52,7 +54,7 @@ bzl_library(
5254
],
5355
visibility = ["//visibility:public"],
5456
deps = [
55-
"//oci/private/repositories:pull.bzl",
57+
"//oci/private/repositories:oci_pull.bzl",
5658
],
5759
)
5860

oci/defs.bzl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
""" public rules """
22

3-
load(
4-
"//oci/private:image.bzl",
5-
_oci_image = "oci_image",
6-
_oci_image_index = "oci_image_index",
7-
)
3+
load("//oci/private:oci_image.bzl", _oci_image = "oci_image")
4+
load("//oci/private:oci_image_index.bzl", _oci_image_index = "oci_image_index")
85
load("//oci/private:oci_image_layer.bzl", _oci_image_layer = "oci_image_layer")
96
load("//oci/private:oci_image_layout.bzl", _oci_image_layout = "oci_image_layout")
10-
load("//oci/private:push.bzl", _oci_push = "oci_push")
7+
load("//oci/private:oci_push.bzl", _oci_push = "oci_push")
118

129
oci_image = _oci_image
1310
oci_image_index = _oci_image_index

oci/private/common.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# buildifier: disable=function-docstring
2+
def get_descriptor_file(ctx, desc):
3+
if hasattr(desc, "descriptor_file"):
4+
return desc.descriptor_file
5+
6+
out = ctx.actions.declare_file(desc.digest)
7+
ctx.actions.write(
8+
output = out,
9+
content = json.encode({
10+
"mediaType": desc.media_type,
11+
"size": desc.size,
12+
"digest": desc.digest,
13+
"urls": desc.urls,
14+
"annotations": desc.annotations,
15+
}),
16+
)
17+
18+
return out
Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,9 @@
1-
""" image """
1+
""" oci_image """
22

33
load("//oci:providers.bzl", "OCIDescriptor", "OCILayout")
4+
load(":common.bzl", "get_descriptor_file")
45

5-
# buildifier: disable=function-docstring
6-
def get_descriptor_file(ctx, desc):
7-
if hasattr(desc, "descriptor_file"):
8-
return desc.descriptor_file
9-
10-
out = ctx.actions.declare_file(desc.digest)
11-
ctx.actions.write(
12-
output = out,
13-
content = json.encode({
14-
"mediaType": desc.media_type,
15-
"size": desc.size,
16-
"digest": desc.digest,
17-
"urls": desc.urls,
18-
"annotations": desc.annotations,
19-
}),
20-
)
21-
22-
return out
23-
24-
def _oci_image_index_impl(ctx):
25-
toolchain = ctx.toolchains["//oci:toolchain"]
26-
27-
layout_files = depset(None, transitive = [m[OCILayout].files for m in ctx.attr.manifests])
28-
29-
index_desc_file = ctx.actions.declare_file("{}.index.descriptor.json".format(ctx.label.name))
30-
index_file = ctx.actions.declare_file("{}.index.json".format(ctx.label.name))
31-
layout_file = ctx.actions.declare_file("{}.index.layout.json".format(ctx.label.name))
32-
33-
desc_files = []
34-
for manifest in ctx.attr.manifests:
35-
desc_files.append(get_descriptor_file(ctx, manifest[OCIDescriptor]))
36-
37-
outputs = [
38-
index_file,
39-
index_desc_file,
40-
layout_file,
41-
]
42-
43-
ctx.actions.run(
44-
executable = toolchain.sdk.ocitool,
45-
arguments = ["--layout={}".format(m[OCILayout].blob_index.path) for m in ctx.attr.manifests] +
46-
[
47-
"create-index",
48-
"--out-index={}".format(index_file.path),
49-
"--out-layout={}".format(layout_file.path),
50-
"--outd={}".format(index_desc_file.path),
51-
] +
52-
["--desc={}".format(d.path) for d in desc_files] +
53-
["--annotations={}={}".format(k, v) for k, v in ctx.attr.annotations.items()],
54-
inputs = desc_files + layout_files.to_list(),
55-
outputs = outputs,
56-
)
57-
58-
return [
59-
OCIDescriptor(
60-
descriptor_file = index_desc_file,
61-
),
62-
OCILayout(
63-
blob_index = layout_file,
64-
files = depset(direct = [index_file, layout_file], transitive = [layout_files]),
65-
),
66-
DefaultInfo(
67-
files = depset(outputs),
68-
),
69-
]
70-
71-
oci_image_index = rule(
72-
implementation = _oci_image_index_impl,
73-
doc = """
74-
""",
75-
attrs = {
76-
"manifests": attr.label_list(
77-
doc = """
78-
""",
79-
),
80-
"annotations": attr.string_dict(
81-
doc = """
82-
""",
83-
),
84-
},
85-
toolchains = ["//oci:toolchain"],
86-
)
87-
88-
def _oci_image_impl(ctx):
6+
def _impl(ctx):
897
toolchain = ctx.toolchains["//oci:toolchain"]
908

919
base_desc = get_descriptor_file(ctx, ctx.attr.base[OCIDescriptor])
@@ -179,7 +97,7 @@ def _oci_image_impl(ctx):
17997
]
18098

18199
oci_image = rule(
182-
implementation = _oci_image_impl,
100+
implementation = _impl,
183101
doc = """Creates a new image manifest and config by appending the `layers` to an existing image
184102
manifest and config defined by `base`. If `base` is an image index, then `os` and `arch` will
185103
be used to extract the image manifest.""",

oci/private/oci_image_index.bzl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
""" oci_image_index """
2+
3+
load("//oci:providers.bzl", "OCIDescriptor", "OCILayout")
4+
load(":common.bzl", "get_descriptor_file")
5+
6+
def _impl(ctx):
7+
toolchain = ctx.toolchains["//oci:toolchain"]
8+
9+
layout_files = depset(None, transitive = [m[OCILayout].files for m in ctx.attr.manifests])
10+
11+
index_desc_file = ctx.actions.declare_file("{}.index.descriptor.json".format(ctx.label.name))
12+
index_file = ctx.actions.declare_file("{}.index.json".format(ctx.label.name))
13+
layout_file = ctx.actions.declare_file("{}.index.layout.json".format(ctx.label.name))
14+
15+
desc_files = []
16+
for manifest in ctx.attr.manifests:
17+
desc_files.append(get_descriptor_file(ctx, manifest[OCIDescriptor]))
18+
19+
outputs = [
20+
index_file,
21+
index_desc_file,
22+
layout_file,
23+
]
24+
25+
ctx.actions.run(
26+
executable = toolchain.sdk.ocitool,
27+
arguments = ["--layout={}".format(m[OCILayout].blob_index.path) for m in ctx.attr.manifests] +
28+
[
29+
"create-index",
30+
"--out-index={}".format(index_file.path),
31+
"--out-layout={}".format(layout_file.path),
32+
"--outd={}".format(index_desc_file.path),
33+
] +
34+
["--desc={}".format(d.path) for d in desc_files] +
35+
["--annotations={}={}".format(k, v) for k, v in ctx.attr.annotations.items()],
36+
inputs = desc_files + layout_files.to_list(),
37+
outputs = outputs,
38+
)
39+
40+
return [
41+
OCIDescriptor(
42+
descriptor_file = index_desc_file,
43+
),
44+
OCILayout(
45+
blob_index = layout_file,
46+
files = depset(direct = [index_file, layout_file], transitive = [layout_files]),
47+
),
48+
DefaultInfo(
49+
files = depset(outputs),
50+
),
51+
]
52+
53+
oci_image_index = rule(
54+
implementation = _impl,
55+
doc = """
56+
""",
57+
attrs = {
58+
"manifests": attr.label_list(
59+
doc = """
60+
""",
61+
),
62+
"annotations": attr.string_dict(
63+
doc = """
64+
""",
65+
),
66+
},
67+
toolchains = ["//oci:toolchain"],
68+
)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
""" push """
1+
""" oci_push """
22

33
load("@aspect_bazel_lib//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
44
load("//oci:providers.bzl", "OCIDescriptor", "OCILayout", "OCIReferenceInfo")
55
load(":debug_flag.bzl", "DebugInfo")
66

7-
def _oci_push_impl(ctx):
7+
def _impl(ctx):
88
toolchain = ctx.toolchains["//oci:toolchain"]
99

1010
layout = ctx.attr.manifest[OCILayout]
@@ -137,7 +137,7 @@ oci_push = rule(
137137
doc = """
138138
Pushes a manifest or a list of manifests to an OCI registry.
139139
""",
140-
implementation = _oci_push_impl,
140+
implementation = _impl,
141141
executable = True,
142142
attrs = dict({
143143
"manifest": attr.label(
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
""" blob """
1+
""" oci_blob """
22

33
load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor")
44

5-
def _oci_blob_impl(ctx):
5+
def _impl(ctx):
66
return [OCIDescriptor(
77
file = ctx.file.file,
88
media_type = ctx.attr.media_type,
@@ -13,7 +13,7 @@ def _oci_blob_impl(ctx):
1313
)]
1414

1515
oci_blob = rule(
16-
implementation = _oci_blob_impl,
16+
implementation = _impl,
1717
doc = """
1818
An internal rule to represent a blob in a content-addressable store. This
1919
rule is usually generated by 'ocitool' when pulling an OCI artifact.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
""" oci_image_index_manifest """
2+
3+
load(
4+
"@com_github_datadog_rules_oci//oci:providers.bzl",
5+
"OCIDescriptor",
6+
"OCIImageIndexManifest",
7+
"OCILayout",
8+
)
9+
10+
def _impl(ctx):
11+
return [OCIImageIndexManifest(
12+
manifests = [m[OCIDescriptor] for m in ctx.attr.manifests],
13+
), ctx.attr.layout[OCILayout], ctx.attr.descriptor[OCIDescriptor]]
14+
15+
oci_image_index_manifest = rule(
16+
implementation = _impl,
17+
attrs = {
18+
"descriptor": attr.label(
19+
mandatory = True,
20+
providers = [OCIDescriptor],
21+
),
22+
"manifests": attr.label_list(
23+
mandatory = False,
24+
providers = [OCIDescriptor],
25+
),
26+
"annotations": attr.string_dict(),
27+
"layout": attr.label(),
28+
},
29+
provides = [OCIImageIndexManifest],
30+
)
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
""" manifests """
1+
""" oci_image_manifest """
22

33
load(
44
"@com_github_datadog_rules_oci//oci:providers.bzl",
55
"OCIDescriptor",
6-
"OCIImageIndexManifest",
76
"OCIImageManifest",
87
"OCILayout",
98
)
109

11-
def _oci_image_manifest_impl(ctx):
10+
def _impl(ctx):
1211
return [OCIImageManifest(
1312
config = ctx.attr.config[OCIDescriptor],
1413
layers = [layer[OCIDescriptor] for layer in ctx.attr.layers],
1514
annotations = ctx.attr.annotations,
1615
), ctx.attr.layout[OCILayout], ctx.attr.descriptor[OCIDescriptor]]
1716

1817
oci_image_manifest = rule(
19-
implementation = _oci_image_manifest_impl,
18+
implementation = _impl,
2019
provides = [OCIImageManifest],
2120
attrs = {
2221
"descriptor": attr.label(
@@ -35,25 +34,3 @@ oci_image_manifest = rule(
3534
"layout": attr.label(),
3635
},
3736
)
38-
39-
def _oci_image_index_manifest_impl(ctx):
40-
return [OCIImageIndexManifest(
41-
manifests = [m[OCIDescriptor] for m in ctx.attr.manifests],
42-
), ctx.attr.layout[OCILayout], ctx.attr.descriptor[OCIDescriptor]]
43-
44-
oci_image_index_manifest = rule(
45-
implementation = _oci_image_index_manifest_impl,
46-
attrs = {
47-
"descriptor": attr.label(
48-
mandatory = True,
49-
providers = [OCIDescriptor],
50-
),
51-
"manifests": attr.label_list(
52-
mandatory = False,
53-
providers = [OCIDescriptor],
54-
),
55-
"annotations": attr.string_dict(),
56-
"layout": attr.label(),
57-
},
58-
provides = [OCIImageIndexManifest],
59-
)

0 commit comments

Comments
 (0)