Skip to content

Commit 21026ed

Browse files
committed
designs/modules.v3: module metadata proposal
This adds a proposal for including metadata as annotations in a module's OCI manifest. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I48ec5568d2698773986b95ecfceed53160f9673d Reviewed-on: https://review.gerrithub.io/c/cue-lang/proposal/+/1193751 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent e43ba03 commit 21026ed

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

designs/modules.v3/2939-modules.md

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ This is proposed [here](2943-modules-compat.md).
110110
A more thorough treatment of how the content of a module is
111111
determined is proposed [here](3017-module-files.md).
112112

113+
A proposal for how to attach metadata to module manifests is
114+
[here](3057-module-metadata.md).
115+
113116
# Detailed Design
114117

115118
Although the design of CUE modules is heavily influenced by the Go modules
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Proposal: CUE module metadata
2+
3+
Status: **Draft**
4+
5+
Lifecycle:  **Proposed**
6+
7+
8+
9+
Relevant Links:
10+
11+
12+
13+
Discussion Channel: [GitHub](https://github.com/cue-lang/cue/discussions/3057)
14+
15+
16+
## Abstract
17+
18+
This document is an adjunct to the [modules proposal document](2939-modules.md).
19+
20+
We wish to attach VCS and other metadata to a module when uploading it
21+
to a registry. This information can indicate specifics of where a
22+
module was derived from, for example the commit hash of the VCS commit
23+
from which the module was derived.
24+
25+
This document proposes a way to include this information in the
26+
OCI manifest uploaded to a registry.
27+
28+
## OCI manifests
29+
30+
The OCI manifest schema provides an `annotations` field that is designed
31+
for metadata. It's a simple one level map of string to string.
32+
33+
It is described [here](https://github.com/opencontainers/image-spec/blob/e2edbc8c1723063d5167ea6b420eaebbc74b552c/annotations.md).
34+
35+
To quote some relevant points from that document:
36+
37+
- Annotations MUST be a key-value map where both the key and value MUST be strings.
38+
- While the value MUST be present, it MAY be an empty string.
39+
- Keys MUST be unique within this map, and best practice is to namespace the keys.
40+
- Keys SHOULD be named using a reverse domain notation - e.g. `com.example.myKey`.
41+
- Consumers MUST NOT generate an error if they encounter an unknown annotation key.
42+
43+
## Proposal
44+
45+
We propose that CUE-related metadata be stored in a set of keys
46+
prefixed with `org.cuelang.`, i.e. namespaced within the CUE project.
47+
To hold to the spirit of the manifest annotations, we will stick to a
48+
one-field-one-value convention rather than (for example) encoding all the
49+
metadata as a single JSON blob holding all the CUE-related fields.
50+
51+
As these fields are visible in isolation within third party OCI registry
52+
browsers, it arguably makes sense to describe the fields individually
53+
rather than considering them as a whole. This contrasts with the
54+
approach taken by the `module.cue` file where the entire file
55+
can be considered solely in the context of the language version.
56+
57+
The following fields are initially proposed:
58+
59+
- `org.cuelang.vcs-type`: the kind of VCS for which VCS metadata is supplied (initially
60+
supporting only `git`).
61+
- `org.cuelang.vcs-commit`: the commit associated with the module's contents
62+
- `org.cuelang.vcs-commit-time`: the time of the above commit, in RFC3339 syntax
63+
64+
Note that we are _not_ proposing that the remote location of the VCS
65+
is included, as that is not something that can be used or checked by a
66+
CUE registry. We are free to change that decision in the future if
67+
such a field might prove to be useful.
68+
69+
For example:
70+
71+
```
72+
annotations: {
73+
"org.cuelang.vcs-type": "git"
74+
"org.cuelang.vcs-commit": "2ff5afa7cda41bf030654ab03caeba3fadf241ae"
75+
"org.cuelang.vcs-commit-time": "2024-04-23T14:48:10.542193563Z"
76+
}
77+
```
78+
79+
## Backward and forwards compatibility
80+
81+
When creating a module, the CUE tooling will add all the metadata
82+
fields that it knows about.
83+
84+
The consumer of a CUE module will ignore any fields that it does not
85+
know about (including fields with the `org.cuelang.` prefix. This
86+
conforms to the "Consumers MUST NOT generate an error if they
87+
encounter an unknown annotation key" requirement.
88+
89+
The CUE project will be careful to add fields only in a backwardly
90+
compatible manner and avoid changing the meaning of existing fields.
91+
92+
When processing uploads, a CUE registry may inspect the language
93+
version and reject uploads that don't contain all the expected
94+
metadata fields for such a version. It may also reject uploads with a
95+
version that is not within acceptable bounds. This logic, however,
96+
will be present in the registry code but _not_ the code to actually
97+
parse the metadata, which will parse any fields it knows about and
98+
ignore fields it doesn't.

0 commit comments

Comments
 (0)