blob: c5fc56028b1919c5e8cb2de4bb4a2a290633e21f [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):
4 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
20
21localregistry_manifest = rule(
22 implementation = _localregistry_manifest_impl,
23 doc = """
24 Builds a manifest for serving images directly from the build files.
25 """,
26 attrs = {
27 "images": attr.label_list(
28 mandatory = True,
29 doc = """
Tim Windelschmidt0974b222024-01-16 14:04:15 +010030 List of images to be served from the local registry.
Lorenz Brun901c7322023-07-13 20:10:37 +020031 """,
Tim Windelschmidt0974b222024-01-16 14:04:15 +010032 providers = [],
Lorenz Brun901c7322023-07-13 20:10:37 +020033 ),
34 },
35)