| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 1 | def _localregistry_manifest_impl(ctx): |
| Tim Windelschmidt | 156248b | 2025-01-10 00:27:45 +0100 | [diff] [blame] | 2 | manifest_out = ctx.actions.declare_file(ctx.label.name + ".prototxt") |
| Tim Windelschmidt | 0974b22 | 2024-01-16 14:04:15 +0100 | [diff] [blame] | 3 | |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 4 | images = [] |
| 5 | referenced = [manifest_out] |
| Jan Schär | 9d2f3c6 | 2025-04-14 11:17:22 +0000 | [diff] [blame] | 6 | for key, label in ctx.attr.images.items(): |
| 7 | image_file = label[DefaultInfo].files.to_list()[0] |
| 8 | repository, _, tag = key.partition(":") |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 9 | image = struct( |
| Jan Schär | 9d2f3c6 | 2025-04-14 11:17:22 +0000 | [diff] [blame] | 10 | repository = repository, |
| 11 | tag = tag, |
| Tim Windelschmidt | 0974b22 | 2024-01-16 14:04:15 +0100 | [diff] [blame] | 12 | path = image_file.short_path, |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 13 | ) |
| Tim Windelschmidt | 0974b22 | 2024-01-16 14:04:15 +0100 | [diff] [blame] | 14 | referenced.append(image_file) |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 15 | images.append(image) |
| Tim Windelschmidt | 0974b22 | 2024-01-16 14:04:15 +0100 | [diff] [blame] | 16 | |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 17 | 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 Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 20 | localregistry_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är | 9d2f3c6 | 2025-04-14 11:17:22 +0000 | [diff] [blame] | 26 | "images": attr.string_keyed_label_dict( |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 27 | mandatory = True, |
| 28 | doc = """ |
| Jan Schär | 9d2f3c6 | 2025-04-14 11:17:22 +0000 | [diff] [blame] | 29 | 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 Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 32 | """, |
| Tim Windelschmidt | 156248b | 2025-01-10 00:27:45 +0100 | [diff] [blame] | 33 | providers = [], |
| Lorenz Brun | 901c732 | 2023-07-13 20:10:37 +0200 | [diff] [blame] | 34 | ), |
| 35 | }, |
| 36 | ) |