-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathschema.go
287 lines (263 loc) · 11.5 KB
/
schema.go
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
//
// Copyright Red Hat
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package schema
import (
"time"
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)
/*
Sample index file:
[
{
"name": "java-maven",
"displayName": "Maven Java",
"description": "Upstream Maven and OpenJDK 11",
"type": "stack",
"tags": [
"Java",
"Maven"
],
"architectures": [
"amd64",
"arm64",
"s390x"
],
"projectType": "maven",
"language": "java",
"lastModified": "2024-05-13T12:32:02+02:00",
"versions": [
{
"version": "1.1.0",
"schemaVersion": "2.1.0",
"default": true,
"description": "Upstream Maven and OpenJDK 11",
"tags": [
"Java",
"Maven"
],
"architectures": [
"amd64",
"arm64",
"s390x"
],
"links": {
"self": "devfile-catalog/java-maven:1.1.0"
},
"resources": [
"devfile.yaml"
],
"starterProjects": [
"springbootproject"
],
"lastModified": "2024-05-13T12:32:02+02:00"
}
]
},
{
"name": "java-quarkus",
"displayName": "Quarkus Java",
"description": "Quarkus with Java",
"type": "stack",
"tags": [
"Java",
"Quarkus"
],
"architectures": [
"amd64"
],
"projectType": "quarkus",
"language": "java",
"lastModified": "2024-04-29T17:08:43+03:00",
"versions": [
{
"version": "1.1.0",
"schemaVersion": "2.0.0",
"default": true,
"description": "Quarkus with Java",
"tags": [
"Java",
"Quarkus"
],
"architectures": [
"amd64"
],
"links": {
"self": "devfile-catalog/java-quarkus:1.1.0"
},
"resources": [
"devfile.yaml"
],
"commandGroups": {
"build": true,
"run": true,
"test": false,
"debug": false,
"deploy": false
},
"starterProjects": [
"community",
"redhat-product"
],
"lastModified": "2024-04-29T17:08:43+03:00"
}
]
}
]
*/
/*
Index file schema definition
name: string - The stack name
version: string - The stack version
attributes: map[string]apiext.JSON - Map of implementation-dependant free-form YAML attributes
displayName: string - The display name of devfile
description: string - The description of devfile
type: DevfileType - The type of the devfile, currently supports stack and sample
tags: string[] - The tags associated to devfile
icon: string - The devfile icon
globalMemoryLimit: string - The devfile global memory limit
projectType: string - The project framework that is used in the devfile
language: string - The project language that is used in the devfile
links: map[string]string - Links related to the devfile
commandGroups: map[CommandGroupKind]bool - The command groups that are used in the devfile
deploymentScopes: map[DeploymentScopeKind]bool - The deployment scope that are detected in the devfile
resources: []string - The file resources that compose a devfile stack.
starterProjects: string[] - The project templates that can be used in the devfile
git: *git - The information of remote repositories
provider: string - The devfile provider information
versions: []Version - The list of stack versions information
lastModified: string - The date that a version of this stack/sample was last changed
*/
// Schema is the index file schema
type Schema struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Attributes map[string]apiext.JSON `yaml:"attributes,omitempty" json:"attributes,omitempty"`
DisplayName string `yaml:"displayName,omitempty" json:"displayName,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Type DevfileType `yaml:"type,omitempty" json:"type,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
GlobalMemoryLimit string `yaml:"globalMemoryLimit,omitempty" json:"globalMemoryLimit,omitempty"`
ProjectType string `yaml:"projectType,omitempty" json:"projectType,omitempty"`
Language string `yaml:"language,omitempty" json:"language,omitempty"`
Links map[string]string `yaml:"links,omitempty" json:"links,omitempty"`
CommandGroups map[CommandGroupKind]bool `yaml:"commandGroups,omitempty" json:"commandGroups,omitempty"`
DeploymentScopes map[DeploymentScopeKind]bool `yaml:"deploymentScopes,omitempty" json:"deploymentScopes,omitempty"`
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
Provider string `yaml:"provider,omitempty" json:"provider,omitempty"`
SupportUrl string `yaml:"supportUrl,omitempty" json:"supportUrl,omitempty"`
Versions []Version `yaml:"versions,omitempty" json:"versions,omitempty"`
LastModified string `yaml:"lastModified,omitempty" json:"lastModified,omitempty"`
}
// DevfileType describes the type of devfile
type DevfileType string
const (
// SampleDevfileType represents a sample devfile
SampleDevfileType DevfileType = "sample"
// StackDevfileType represents a stack devfile
StackDevfileType DevfileType = "stack"
)
// CommandGroupKind describes the kind of command group
type CommandGroupKind string
const (
BuildCommandGroupKind CommandGroupKind = "build"
RunCommandGroupKind CommandGroupKind = "run"
TestCommandGroupKind CommandGroupKind = "test"
DebugCommandGroupKind CommandGroupKind = "debug"
DeployCommandGroupKind CommandGroupKind = "deploy"
)
// DeploymentScopeKind describes the kind of deployment scope
type DeploymentScopeKind string
const (
InnerloopKind DeploymentScopeKind = "innerloop"
OuterloopKind DeploymentScopeKind = "outerloop"
)
// StarterProject is the devfile starter project
type StarterProject struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
}
// Commands stores the command information
type Commands struct {
Id string `yaml:"id,omitempty" json:"id,omitempty"`
Exec CommandType `yaml:"exec,omitempty" json:"exec,omitempty"`
Apply CommandType `yaml:"apply,omitempty" json:"apply,omitempty"`
Composite CommandType `yaml:"composite,omitempty" json:"composite,omitempty"`
}
// CommandType stores the group for a command
type CommandType struct {
Group CommandGroup `yaml:"group,omitempty" json:"group,omitempty"`
}
// CommandGroup stores the group information for a command
type CommandGroup struct {
Kind CommandGroupKind `yaml:"kind,omitempty" json:"kind,omitempty"`
IsDefault bool `yaml:"isDefault,omitempty" json:"isDefault,omitempty"`
}
// Devfile is the devfile structure that is used by index component
type Devfile struct {
Meta Schema `yaml:"metadata,omitempty" json:"metadata,omitempty"`
StarterProjects []StarterProject `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
Commands []Commands `yaml:"commands,omitempty" json:"commands,omitempty"`
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
}
// Git stores the information of remote repositories
type Git struct {
Remotes map[string]string `yaml:"remotes,omitempty" json:"remotes,omitempty"`
Url string `yaml:"url,omitempty" json:"url,omitempty"`
RemoteName string `yaml:"remoteName,omitempty" json:"remoteName,omitempty"`
SubDir string `yaml:"subDir,omitempty" json:"subDir,omitempty"`
Revision string `yaml:"revision,omitempty" json:"revision,omitempty"`
}
// ExtraDevfileEntries is the extraDevfileEntries structure that is used by index component
type ExtraDevfileEntries struct {
Samples []Schema `yaml:"samples,omitempty" json:"samples,omitempty"`
Stacks []Schema `yaml:"stacks,omitempty" json:"stacks,omitempty"`
}
// StackInfo stores the top-level stack information defined within stack.yaml
type StackInfo struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
DisplayName string `yaml:"displayName,omitempty" json:"displayName,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Versions []Version `yaml:"versions,omitempty" json:"versions,omitempty"`
}
// Version stores the information for each stack version
type Version struct {
Version string `yaml:"version,omitempty" json:"version,omitempty"`
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
Default bool `yaml:"default,omitempty" json:"default,omitempty"`
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Links map[string]string `yaml:"links,omitempty" json:"links,omitempty"`
CommandGroups map[CommandGroupKind]bool `yaml:"commandGroups,omitempty" json:"commandGroups,omitempty"`
DeploymentScopes map[DeploymentScopeKind]bool `yaml:"deploymentScopes,omitempty" json:"deploymentScopes,omitempty"`
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
LastModified string `yaml:"lastModified,omitempty" json:"lastModified,omitempty"`
}
type LastModifiedEntry struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
LastModified time.Time `yaml:"lastModified,omitempty" json:"lastModified,omitempty"`
}
type LastModifiedInfo struct {
Stacks []LastModifiedEntry `yaml:"stacks,omitempty" json:"stacks,omitempty"`
Samples []LastModifiedEntry `yaml:"samples,omitempty" json:"samples,omitempty"`
}