blob: 3b8e378b7172666eb32a781e9051d8bc370c1602 [file] [log] [blame]
Lorenz Brun901c7322023-07-13 20:10:37 +02001def _localregistry_manifest_impl(ctx):
Tim Windelschmidt156248b2025-01-10 00:27:45 +01002 manifest_out = ctx.actions.declare_file(ctx.label.name + ".prototxt")
Tim Windelschmidt0974b222024-01-16 14:04:15 +01003
Lorenz Brun901c7322023-07-13 20:10:37 +02004 images = []
5 referenced = [manifest_out]
Jan Schär9d2f3c62025-04-14 11:17:22 +00006 for key, label in ctx.attr.images.items():
7 image_file = label[DefaultInfo].files.to_list()[0]
8 repository, _, tag = key.partition(":")
Lorenz Brun901c7322023-07-13 20:10:37 +02009 image = struct(
Jan Schär9d2f3c62025-04-14 11:17:22 +000010 repository = repository,
11 tag = tag,
Tim Windelschmidt0974b222024-01-16 14:04:15 +010012 path = image_file.short_path,
Lorenz Brun901c7322023-07-13 20:10:37 +020013 )
Tim Windelschmidt0974b222024-01-16 14:04:15 +010014 referenced.append(image_file)
Lorenz Brun901c7322023-07-13 20:10:37 +020015 images.append(image)
Tim Windelschmidt0974b222024-01-16 14:04:15 +010016
Lorenz Brun901c7322023-07-13 20:10:37 +020017 ctx.actions.write(manifest_out, proto.encode_text(struct(images = images)))
18 return [DefaultInfo(runfiles = ctx.runfiles(files = referenced), files = depset([manifest_out]))]
19
Lorenz Brun901c7322023-07-13 20:10:37 +020020localregistry_manifest = rule(
21 implementation = _localregistry_manifest_impl,
22 doc = """
23 Builds a manifest for serving images directly from the build files.
24 """,
25 attrs = {
Jan Schär9d2f3c62025-04-14 11:17:22 +000026 "images": attr.string_keyed_label_dict(
Lorenz Brun901c7322023-07-13 20:10:37 +020027 mandatory = True,
28 doc = """
Jan Schär9d2f3c62025-04-14 11:17:22 +000029 Images to be served from the local registry.
30 The key defines the repository and tag, separated by ':'.
31 The value is a label which must contain an OCI layout directory.
Lorenz Brun901c7322023-07-13 20:10:37 +020032 """,
Tim Windelschmidt156248b2025-01-10 00:27:45 +010033 providers = [],
Lorenz Brun901c7322023-07-13 20:10:37 +020034 ),
35 },
36)