Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Usage of Eclipse Che 7 Workspace

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "the use of Eclipse Che 7 Workspace". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the usage of Eclipse Che 7 Workspace.

The Eclipse Che workspace is defined by devfile. Devfile is the definition of everything used in the developer's workspace.

Che is defined using devfiles:

Clone project

Browser IDE used

Preconfigured command

The tools you need

Application runtime definition

When you create a workspace, Che uses this definition to initialize everything for you and run all containers for your tools and applications at runtime. Che also installs file system volumes to make your source code available to the workspace.

Devfiles can be versioned using the project source code. When you need a workspace to repair the old maintenance branch, the project devfile provides you with a definition of the workspace that contains tools and exact dependencies to start working on the old branch. Use it to easily instantiate a workspace on demand.

Che uses the tools you use in the workspace to maintain the latest information about devfile:

Project of the workspace (path, Git location, branch)

Commands to perform routine tasks (build, run, test, debug)

Runtime environment (container image used to run the application)

Che-Theia plug-ins with tools, IDE features, and helpers (Git,Java support, Sonarlint,Pull Request) that developers will use in the workspace

Start the workspace using devfile

This section describes how to start the Che workspace using your own existing devfile.

precondition

A running instance of Eclipse Che. To install an instance of Eclipse Che, see Che'quick-starts'.

The existing workspace defined on this Eclipse Che instance creates the workspace from the user dashboard.

There are several ways to start a Che workspace based on a prepared dev file:

Devfile from Git

Add devfile to the Git source repository, and then create a factory from that repository.

Place the devfile.yaml file in the root directory of the Git repository.

Execute the factory by opening the following URL:

Https:// / fanciurl = Devfile in https://github.com/ / URL

Execute devfile by using a URL construction factory that points to the original content of devfile, for example:

Https:// / fanciurl = https://pastebin.com/raw/ux6iCGaW Devfile using the chectl tool

Use the workspace:start parameter with the chectl tool to execute the workspace from devfile, as follows:

$chectl workspace:start-- devfile=devfile.yaml writes devfile for the project

This section describes how to create a minimum devfile for your project and how to include multiple projects in devfile.

Example of a minimum devfile without a project

The minimum devfile prepared to run the workspace consists of the following parts:

Specification version

Name

ApiVersion: 1.0.0metadata: name: minimal-workspace example of minimum devfile with project

No further configuration is required, and the workspace with the default editor starts with its default plug-ins, which are configured on Che Server. Che-Theia is configured as the default editor along with the Che Machine Exec plug-in.

Add the following sections to achieve a more useful workspace:

Component list: development components and user runtime

Project list: source code repository

Command list: used to manage the actions of workspace components, such as running development tools, starting the runtime environment, etc.

ApiVersion: 1.0.0metadata: name: petclinic-dev-environmentprojects:-name: petclinic source: type: git location: 'https://github.com/spring-projects/spring-petclinic.git'components:-type: chePlugin id: redhat/java/latest devfile example with two projects

Specify multiple projects in devfile. A devfile can specify multiple projects. For each project, specify the type of source repository, its location, and, optionally, the directory to which you want to clone the project.

ApiVersion: 1.0.0metadata: name: example-devfileprojects:- name: frontend source: type: git location: https://github.com/acmecorp/frontend.git- name: backend clonePath: src/github.com/acmecorp/backend source: type: git location: https://github.com/acmecorp/backend.git

In the previous example, two projects are defined, the front end and the back end. Each project is located in its own repository. The back-end project has a special requirement that it must be cloned to the src/github.com/acmecorp/ backend/ directory under the source root (defined implicitly by the Che runtime), while the front-end project will be cloned to the root in the frontend / directory under the source directory.

Additional resources

For a detailed description of all devfile component assignments and possible values, see:

Specification base

Detailed json schema documentation

These sample devfile are a good source of inspiration:

Sample devfile for the Eclipse Che workspace used by default in the user interface.

Sample devfile from the Eclipse Che workspace of the Red Hat Developer program.

Devfile referenc

This section contains the devfile reference and instructions on how to use the various elements made up of devfile.

Add components to devfile

Each component in a single devfile must have a unique name.

Component type: cheEditor

Describe the editor used in the workspace by defining its ID. A devfile can contain only one component of type cheEditor.

Components:-alias: theia-editor type: cheEditor id: eclipse/che-theia/next

If cheEditor is missing, the default editor and its default plug-in are provided. Default plug-ins are also provided for explicitly defined editors that have the same ID as the default ID (even if it is a different version). Che-Theia is configured as the default editor along with the Che Machine Exec plug-in.

