This procedure demonstrates how to define the Che 7 workspace devfile by Kubernetes application.
-
A running instance of Eclipse Che. To install an instance of Eclipse Che, see Che 'quick-starts'.
-
chectlmanagement tool is installed. See Installing thechectlmanagement tool
The devfile format is used to define a Che workspace, and its format is described in the Making a workspace portable using a devfile section. The following is an example of the simplest devfile:
apiVersion: 1.0.0
metadata:
name: minimal-workspace
Only the name (minimal-workspace) is specified. After the Che server processes this devfile, the devfile is converted to a minimal Che workspace that only has the default editor (Che-Theia) and the default editor plug-ins (example: the terminal).
Use the Kubernetes type of components in the devfile to add Kubernetes applications to a workspace.
For example, the user can embed the NodeJS-Mongo application in the minimal-workspace defined in this paragraph by adding a components section.
apiVersion: 1.0.0
metadata:
name: minimal-workspace
components:
- type: kubernetes
reference: https://raw.githubusercontent.com/.../mongo-db.yaml
- alias: nodejs-app
type: kubernetes
reference: https://raw.githubusercontent.com/.../nodejs-app.yaml
entrypoints:
- command: ['sleep']
args: ['infinity']
Note that the sleep infinity command is added as the entrypoint of the Node.js application. This prevents the application from starting at the workspace start phase. It allows the user to start it when needed for testing or debugging purposes.
To make it easier for a developer to test the application, add the commands in the devfile:
apiVersion: 1.0.0
metadata:
name: minimal-workspace
components:
- type: kubernetes
reference: https://raw.githubusercontent.com/.../mongo-db.yaml
- alias: nodejs-app
type: kubernetes
reference: https://raw.githubusercontent.com/.../nodejs-app.yaml
entrypoints:
- command: ['sleep']
args: ['infinity']
commands:
- name: run
actions:
- type: exec
component: nodejs-app
command: cd ${CHE_PROJECTS_ROOT}/nodejs-mongo-app/EmployeeDB/ && npm install && sed -i -- ''s/localhost/mongo/g'' app.js && node app.js
Use this devfile to create and start a workspace with the chectl command:
$ chectl worspace:start --devfile <devfile-path>
The run command added to the devfile is available as a task in Che-Theia from the command palette. When executed, the command starts the NodeJS application.