Skip to content

Commit

Permalink
feat(index/generator): adding command groups to index schema (#163)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoang <[email protected]>
  • Loading branch information
mike-hoang authored Feb 15, 2023
1 parent 3b53719 commit cdf58b1
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 55 deletions.
27 changes: 27 additions & 0 deletions index/generator/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,33 @@ func parseStackDevfile(devfileDirPath string, stackName string, force bool, vers
versionComponent.Links["self"] = fmt.Sprintf("%s/%s:%s", "devfile-catalog", stackName, versionComponent.Version)
versionComponent.SchemaVersion = devfile.SchemaVersion

kinds := []schema.CommandGroupKind{
schema.BuildCommandGroupKind,
schema.RunCommandGroupKind,
schema.TestCommandGroupKind,
schema.DebugCommandGroupKind,
schema.DeployCommandGroupKind,
}

if versionComponent.CommandGroups == nil {
versionComponent.CommandGroups = make(map[schema.CommandGroupKind]bool)
for _, kind := range kinds {
versionComponent.CommandGroups[kind] = false
}
}

for _, commands := range devfile.Commands {
if commands.Exec.Group.Kind != "" {
versionComponent.CommandGroups[commands.Exec.Group.Kind] = true
}
if commands.Apply.Group.Kind != "" {
versionComponent.CommandGroups[commands.Apply.Group.Kind] = true
}
if commands.Composite.Group.Kind != "" {
versionComponent.CommandGroups[commands.Composite.Group.Kind] = true
}
}

for _, starterProject := range devfile.StarterProjects {
versionComponent.StarterProjects = append(versionComponent.StarterProjects, starterProject.Name)
}
Expand Down
103 changes: 72 additions & 31 deletions index/generator/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ Sample index file:
"resources": [
"devfile.yaml"
],
"commandGroups": {
"build": true,
"run": true,
"test": false,
"debug": false,
"deploy": false
},
"starterProjects": [
"community",
"redhat-product"
Expand All @@ -122,6 +129,7 @@ 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
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
Expand All @@ -131,25 +139,26 @@ versions: []Version - The list of stack versions information

// 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"`
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"`
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"`
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"`
}

// DevfileType describes the type of devfile
Expand All @@ -163,15 +172,46 @@ const (
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"
)

// 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"`
}

Expand All @@ -190,7 +230,7 @@ type ExtraDevfileEntries struct {
Stacks []Schema `yaml:"stacks,omitempty" json:"stacks,omitempty"`
}

// Version stores the top-level stack information defined within stack.yaml
// 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"`
Expand All @@ -201,15 +241,16 @@ type StackInfo struct {

// 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"`
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
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"`
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
}
108 changes: 96 additions & 12 deletions index/generator/tests/registry/index_main.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
"self": "devfile-catalog/go:1.2.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["go-starter"]
"starterProjects": ["go-starter"],
"commandGroups": {
"build": true,
"debug": false,
"deploy": false,
"run": true,
"test": false
}
},
{
"version": "1.1.0",
Expand All @@ -33,7 +40,14 @@
"self": "devfile-catalog/go:1.1.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["go-starter"]
"starterProjects": ["go-starter"],
"commandGroups": {
"build": true,
"debug": false,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand All @@ -57,7 +71,14 @@
"self": "devfile-catalog/java-maven:1.1.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["springbootproject"]
"starterProjects": ["springbootproject"],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand All @@ -79,7 +100,14 @@
"self": "devfile-catalog/java-openliberty:0.5.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["user-app"]
"starterProjects": ["user-app"],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": true
}
}
]
},
Expand All @@ -103,7 +131,14 @@
"self": "devfile-catalog/java-quarkus:1.1.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["community", "redhat-product"]
"starterProjects": ["community", "redhat-product"],
"commandGroups": {
"build": false,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand All @@ -128,7 +163,14 @@
"self": "devfile-catalog/java-springboot:1.1.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["springbootproject"]
"starterProjects": ["springbootproject"],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand Down Expand Up @@ -171,7 +213,14 @@
"vertx-configmap-example-redhat",
"vertx-messaging-work-queue-booster",
"vertx-istio-distributed-tracing-booster"
]
],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand Down Expand Up @@ -203,7 +252,14 @@
"microprofile-openapi",
"microprofile-opentracing",
"microprofile-rest-client"
]
],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand Down Expand Up @@ -243,7 +299,14 @@
"microprofile-openapi",
"microprofile-opentracing",
"microprofile-rest-client"
]
],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand All @@ -266,7 +329,14 @@
"self": "devfile-catalog/nodejs:1.0.0"
},
"resources": ["archive.tar", "devfile.yaml"],
"starterProjects": ["nodejs-starter"]
"starterProjects": ["nodejs-starter"],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": true
}
}
]
},
Expand All @@ -289,7 +359,14 @@
"self": "devfile-catalog/python:1.0.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["python-example"]
"starterProjects": ["python-example"],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand All @@ -312,7 +389,14 @@
"self": "devfile-catalog/python-django:1.0.0"
},
"resources": ["devfile.yaml"],
"starterProjects": ["django-example"]
"starterProjects": ["django-example"],
"commandGroups": {
"build": true,
"debug": true,
"deploy": false,
"run": true,
"test": false
}
}
]
},
Expand Down
Loading

0 comments on commit cdf58b1

Please sign in to comment.