To specify that the workspace does not require an editor, use the editorFree:true property in the devfile property.

Component type: chePlugin

Plug-ins in the workspace are described by defining a plug-in ID. Multiple chePlugin components are allowed.

Components:-alias: exec-plugin type: chePlugin id: eclipse/che-machine-exec-plugin/0.0.1

Both of the above types use id (that is, the publisher separated by slashes), the name and version of the plug-in in the Che Plugin registry. A list of available Che plug-ins and more information about the registry can be found on https://github.com/eclipse/che-plugin-registry.

Specify the alternate component registry

To specify an alternative registry for the cheEditor and chePlugin component types, use the RegistryUrl parameter:

Components:-alias: exec-plugin type: chePlugin registryUrl: https://my-customregistry.com id: eclipse/che-machine-exec-plugin/0.0.1 specifies the component by linking to its descriptor

An alternative to specifying cheEditor or chePlugin, instead of using the editor or plug-in ID (and optionally the alternative registry), is to provide a direct link to the component descriptor (typically called meta.yaml) by using reference fields:

Components:-alias: exec-plugin type: chePlugin reference: https://raw.githubusercontent.com.../plugin/1.0.1/meta.yaml

You cannot mix id and reference fields in a single component definition. They are mutually exclusive.

Specify the container memory limit for the component

To specify the memory limit for the container for cheEditor or chePlugin, use the memoryLimit parameter:

Components:-alias: exec-plugin type: chePlugin id: eclipse/che-machine-exec-plugin/0.0.1 memoryLimit: 256m

This restriction applies to each container for a given component.

Adjust component configuration

You may need to fine-tune the component, in which case you can use component preferences. This example shows how to configure JVM using plug-in preferences.

Id: redhat/java/0.38.0 type: chePlugin preferences: java.jdt.ls.vmargs:'- noverify-Xmx1G-XX:+UseG1GC-XX:+UseStringDeduplication' component type: kubernetes

A complex type of component that allows configuration to be applied from a Kubernetes or OpenShift list. You can provide the content of a component by referencing a property that points to a file with the content of the component.

Components:-alias: mysql type: kubernetes reference: petclinic.yaml selector: app.kubernetes.io/name: mysql app.kubernetes.io/component: database app.kubernetes.io/part-of: petclinic

In addition, to publish a devfile with such components to REST API, you can use the referenceContent field to embed the contents of the Kubernetes or OpenShift list into the devfile:

Components:-alias: mysql type: kubernetes reference: petclinic.yaml referenceContent: | kind: List items:-apiVersion: V1 kind: Pod metadata: name: ws spec: containers:. Etc

As with the dockerimage component, you can use the command and args attributes to override the entry point of containers contained in the Kubernetes or OpenShift list (Kubernetes can understand).

There can be more containers in the list (included in the deployed Pod or Pod template). Selecting the container to which you want to apply the entry point changes.

The entry point can be defined as follows:

