Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DevWorkspace Operator contributions attributes to inject editors into Devfile containers #716

Merged
merged 6 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
| [`@bcoe/[email protected]`](git://github.com/demurgos/v8-coverage.git) | MIT | clearlydefined |
| [`@cnakazawa/[email protected]`](git://github.com/mikeal/watch.git) | Apache-2.0 | clearlydefined |
| [`@csstools/[email protected]`](https://github.com/csstools/postcss-plugins.git) | CC0-1.0 | clearlydefined |
| [`@devfile/[email protected]`](https://github.com/devfile/api.git) | EPL-2.0 | clearlydefined |
| [`@discoveryjs/[email protected]`](https://github.com/discoveryjs/json-ext.git) | MIT | clearlydefined |
| [`@eslint/[email protected]`](https://github.com/eslint/eslintrc.git) | MIT | clearlydefined |
| [`@gar/[email protected]`](https://github.com/wraithgar/gar-promisify.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -284,7 +285,6 @@
| [`[email protected]`](https://github.com/micromatch/anymatch) | ISC | #5050 |
| [`[email protected]`](https://github.com/iarna/aproba) | ISC | clearlydefined |
| [`[email protected]`](https://github.com/npm/are-we-there-yet.git) | ISC | clearlydefined |
| [`[email protected]`](https://github.com/nodeca/argparse.git) | MIT | #2174 |
| [`[email protected]`](git+https://github.com/A11yance/aria-query.git) | Apache-2.0 | clearlydefined |
| [`[email protected]`](https://github.com/jonschlinkert/arr-diff.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jonschlinkert/arr-flatten.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -559,7 +559,7 @@
| [`[email protected]`](git://github.com/isaacs/ini.git) | ISC | [CQ23023](https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23023) |
| [`[email protected]`](https://github.com/npm/init-package-json.git) | ISC | clearlydefined |
| [`[email protected]`](https://github.com/SBoudrias/Inquirer.js.git) | MIT | clearlydefined |
| [`[email protected]`](git+https://github.com/ljharb/internal-slot.git) | MIT | clearlydefined |
| [`[email protected]`](git+https://github.com/ljharb/internal-slot.git) | MIT | #7118 |
| [`[email protected]`](https://github.com/gulpjs/interpret.git) | MIT | clearlydefined |
| [`[email protected]`](http://github.com/indutny/node-ip.git) | MIT | #126 |
| [`[email protected]`](git://github.com/whitequark/ipaddr.js) | MIT | clearlydefined |
Expand Down Expand Up @@ -633,7 +633,6 @@
| [`[email protected]`](git+https://github.com/romgain/jest-websocket-mock.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/facebook/jest.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/facebook/jest) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/nodeca/js-yaml.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jsdom/jsdom.git) | MIT | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/jsdom/16.7.0) |
| [`[email protected]`](https://github.com/zkat/json-parse-better-errors) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/npm/json-parse-even-better-errors) | MIT | clearlydefined |
Expand Down Expand Up @@ -737,7 +736,7 @@
| [`[email protected]`]([email protected]:indutny/offset-buffer) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jshttp/on-finished.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jshttp/on-headers.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/sindresorhus/open.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/sindresorhus/open.git) | MIT | #7102 |
| [`[email protected]`](git://github.com/gkz/optionator.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/sindresorhus/p-each-series.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/sindresorhus/p-finally.git) | MIT | clearlydefined |
Expand Down
10 changes: 5 additions & 5 deletions .deps/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
| Packages | License | Resolved CQs |
| --- | --- | --- |
| [`@babel/[email protected]`](https://github.com/babel/babel.git) | MIT | #1946 |
| [`@devfile/[email protected].0-alpha-1646855991`](https://github.com/devfile/api.git) | EPL-2.0 | clearlydefined |
| [`@devfile/[email protected].1-alpha-1667236163`](https://github.com/devfile/api.git) | Apache-2.0 | N/A |
| `@eclipse-che/[email protected]` | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](git+https://github.com/che-incubator/che-code.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](git+https://github.com/eclipse-che/che-theia.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](git+https://github.com/eclipse-che/che-devfile-registry.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/[email protected]`](git://github.com/eclipse/che-dashboard.git) | EPL-2.0 | ecd.che |
Expand Down Expand Up @@ -170,7 +169,7 @@
| [`[email protected]`](git+https://github.com/focus-trap/focus-trap.git) | MIT | clearlydefined |
| [`[email protected]`]([email protected]:follow-redirects/follow-redirects.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/mikeal/forever-agent) | Apache-2.0 | clearlydefined |
| [`form-data@2.5.1`](git://github.com/form-data/form-data.git) | MIT | clearlydefined |
| [`form-data@2.3.3`](git://github.com/form-data/form-data.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jshttp/forwarded.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jshttp/fresh.git) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jprichardson/node-fs-extra) | MIT | clearlydefined |
Expand Down Expand Up @@ -202,6 +201,7 @@
| [`[email protected]`](git://github.com/TooTallNate/node-http-proxy-agent.git) | MIT | clearlydefined |
| [`[email protected]`](git://github.com/joyent/node-http-signature.git) | MIT | #2732 |
| [`[email protected]`](git://github.com/TooTallNate/node-https-proxy-agent.git) | MIT | clearlydefined |
| `[email protected]` | ISC | clearlydefined |
| [`[email protected]`](https://github.com/ehmicky/human-signals.git) | Apache-2.0 | clearlydefined |
| [`[email protected]`](git://github.com/feross/ieee754.git) | BSD-3-Clause | clearlydefined |
| [`[email protected]`](git://github.com/immutable-js/immutable-js.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -231,7 +231,7 @@
| [`[email protected]`](git+https://github.com/epoberezkin/json-schema-traverse.git) | MIT | clearlydefined |
| [`[email protected]`](http://github.com/kriszyp/json-schema) | (AFL-2.1 OR BSD-3-Clause) | #2410 |
| [`[email protected]`](git://github.com/isaacs/json-stringify-safe) | ISC | clearlydefined |
| [`json5@0.5.1`](https://github.com/aseemk/json5.git) | MIT | #1040 |
| [`json5@1.0.1`](git+https://github.com/json5/json5.git) | MIT | [CQ22351](https://dev.eclipse.org/ipzilla/show_bug.cgi?id=22351) |
| [`[email protected]`](https://github.com/microsoft/node-jsonc-parser) | MIT | clearlydefined |
| [`[email protected]`]([email protected]:jprichardson/node-jsonfile.git) | MIT | clearlydefined |
| [`[email protected]`](git://github.com/s3u/JSONPath.git) | MIT | clearlydefined |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
run: yarn lint:check
-
name: "Run unit tests"
run: yarn test --runInBand
run: yarn test

docker-build:
needs: build-and-test
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ Then you can proceed to the following steps:
```sh
# 1. Install all dependencies:
yarn
# 2. Patch cluster to enable local development flow:
# 2. (Optional) Patch minikube cluster to enable local development flow:
yarn start:prepare
# 3. Run server locally:
# 3. Export Che certificate
chectl cacert:export --destination=$TMPDIR
# 4. Set CHE_SELF_SIGNED_MOUNT_PATH
export CHE_SELF_SIGNED_MOUNT_PATH=$TMPDIR
# 5. Run server locally:
yarn start
# 4. (optional) Patch cluster to revert it to initial state:
# 6. (optional) Patch cluster to revert it to initial state:
yarn start:cleanup
# If you want to make sure the latest bits are used, add flag to recompile
# yarn start --force-build
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"license:generate": "docker run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses:next",
"test": "lerna run test --stream -- --no-cache $@",
"pretest": "yarn run prebuild",
"test:coverage": "yarn run test -- --runInBand --coverage",
"test:coverage": "yarn run test -- --coverage",
"format:check": "yarn workspaces run format:check",
"format:fix": "lerna run --stream format:fix",
"lint:check": "yarn workspaces run lint:check",
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/dto/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ export interface IDevWorkspaceList {
};
items: V1alpha2DevWorkspace[];
}

export interface IDevworkspaceResources {
devfileContent: string | undefined;
editorPath: string | undefined;
pluginRegistryUrl: string | undefined;
editorEntry: string | undefined;
editorContent: string | undefined;
}
5 changes: 4 additions & 1 deletion packages/dashboard-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
],
"license": "EPL-2.0",
"dependencies": {
"@devfile/api": "^2.2.0-alpha-1633545768",
"@devfile/api": "^2.2.1-alpha-1667236163",
"@eclipse-che/che-devworkspace-generator": "0.0.1-96cdbb4",
"@fastify/cors": "^7.0.0",
"@fastify/error": "^3.0.0",
"@fastify/http-proxy": "^7.1.0",
Expand All @@ -38,6 +39,8 @@
"axios": "^0.21.4",
"fastify": "^3.29.1",
"fs-extra": "9.1.0",
"https": "^1.0.0",
"js-yaml": "^4.0.0",
"node-fetch": "^2.6.7",
"querystring": "^0.2.1",
"reflect-metadata": "^0.1.13",
Expand Down
3 changes: 3 additions & 0 deletions packages/dashboard-backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { registerWorkspaceRedirect } from './routes/workspaceRedirect';
import { registerDevfileSchemaRoute } from './routes/api/devfileSchema';
import { registerEventsRoutes } from './routes/api/events';
import { registerPodsRoutes } from './routes/api/pods';
import { registerDevworkspaceResourcesRoute } from './routes/api/devworkspaceResources';

export default async function buildApp(server: FastifyInstance): Promise<void> {
const cheHost = process.env.CHE_HOST as string;
Expand Down Expand Up @@ -106,4 +107,6 @@ export default async function buildApp(server: FastifyInstance): Promise<void> {
registerYamlResolverRoute(server);

registerDevfileSchemaRoute(server);

registerDevworkspaceResourcesRoute(server);
}
26 changes: 26 additions & 0 deletions packages/dashboard-backend/src/constants/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Red Hat, Inc. - initial API and implementation
*/

import { dump } from 'js-yaml';

export const dockerConfigExample = {
get dockerconfig() {
const registry = 'https://index.docker.io/v1/';
Expand All @@ -29,3 +31,27 @@ export const dockerConfigExample = {
).toString('base64');
},
};

export const devWorkspaceResourcesExample = {
get devfileContent() {
const devfile = {
schemaVersion: '2.1.0',
metadata: {
name: 'wksp-test',
},
components: [
{
container: {
image: 'quay.io/devfile/universal-developer-image:latest',
sourceMapping: '/projects',
},
name: 'universal-developer-image',
},
],
};

return dump(devfile, { indent: 2 });
},
editorEntry: 'che-incubator/che-code/insiders',
projects: [],
};
35 changes: 34 additions & 1 deletion packages/dashboard-backend/src/constants/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

import { dockerConfigExample } from './examples';
import { dockerConfigExample, devWorkspaceResourcesExample } from './examples';
import { JSONSchema7 } from 'json-schema';

export const authenticationHeaderSchema: JSONSchema7 = {
Expand Down Expand Up @@ -149,6 +149,39 @@ export const yamlResolverSchema: JSONSchema7 = {
required: ['url'],
};

export const devWorkspaceResourcesSchema: JSONSchema7 = {
type: 'object',
properties: {
devfileContent: {
type: 'string',
},
editorPath: {
type: 'string',
},
pluginRegistryUrl: {
type: 'string',
},
editorEntry: {
type: 'string',
},
projects: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
location: {
type: 'string',
},
},
},
},
},
examples: [devWorkspaceResourcesExample],
};

export const devworkspaceSchema: JSONSchema7 = {
type: 'object',
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

import { V220DevfileComponents } from '@devfile/api';
import { V221DevfileComponents } from '@devfile/api';
import { api } from '@eclipse-che/common';
import * as k8s from '@kubernetes/client-node';
import {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class ServerConfigApiService implements IServerConfigApi {
return cheCustomResource.spec.devEnvironments?.defaultEditor;
}

getDefaultComponents(cheCustomResource: CustomResourceDefinition): V220DevfileComponents[] {
getDefaultComponents(cheCustomResource: CustomResourceDefinition): V221DevfileComponents[] {
return cheCustomResource.spec.devEnvironments?.defaultComponents || [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import {
V1alpha2DevWorkspace,
V1alpha2DevWorkspaceTemplate,
V220DevfileComponents,
V221DevfileComponents,
} from '@devfile/api';
import { api } from '@eclipse-che/common';
import * as k8s from '@kubernetes/client-node';
Expand Down Expand Up @@ -115,7 +115,7 @@ export type CustomResourceDefinitionSpecDevEnvironments = {
containerBuildConfiguration?: {
openShiftSecurityContextConstraint?: string;
};
defaultComponents?: V220DevfileComponents[];
defaultComponents?: V221DevfileComponents[];
defaultEditor?: string;
defaultPlugins?: api.IWorkspacesDefaultPlugins[];
disableContainerBuildCapabilities?: boolean;
Expand Down Expand Up @@ -170,7 +170,7 @@ export interface IServerConfigApi {
* Returns the default components applied to DevWorkspaces.
* These default components are meant to be used when a Devfile does not contain any components.
*/
getDefaultComponents(cheCustomResource: CustomResourceDefinition): V220DevfileComponents[];
getDefaultComponents(cheCustomResource: CustomResourceDefinition): V221DevfileComponents[];
/**
* Returns the openVSX URL.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018-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
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { FastifyInstance, FastifyRequest } from 'fastify';
import { baseApiPath } from '../../constants/config';
import { getSchema } from '../../services/helpers';
import { devWorkspaceResourcesSchema } from '../../constants/schemas';
import { dump } from 'js-yaml';
import { Main as DevworkspaceGenerator } from '@eclipse-che/che-devworkspace-generator/lib/main';
import { V1alpha2DevWorkspaceTemplate } from '@devfile/api';
import { axiosInstance } from './helpers/getCertificateAuthority';
import { api } from '@eclipse-che/common';

const tags = ['DevWorkspace Resources'];

export function registerDevworkspaceResourcesRoute(server: FastifyInstance) {
const generator = new DevworkspaceGenerator();

server.post(
`${baseApiPath}/devworkspace-resources`,
getSchema({ tags, body: devWorkspaceResourcesSchema }),
async function (request: FastifyRequest) {
const { devfileContent, editorPath, pluginRegistryUrl, editorEntry, editorContent } =
request.body as api.IDevworkspaceResources;
const context = await generator.generateDevfileContext(
{
devfileContent,
editorPath,
pluginRegistryUrl,
editorEntry,
editorContent,
projects: [],
},
axiosInstance,
);
// write templates and then DevWorkspace in a single file
const allContentArray = context.devWorkspaceTemplates.map(
(template: V1alpha2DevWorkspaceTemplate) => dump(template),
);
allContentArray.push(dump(context.devWorkspace));

return allContentArray.join('---\n');
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {
V1alpha2DevWorkspace,
V1alpha2DevWorkspaceTemplate,
V220DevfileComponents,
V221DevfileComponents,
} from '@devfile/api';
import { api } from '@eclipse-che/common';
import {
Expand All @@ -33,7 +33,7 @@ export const stubContainerBuild = {
disableContainerBuildCapabilities: true,
};
export const stubDashboardWarning = 'Dashboard warning';
export const stubDefaultComponents: V220DevfileComponents[] = [];
export const stubDefaultComponents: V221DevfileComponents[] = [];
export const stubDefaultEditor = undefined;
export const stubDefaultPlugins: api.IWorkspacesDefaultPlugins[] = [];
export const stubOpenVSXURL = 'openvsx-url';
Expand Down
Loading