...
1# Considerations
2
3## Extensibility
4
5Implementations storing or copying content MUST NOT modify or alter the content in a way that would change the digest of the content. Examples of these implementations include:
6
7- A [registry implementing the distribution specification][distribution-spec], including local registries, caching proxies
8- An application which copies content to disk or between registries
9
10Implementations processing content SHOULD NOT generate an error if they encounter an unknown property in a known media type. Examples of these implementations include:
11
12- A [runtime implementing the runtime specification][runtime-spec]
13- An implementation using OCI to retrieve and utilize artifacts, e.g.: a WASM runtime
14
15## Canonicalization
16
17- OCI Images are [content-addressable](https://en.wikipedia.org/wiki/Content-addressable_storage). See [descriptors](descriptor.md) for more.
18- One benefit of content-addressable storage is easy deduplication.
19- Many images might depend on a particular [layer](layer.md), but there will only be one blob in the [store](image-layout.md).
20- With a different serialization, that same semantic layer would have a different hash, and if both versions of the layer are referenced there will be two blobs with the same semantic content.
21- To allow efficient storage, implementations serializing content for blobs SHOULD use a canonical serialization.
22- This increases the chance that different implementations can push the same semantic content to the store without creating redundant blobs.
23
24### JSON
25
26[JSON][JSON] content SHOULD be serialized as [canonical JSON][canonical-json].
27Of the [OCI Image Format Specification media types](media-types.md), all the types ending in `+json` contain JSON content.
28Implementations:
29
30- [Go][Go]: [github.com/docker/go][docker-go], which claims to implement [canonical JSON][canonical-json] except for Unicode normalization.
31
32## EBNF
33
34For field formats described in this specification, we use a limited subset of [Extended Backus-Naur Form][ebnf], similar to that used by the [XML specification][xmlebnf].
35Grammars present in the OCI specification are regular and can be converted to a single regular expressions.
36However, regular expressions are avoided to limit ambiguity between regular expression syntax.
37By defining a subset of EBNF used here, the possibility of variation, misunderstanding or ambiguities from linking to a larger specification can be avoided.
38
39Grammars are made up of rules in the following form:
40
41```ebnf
42symbol ::= expression
43```
44
45We can say we have the production identified by symbol if the input is matched by the expression.
46Whitespace is completely ignored in rule definitions.
47
48### Expressions
49
50The simplest expression is the literal, surrounded by quotes:
51
52```ebnf
53literal ::= "matchthis"
54```
55
56The above expression defines a symbol, "literal", that matches the exact input of "matchthis".
57Character classes are delineated by brackets (`[]`), describing either a set, range or multiple range of characters:
58
59```ebnf
60set := [abc]
61range := [A-Z]
62```
63
64The above symbol "set" would match one character of either "a", "b" or "c".
65The symbol "range" would match any character, "A" to "Z", inclusive.
66Currently, only matching for 7-bit ascii literals and character classes is defined, as that is all that is required by this specification.
67Multiple character ranges and explicit characters can be specified in a single character classes, as follows:
68
69```ebnf
70multipleranges := [a-zA-Z=-]
71```
72
73The above matches the characters in the range `A` to `Z`, `a` to `z` and the individual characters `-` and `=`.
74
75Expressions can be made up of one or more expressions, such that one must be followed by the other.
76This is known as an implicit concatenation operator.
77For example, to satisfy the following rule, both `A` and `B` must be matched to satisfy the rule:
78
79```ebnf
80symbol ::= A B
81```
82
83Each expression must be matched once and only once, `A` followed by `B`.
84To support the description of repetition and optional match criteria, the postfix operators `*` and `+` are defined.
85`*` indicates that the preceding expression can be matched zero or more times.
86`+` indicates that the preceding expression must be matched one or more times.
87These appear in the following form:
88
89```ebnf
90zeroormore ::= expression*
91oneormore ::= expression+
92```
93
94Parentheses are used to group expressions into a larger expression:
95
96```ebnf
97group ::= (A B)
98```
99
100Like simpler expressions above, operators can be applied to groups, as well.
101To allow for alternates, we also define the infix operator `|`.
102
103```ebnf
104oneof ::= A | B
105```
106
107The above indicates that the expression should match one of the expressions, `A` or `B`.
108
109### Precedence
110
111The operator precedence is in the following order:
112
113- Terminals (literals and character classes)
114- Grouping `()`
115- Unary operators `+*`
116- Concatenation
117- Alternates `|`
118
119The precedence can be better described using grouping to show equivalents.
120Concatenation has higher precedence than alternates, such `A B | C D` is equivalent to `(A B) | (C D)`.
121Unary operators have higher precedence than alternates and concatenation, such that `A+ | B+` is equivalent to `(A+) | (B+)`.
122
123### Examples
124
125The following combines the previous definitions to match a simple, relative path name, describing the individual components:
126
127```ebnf
128path ::= component ("/" component)*
129component ::= [a-z]+
130```
131
132The production "component" is one or more lowercase letters.
133A "path" is then at least one component, possibly followed by zero or more slash-component pairs.
134The above can be converted into the following regular expression:
135
136```regex
137[a-z]+(?:/[a-z]+)*
138```
139
140[canonical-json]: https://wiki.laptop.org/go/Canonical_JSON
141[distribution-spec]: https://github.com/opencontainers/distribution-spec/blob/main/spec.md
142[docker-go]: https://github.com/docker/go/
143[ebnf]: https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form
144[Go]: https://golang.org/
145[JSON]: https://json.org/
146[runtime-spec]: https://github.com/opencontainers/runtime-spec/blob/main/spec.md
147[xmlebnf]: https://www.w3.org/TR/REC-xml/#sec-notation
View as plain text