-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbalena-contracts.cue
262 lines (246 loc) · 7.15 KB
/
balena-contracts.cue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
info: {
title: "Contracts Specification"
version: "1.0.0"
license: {
name: "Apache 2.0"
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
}
}
// Semantic Versioning compliant version (see https://semver.org)
//
// Example: `3.1.5`
#SemVer: string
// Semantic Version range
//
// See https://github.com/npm/node-semver#ranges
//
// Example: `>=1.0.0`
#SemVerRange: string
// A namespaced type string
#Type: =~"^[a-zA-Z][a-zA-Z0-9.-]*$"
// A slug string
#Slug: =~"^[a-zA-Z][a-zA-Z0-9-.]*$"
// Uniform resource location
#URL: "^(http|https|file)://.+$"
#Asset: {
name?: string
url: #URL
checksum?: string
checksumType?: string
// Validation: If checksum is present, checksumType must also be present
// (this doesn't translate to openapi)
if checksum != _|_ {
checksumType: string
}
}
// A matcher to a contract or a range of contracts
//
// Examples:
// Match all hw.device-type contracts with the given data
// ```yml
// type: hw.device-type
// data:
// arch: armv7hf
// hdmi: true
// ```
//
// Match all alpine versions bigger than 3.15
// ```yml
// type: sw.os
// slug: alpine
// version: >=3.15
// ```
#ContractMatcher: {
#Contract
version?: #SemVerRange
}
// A contract requirement
#ContractRequirement: #ContractMatcher | {or: [...#ContractRequirement]} | {not: [...#ContractRequirement]}
// The contract metadata specification
#ContractMetadata: {
// A semver version of the entity definition as we have defined it in the contract. The version should be updated every time the contract information changes.
//
// If not provided, we assume the contract is version 1.0.0
//
// Example: `1.0.1`
version?: #SemVer
// A human readable name of the entity.
//
// Example: `Raspberry PI 3`
name?: string
// A human readable description of the entity
//
// Example: `Single-board device to enable your IoT projects`
description?: string
// Alternative, globally unique slugs
//
// Example: `[ 'rpi3', 'raspberry-pi3' ]`
aliases?: [...#Slug]
// A free-form object for contract specific information. Notice that contracts are not allowed to define any extra top-level properties, so any information specific to a type must live inside data
data: {...}
// The assets this contract requires.
// There are two types of assets:
// - Local (declared with a file path)
// - Remote (declared with a URL)
//
// If the protocol prefix is not provided, `file://` is assumed. Slashes should be used as path separators (UNIX style).
// The url data property is mandatory.
// If name is not provided, the asset key can be used as a substitute.
// The checksum property is optional, but if present, checksumType must exist.
//
// Example:
// ```yml
// assets:
// bin:
// name: qemu-arm-static
// url: file://./assets/qemu-arm-static
// checksum: 7bce65c956bbddbf83a8ce9121b505657e835df4a064823de51623858c25090f
// checksumType: sha256
// ```
assets: {
[string]: #Asset
}
// Enables each contract to specify its requirements on the environment in order to be valid.
// The requirements are specified as a contract reference or an operation (`or`,`not`) on requirements
//
// Example:
// ```yml
// type: sw.application
// slug: balena-sound
// requires:
// - or:
// - type: hw.connector
// slug: hdmiv1.5
// - type: hw.connector
// slug: usb3
// ```
requires?: [...#ContractRequirement]
// Allows to specify what functionalities
// or capabilities from the environment an entity defined by the contract provides.
//
// Differently from requirements, only a list of contract references is supported for now
//
// Example:
// ```yml
// type: sw.application
// slug: balena-os-for-raspberrypi3
// provides:
// - type: sw.os
// slug: balenaos
// ```
provides?: [...#ContractMatcher]
// Allows to specify contract alternatives for different sets of requirements.
//
// It can be combined with templating to generate a large number of contracts
// from a short specification
// For an example, see: https://github.com/balena-io/contracts/blob/master/contracts/sw.stack/node/contract.json
variants?: [...#ContractMetadata]
// A contract can contain other contracts, which makes it a composite contract.
// This is accomplished by adding other contracts inside the `children` property
children?: [...#Contract]
}
// A contract is a specification for describing _things_. A thing can be pretty much anything,
// a software library, a feature, an API, etc. Relationships between things can be established
// via composition and referencing (`requires` and `provides`).
//
// Example:
// ```json
// {
// "slug": "raspberrypi3",
// "version": "1",
// "type": "hw.device-type",
// "aliases": [],
// "name": "Raspberry Pi 3",
// "assets": {
// "logo": {
// "url": "./raspberrypi3.svg",
// "name": "logo"
// }
// },
// "data": {
// "arch": "armv7hf",
// "hdmi": true,
// "led": true,
// "connectivity": {
// "bluetooth": true,
// "wifi": true
// },
// "storage": {
// "internal": false
// },
// "media": {
// "defaultBoot": "sdcard",
// "altBoot": ["usb_mass_storage", "network"]
// },
// "is_private": false
// }
// }
// ```
#Contract: {
// The type of a contract, which mostly aims to determine the contents of the free-form data object.
// Ideally types should be namespaced to avoid clashing of contract types.
//
// Example: `hw.device-type`
type: #Type
// Unique identifier for the contract. No two contracts of the same type should have the same slug.
//
// Example: `raspberrypi3`
slug?: #Slug
// The contract body
#ContractMetadata
}
// A cardinality operator
//
// A cardinality is usually represented with a tuple that defines a range of
// integers. On top of that, the following syntax sugar is supported.
// Assuming `x` in an integer:
// - `x` -> `[ x, x ]`
// - `*` -> `[ 0, Infinity ]`
// - `?` -> `[ 0, 1 ]`
// - `1?` -> `[ 0, 1 ]`
// - `'x'` -> `[ x, x ]`
// - `x+` -> `[ x, Infinity ]`
// - `[ x, '*' ]` -> `[ x, Infinity ]`
#Cardinality: string
// A JSON schema filter
//
// Example
// ```json
// {
// "type": "object",
// "properties": {
// "slug": {
// "const": "armv7hf"
// }
// }
// }
// ```
#FilterSchema: {...}
// A set of cardinality operators for a blueprint
#BlueprintLayout: {
[string]: #Cardinality | {cardinality: #Cardinality, filter: #FilterSchema}
}
// A blueprint is a partial contract that defines how to generate a certain combination of contracts
// from a universe. The result of "applying" a blueprint on a universe is a set of contexts.
#Blueprint: {
type: "meta.blueprint"
// The query for the blueprint using a set of cardinality operators
//
// Example
// ```yml
// selector:
// sw.os: '1'
// sw.blob: '*',
// arch.sw:
// cardinality: [0,1]
// filter:
// type: object
// properties:
// slug:
// const: armv7hf
// ```
layout: #BlueprintLayout
// An object describing how the resulting contexts should look like. You may use properties such as type, slug, data, etc.
// You may use blueprint results to construct certain properties by accessing children through the children property.
skeleton?: {...}
}