blob: 289dc3402868bf5b6d90f2686ed741a9f8b087e0 [file] [log] [blame]
Tim Windelschmidt0974b222024-01-16 14:04:15 +01001#load("@io_bazel_rules_docker//container:providers.bzl", "ImageInfo")
Lorenz Brun901c7322023-07-13 20:10:37 +02002
3def _localregistry_manifest_impl(ctx):
Tim Windelschmidt156248b2025-01-10 00:27:45 +01004 manifest_out = ctx.actions.declare_file(ctx.label.name + ".prototxt")
Tim Windelschmidt0974b222024-01-16 14:04:15 +01005
Lorenz Brun901c7322023-07-13 20:10:37 +02006 images = []
7 referenced = [manifest_out]
8 for i in ctx.attr.images:
Tim Windelschmidt0974b222024-01-16 14:04:15 +01009 image_file = i.files.to_list()[0]
Lorenz Brun901c7322023-07-13 20:10:37 +020010 image = struct(
11 name = i.label.package + "/" + i.label.name,
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 = {
26 "images": attr.label_list(
27 mandatory = True,
28 doc = """
Tim Windelschmidt0974b222024-01-16 14:04:15 +010029 List of images to be served from the local registry.
Lorenz Brun901c7322023-07-13 20:10:37 +020030 """,
Tim Windelschmidt156248b2025-01-10 00:27:45 +010031 providers = [],
Lorenz Brun901c7322023-07-13 20:10:37 +020032 ),
33 },
34)