This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add schema validation to the generator
Signed-off-by: Valeriy Svydenko <[email protected]>
- Loading branch information
Showing
30 changed files
with
9,362 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2,852 changes: 2,852 additions & 0 deletions
2,852
tools/devworkspace-generator/src/devfile-schema/2.0.0/devfile.json
Large diffs are not rendered by default.
Oops, something went wrong.
1,430 changes: 1,430 additions & 0 deletions
1,430
tools/devworkspace-generator/src/devfile-schema/2.1.0/devfile.json
Large diffs are not rendered by default.
Oops, something went wrong.
2,037 changes: 2,037 additions & 0 deletions
2,037
tools/devworkspace-generator/src/devfile-schema/2.2.0/devfile.json
Large diffs are not rendered by default.
Oops, something went wrong.
2,037 changes: 2,037 additions & 0 deletions
2,037
tools/devworkspace-generator/src/devfile-schema/2.2.1-alpha/devfile.json
Large diffs are not rendered by default.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
tools/devworkspace-generator/src/devfile-schema/devfile-schema-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
import { ContainerModule, interfaces } from 'inversify'; | ||
|
||
import { DevfileSchemaValidator } from './devfile-schema-validator'; | ||
|
||
const devfileSchemaModule = new ContainerModule((bind: interfaces.Bind) => { | ||
bind(DevfileSchemaValidator).toSelf().inSingletonScope(); | ||
}); | ||
|
||
export { devfileSchemaModule }; |
43 changes: 43 additions & 0 deletions
43
tools/devworkspace-generator/src/devfile-schema/devfile-schema-validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
import { injectable } from 'inversify'; | ||
|
||
import * as devfileSchemaV200 from './2.0.0/devfile.json'; | ||
import * as devfileSchemaV210 from './2.1.0/devfile.json'; | ||
import * as devfileSchemaV220 from './2.2.0/devfile.json'; | ||
import * as devfileSchemaV221Alpha from './2.2.1-alpha/devfile.json'; | ||
import * as Validator from 'jsonschema'; | ||
import { DevfileSchemaVersion } from '../api/devfile-context'; | ||
|
||
@injectable() | ||
export class DevfileSchemaValidator { | ||
getDevfileSchema(version: string) { | ||
switch (version) { | ||
case DevfileSchemaVersion.V200: | ||
return devfileSchemaV200; | ||
case DevfileSchemaVersion.V210: | ||
return devfileSchemaV210; | ||
case DevfileSchemaVersion.V220: | ||
return devfileSchemaV220; | ||
case DevfileSchemaVersion.V221_alpha: | ||
return devfileSchemaV221Alpha; | ||
default: | ||
throw new Error(`Dev Workspace generator tool doesn't support devfile version: ${version}`); | ||
} | ||
} | ||
|
||
// Validates devfile against schema | ||
validateDevfile(devfile: any, version: string) { | ||
const schema = this.getDevfileSchema(version); | ||
const validatorResult = Validator.validate(devfile, schema, { nestedErrors: true }); | ||
|
||
return validatorResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tools/devworkspace-generator/tests/_data/devfile/2.0.0/ansible-devfile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
schemaVersion: 2.0.0 | ||
metadata: | ||
name: ansible-demo | ||
namespace: svor-che | ||
projects: | ||
- name: ansible-devspaces-demo | ||
git: | ||
remotes: | ||
origin: https://github.com/svor/ansible-devspaces-demo.git | ||
checkoutFrom: | ||
revision: sv-test-pr-with-new-ee-image | ||
components: | ||
- name: tooling-container | ||
container: | ||
image: quay.io/vsvydenk/ansible-creator-ee:base20 | ||
memoryLimit: 6Gi | ||
args: | ||
- tail | ||
- '-f' | ||
- /dev/null | ||
commands: | ||
- id: oc-install | ||
exec: | ||
commandLine: /usr/local/bin/ansible-playbook ${PROJECT_SOURCE}/playbooks/install_oc.yml | ||
workingDir: ${PROJECT_SOURCE} | ||
group: | ||
kind: build | ||
isDefault: true | ||
component: tooling-container | ||
- id: molecule-test | ||
exec: | ||
label: 'Molecule: Run Scenario for Backup Role' | ||
commandLine: source $HOME/.bashrc && molecule test | ||
workingDir: ${PROJECTS_ROOT}/ansible-devspaces-demo/collections/example/collection/roles/backup_file | ||
group: | ||
kind: run | ||
isDefault: true | ||
component: tooling-container | ||
- id: molecule-verify | ||
exec: | ||
label: 'Molecule: Validate Backup File Role' | ||
commandLine: source $HOME/.bashrc && molecule verify | ||
workingDir: ${PROJECTS_ROOT}/ansible-devspaces-demo/collections/example/collection/roles/backup_file | ||
group: | ||
kind: run | ||
isDefault: true | ||
component: tooling-container | ||
events: | ||
postStart: | ||
- oc-install |
8 changes: 8 additions & 0 deletions
8
tools/devworkspace-generator/tests/_data/devfile/2.0.0/empty-devfile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
schemaVersion: 2.0.0 | ||
metadata: | ||
name: empty | ||
namespace: svor-che | ||
components: | ||
- name: universal-developer-image | ||
container: | ||
image: quay.io/devfile/universal-developer-image:ubi8-latest |
103 changes: 103 additions & 0 deletions
103
tools/devworkspace-generator/tests/_data/devfile/2.0.0/quarkus-api-devfile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
schemaVersion: 2.0.0 | ||
metadata: | ||
generateName: quarkus-api-example | ||
components: | ||
- name: tools | ||
container: | ||
image: quay.io/devfile/universal-developer-image:ubi8-latest | ||
env: | ||
- name: QUARKUS_HTTP_HOST | ||
value: 0.0.0.0 | ||
endpoints: | ||
- exposure: none | ||
name: debug | ||
protocol: tcp | ||
targetPort: 5005 | ||
- exposure: public | ||
name: list-all-food | ||
protocol: http | ||
targetPort: 8080 | ||
path: /food | ||
volumeMounts: | ||
- name: m2 | ||
path: /home/user/.m2 | ||
memoryLimit: 6G | ||
mountSources: true | ||
|
||
- name: postgresql | ||
container: | ||
image: 'quay.io/centos7/postgresql-13-centos7@sha256:994f5c622e2913bda1c4a7fa3b0c7e7f75e7caa3ac66ff1ed70ccfe65c40dd75' | ||
env: | ||
- name: POSTGRESQL_USER | ||
value: user | ||
- name: POSTGRESQL_PASSWORD | ||
value: password | ||
- name: POSTGRESQL_DATABASE | ||
value: food_db | ||
- name: PGDATA | ||
value: /tmp/pgdata | ||
- name: m2 | ||
volume: | ||
size: 1G | ||
commands: | ||
- id: package | ||
exec: | ||
label: "Package" | ||
component: tools | ||
workingDir: ${PROJECTS_ROOT}/quarkus-api-example | ||
commandLine: "./mvnw clean package -DskipTests=true" | ||
group: | ||
kind: build | ||
isDefault: true | ||
- id: runtests | ||
exec: | ||
label: "Run Tests" | ||
component: tools | ||
workingDir: ${PROJECTS_ROOT}/quarkus-api-example | ||
commandLine: "./mvnw test" | ||
group: | ||
kind: test | ||
- id: packagenative | ||
exec: | ||
label: "Package Native" | ||
component: tools | ||
workingDir: ${PROJECTS_ROOT}/quarkus-api-example | ||
commandLine: "./mvnw package -Dnative -Dmaven.test.skip -Dquarkus.native.native-image-xmx=3G" | ||
group: | ||
kind: build | ||
- id: startdev | ||
exec: | ||
label: "Start Development mode (Hot reload + debug)" | ||
component: tools | ||
workingDir: ${PROJECTS_ROOT}/quarkus-api-example | ||
commandLine: "./mvnw compile quarkus:dev" | ||
group: | ||
kind: run | ||
isDefault: true | ||
- id: startnative | ||
exec: | ||
label: "Start Native" | ||
component: tools | ||
workingDir: ${PROJECTS_ROOT}/quarkus-api-example/target | ||
commandLine: "./quarkus-api-example-1.0.0-SNAPSHOT-runner" | ||
group: | ||
kind: run | ||
- id: buildimage | ||
exec: | ||
label: "Build Image" | ||
component: tools | ||
workingDir: ${PROJECT_SOURCE} | ||
commandLine: "podman build -f src/main/docker/Dockerfile.jvm -t quay.io/che-incubator/quarkus-api-example ." | ||
group: | ||
kind: build | ||
- id: deploypostgres | ||
exec: | ||
label: "Deploy Postrgres" | ||
component: tools | ||
workingDir: ${PROJECTS_ROOT}/quarkus-api-example | ||
commandLine: "oc new-app -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=password -e POSTGRESQL_DATABASE=food_db postgresql:10-el7 -n demo" | ||
group: | ||
kind: test | ||
events: | ||
postStart: | ||
- package |
53 changes: 53 additions & 0 deletions
53
tools/devworkspace-generator/tests/_data/devfile/2.1.0/ansible-devfile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
schemaVersion: 2.1.0 | ||
metadata: | ||
name: ansible-demo | ||
namespace: svor-che | ||
projects: | ||
- name: ansible-devspaces-demo | ||
git: | ||
remotes: | ||
origin: https://github.com/svor/ansible-devspaces-demo.git | ||
checkoutFrom: | ||
revision: sv-test-pr-with-new-ee-image | ||
components: | ||
- name: tooling-container | ||
container: | ||
image: quay.io/vsvydenk/ansible-creator-ee:base20 | ||
memoryRequest: 256M | ||
memoryLimit: 6Gi | ||
cpuRequest: 250m | ||
cpuLimit: 2000m | ||
args: | ||
- tail | ||
- '-f' | ||
- /dev/null | ||
commands: | ||
- id: oc-install | ||
exec: | ||
commandLine: /usr/local/bin/ansible-playbook ${PROJECT_SOURCE}/playbooks/install_oc.yml | ||
workingDir: ${PROJECT_SOURCE} | ||
group: | ||
kind: build | ||
isDefault: true | ||
component: tooling-container | ||
- id: molecule-test | ||
exec: | ||
label: 'Molecule: Run Scenario for Backup Role' | ||
commandLine: source $HOME/.bashrc && molecule test | ||
workingDir: ${PROJECTS_ROOT}/ansible-devspaces-demo/collections/example/collection/roles/backup_file | ||
group: | ||
kind: run | ||
isDefault: true | ||
component: tooling-container | ||
- id: molecule-verify | ||
exec: | ||
label: 'Molecule: Validate Backup File Role' | ||
commandLine: source $HOME/.bashrc && molecule verify | ||
workingDir: ${PROJECTS_ROOT}/ansible-devspaces-demo/collections/example/collection/roles/backup_file | ||
group: | ||
kind: run | ||
isDefault: true | ||
component: tooling-container | ||
events: | ||
postStart: | ||
- oc-install |
Oops, something went wrong.