Components:-alias: appDeployment type: kubernetes reference: app-deployment.yaml entrypoints:-parentName: mysqlServer command: ['sleep'] args: [' infinity']-parentSelector: app: prometheus args: ['- fags,'/ opt/app/prometheus-config.yaml']

The list of entry points contains the constraints used to select containers and the commands and args parameters to apply to them. In the above example, the constraint is parentName:mysqlServer, which causes the command to be applied to all containers defined in any parent object named mysqlServer. Assume that the parent object is the top-level object in the list defined in the reference file, which in the example above is app-deployment.yaml.

Other types of constraints (and their combinations) are also possible:

ContainerName: name of the container

ParentName: (indirectly) the name of the parent object that contains the container to be overwritten

ParentSelector: the label set that the parent object needs to have

The combination of these constraints can be used to pinpoint containers in the referenced Kubernetes list.

Specify installation source options

To specify the project source directory to load the container, use the mountSources parameter:

Components:-alias: appDeployment type: kubernetes reference: app-deployment.yaml mountSources: true

If enabled, the project source installation is applied to each container for a given component. This parameter also applies to components of type chePlugin.

Component type: dockerimage

Allows component types of container image-based configurations for containers to be defined in the workspace. A devfile can contain only one component of type dockerimage. The dockerimage type of the component introduces custom tools into the workspace. The component is identified by its image.

Components:-alias: maven type: dockerimage image: eclipe/maven-jdk8:latest volumes:-name: mavenrepo containerPath: / root/.m2 env:-name: ENV_VAR value: value endpoints:-name: maven-server port: 3101 attributes: protocol: http secure: 'true' Public: 'true' discoverable:' false' memoryLimit: 1536M command: ['tail'] args: ['-f'' '/ dev/null']

Example of the smallest dockerimage component

ApiVersion: 1.0.0metadata: name: MyDevfilecomponents:type: dockerimageimage: golangmemoryLimit: 512Micommand: ['sleep',' infinity']

It specifies the type of component, dockerimage, and the image attribute names the image to be used for the component using the usual docker naming convention, that is, the above type attribute is equal to docker.io/library/golang:latest.

The dockerimage component has many features that extend images by using other resources and information needed for meaningful integration with Eclipse Che.

Mount the project source

For the dockerimage component to have access to the project source, the mountSources property must be set to true.

ApiVersion: 1.0.0metadata: name: MyDevfilecomponents:type: dockerimageimage: golangmemoryLimit: 512MimountSources: truecommand: ['sleep',' infinity']

The source is installed in the location stored in the CHE_PROJECTS_ROOT environment variable, which is available in the image's running container. This setting defaults to / projects.

Container entry point

The command property of dockerimage and other parameters are used to modify the entry point command of the container created from the image. In Eclipse Che, the container needs to run indefinitely so that you can connect to the container and execute arbitrary commands at any time. Because the availability of the sleep command and its support for the infinity parameter are different, and depending on the base image used in a particular image, Che cannot automatically insert this behavior. However, you can use this feature to start the necessary servers with a modified configuration, for example.

Permanent storage

The Docker Image tool can specify custom volumes to be installed in a specific location in the image. Note that volume names are shared among all components, so this mechanism can also be used to share file systems between components.

ApiVersion: 1.0.0metadata: name: MyDevfilecomponents:type: dockerimageimage: golangmemoryLimit: 512MimountSources: truecommand: ['sleep',' infinity'] volumes:-name: cache containerPath: / .cache environment

Eclipse Che allows you to configure the Docker container by modifying the environment variables available in the image container.

ApiVersion: 1.0.0metadata: name: MyDevfileprojects:name: my-go-projectsource: type: git location: https://github.com/acme/my-go-project.git clonePath: go/src/github.com/acme/my-go-projectcomponents:type: dockerimageimage: golangmemoryLimit: 512MimountSources: truecommand: ['sleep',' infinity'] env:-name: GOPATH value: $(CHE_PROJECTS_ROOT) / go- name: GOCACHE value: / tmp/go-cache

The variable extension works between environment variables, and it uses the Kubernetes convention to reference variables. You can use predefined variables in your own definition. The Che server presets the following environment variables:

CHE_PROJECTS_ROOT: the location of the project directory (note that if the component does not load the source, the project will not be accessible).

CHE_WORKSPACE_LOGS_ROOT__DIR: the location of logs common to all components. If the component chooses to put the logs in this directory, you can access the log files from all other components.

CHE_API_INTERNAL: the URL of the Che server API endpoint used to communicate with the Che server.

CHE_WORKSPACE_ID: the ID of the current workspace.

CHE_WORKSPACE_NAME: the name of the current workspace.

CHE_WORKSPACE_NAMESPACE: the namespace of the current workspace.

CHE_MACHINE_TOKEN: the token used to validate the request against the Che server.

CHE_MACHINE_AUTH_SIGNATUREPUBLICKEY: a public key used to secure communication with the Che server.

CHE_MACHINE_AUTH_SIGNATURE__ALGORITHM: the encryption algorithm used in secure communication with the Che server.

A development file may only need the CHE_PROJECTS_ROOT environment variable to find the cloned project in the container of the component. More advanced devfile can use the CHE_WORKSPACE_LOGS_ROOT__DIR environment variable to read logs (for example, as part of the devfile command). Most of the environment variables used for secure access to the Che server are outside the scope of devfile and exist only in advanced use cases that are typically handled by the Che plug-in.

Endpoints

You can specify the endpoints that the Docker image exposes. If the Che cluster is running using Kubernetes ingress or OpenShift routing, users can access these endpoints and other components in the workspace. If your application or database server is listening on a port and you want to be able to interact with it directly or with other components, you can create endpoints for your application or database.

Endpoints have many properties, as shown in the following example:

ApiVersion: 1.0.0metadata: name: MyDevfileprojects:name: my-go-projectsource: type: git location: https://github.com/acme/my-go-project.git clonePath: go/src/github.com/acme/my-go-projectcomponents:type: dockerimageimage: golangmemoryLimit: 512MimountSources: truecommand: ['sleep' 'infinity'] env:-name: GOPATH value: $(CHE_PROJECTS_ROOT) / go- name: GOCACHE value: / tmp/go-cacheendpoints:name: web port: 8080 attributes: discoverable: false public: true protocol: httptype: dockerimageimage: postgresmemoryLimit: 512Mienv:name: POSTGRES_USERvalue: username: POSTGRES_PASSWORDvalue: passwordname: POSTGRES_DB value: databaseendpoints:name: postgres port: 5432 attributes: discoverable: true public: false

Here, there are two dockerimage, and each dockerimage defines an endpoint. An endpoint is an accessible port that can be accessed within the workspace or publicly (for example, from UI). Each endpoint has a name and port, which is the port on which some servers running in the container are listening. Here are some properties that you can set on the endpoint:

Discoverable: if the endpoint is discoverable, it means that it can be accessed using its name as the hostname within the workspace container (in Kubernetes's view, the service will be created for it using the name provided).

Public: the endpoint can also be accessed outside the workspace (it can be accessed from the Che user interface). Such endpoints are always published on port 80 or 443 (depending on whether tls is enabled in Che).

Protocol: for public endpoints, this protocol prompts UI on how to build a URL for endpoint access. The typical value is http,https,ws,wss.

Secure: a Boolean value (default is false) that specifies whether to place the endpoint after the JWT agent that requires the JWT workspace token to grant access.

Path: the URL of the endpoint

UnsecuredPaths: a comma-separated list of paths in an endpoint that should not be protected even if the secure property is set to true

CookiesAuthEnabled: when set to true (the default is false), the JWT workspace token is automatically obtained and included in the workspace-specific cookie to allow requests to be passed through the JWT agent.

This setting can lead to CSRF attacks when used in conjunction with servers that use POST requests.

Che automatically detects this when you start a new server within a component, and UI automatically exposes this port as a public port. For example, this is useful for debugging Web applications. This operation cannot be performed on a server that starts automatically with a container (for example, a database server). For such components, specify the endpoint explicitly.

Kubernetes and OpenShift resources

Complex deployments can be described using a list of Kubernetes or OpenShift resources that can be referenced in devfile. This will make them part of the workspace.

Because the Che workspace is represented internally as a single deployment, all resources in the Kubernetes or OpenShift list are merged into that single deployment.

Care must be taken when designing such lists, as this can lead to name conflicts and other problems.

Only the following subsets of Kubernetes objects are supported: deployment, pod, service, persistent volume declaration, secret, and configuration mapping. Kubernetes entry will be ignored, but OpenShift routing is supported. Workspaces created from devfile using any other object type will not start.

If you are running Che on a Kubernetes cluster, only Kubernetes lists are supported. However, if you are running Che on an OpenShift cluster, both Kubernetes and OpenShift lists are supported (because OpenShift is a superset of Kubernetes).

ApiVersion: 1.0.0metadata: name: MyDevfileprojects:name: my-go-projectsource: type: git location: https://github.com/acme/my-go-project.git clonePath: go/src/github.com/acme/my-go-projectcomponents:type: kubernetesreference:.. / relative/path/postgres.yaml

The previous component references a file relative to the location of the devfile itself. This means that the devfile can only be loaded by the Che factory, and you can provide it with the location of the devfile, so it can find out the location of the referenced list of Kubernetes resources.

The following is an example of a postgres.yaml file.

ApiVersion: v1kind: Listitems:- apiVersion: v1kind: Deployment metadata: name: postgres labels: app: postgres spec: template: metadata: name: postgres app: name: postgres spec: containers:-image: postgres name: postgres Ports:-name: postgres containerPort: 5432 volumeMounts:-name: pg-storage mountPath: / var/lib/postgresql/data volumes:-name: pg-storage persistentVolumeClaim: claimName: pg-storage- apiVersion: v1 kind: Service metadata: Name: postgres labels: app: postgres name: postgres spec: ports:-port: 5432 targetPort: 5432 selector: app: postgres- apiVersion: V1 kind: PersistentVolumeClaim metadata: name: pg-storage labels: app: postgres spec: accessModes:-ReadWriteOnce Resources: requests: storage: 1Gi

For a basic example of a devfile with an associated Kubernetes or OpenShift list, see https://github.com/redhat-developer/devfile/tree/master/samples/web-nodejs-with-db-sample.

If you use a regular or large resource list that requires only a subset of resources, you can use a selector to select a specific resource from the list (like a normal Kubernetes selector, this selector can be used for tagging resources in the list).

ApiVersion: 1.0.0metadata: name: MyDevfileprojects:name: my-go-projectsource: type: git location: https://github.com/acme/my-go-project.git clonePath: go/src/github.com/acme/my-go-projectcomponents:type: kubernetesreference:.. / relative/path/postgres.yamlselector: app: postgres

In addition, you can modify the entry points (commands and arguments) of containers that exist in the resource list. For more information about advanced use cases, see Resources (TODO: link).

Add commands to devfile

Devfile allows you to specify commands that can be executed in the workspace. Each command can contain a subset of actions related to specific components that will be executed in its container.

Commands:-name: build actions:-type: exec component: mysql command: mvn clean workdir: / projects/spring-petclinic

You can use the command to automate the workspace. You can define commands for building and testing code or cleaning up the database.

Here are two commands:

Che specific command: you have complete control over which component executes the command.

Editor-specific commands: you can use editor-specific command definitions (for example, task.json and launch.json in Theia, equivalent to how these files work in VS Code).

Che special command

Each che-specific command has an action property (a command to execute) and a component property (specifying a container in which the command should be executed). These commands are run using the default shell in the container.

ApiVersion: 1.0.0metadata: name: MyDevfileprojects:name: my-go-projectsource: type: git location: https://github.com/acme/my-go-project.git clonePath: go/src/github.com/acme/my-go-projectcomponents:type: dockerimageimage: golangalias: go-climemoryLimit: 512MimountSources: truecommand: ['sleep' 'infinity'] env:-name: GOPATH value: $(CHE_PROJECTS_ROOT) / go- name: GOCACHE value: / tmp/go-cachecommands:- name: compile and run actions:-type: exec component: go-cli command: "go get-d & & go run main.go" workdir: "${CHE_PROJECTS_ROOT} / src/github.com/acme/my-go-project"

If the component to be used in the command must have an alias. This alias is used to reference components in the command definition. Example: alias: go-cli in component definition and component: go-cli in command definition. This ensures that Eclipse Che can find the correct container to run the command. A command can have only one action.

Editor-specific command

If the editor in the workspace supports it, devfile can specify additional configurations in an editor-specific format. This depends on the integration code provided in the workspace editor itself, so it is not a general mechanism. However, the default Theia editor in Eclipse Che understands the task.json and launch.json files provided in devfile.

ApiVersion: 1.0.0metadata: name: MyDevfileprojects:name: my-go-projectsource: type: git location: https://github.com/acme/my-go-project.git clonePath: go/src/github.com/acme/my-go-projectcommands:-name: tasks actions:-type: vscode-task referenceContent: > {"version": "2.0.0" "tasks": [{"label": "create test file", "type": "shell" "command": "touch ${workspaceFolder} / test.file"}]}

This example shows the association of the task.json file with the devfile. Note that the vscode-task type instructs the Che-Theia editor to interpret this command as a task definition and a referenceContent attribute that contains the contents of the file itself. You can also save the file separately from the devfile and use the reference property to specify a relative or absolute URL.

In addition to the vscode-task command, the Che-Theia editor knows about the vscode-launch type, which you can use to specify the startup configuration.

Devfile attribute

The Devfile property can be used to configure various functions.

Attribute: editorFree

If no editor is specified in devfile, a default value is provided. Use the editorFree attribute when you do not need an editor. The default value is false, which means that devfile needs to configure a default editor.

Example of devfile without an editor

ApiVersion: 1.0.0metadata: name: petclinic-dev-environmentcomponents:-alias: myApp type: kubernetes local: my-app.yamlattributes: editorFree: trueAttribute: persistVol attribute: persistVolumes (temporary mode)

By default, even after the container is restarted, the volumes and PVC specified in devfile are bound to the host folder to persist the data. Sometimes it may be necessary to disable data persistence, such as when the back end of the volume is slower and you need to make the workspace faster. To do this, you should use the persistVolumes devfile attribute. The default value is true, and if false, the emptyDir volume is used for the configured volume and PVC.

Example of devfile with transient mode enabled

ApiVersion: 1.0.0metadata: name: petclinic-dev-environmentprojects:-name: petclinic source: type: git location: 'https://github.com/che-samples/web-java-spring-petclinic.git'attributes: persistVolumes: false at this point, I believe you have a better understanding of "the use of Eclipse Che 7 workspace", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report