CLI syntax and commands
The CLI is a Docker-formatted container image that comes with a collection of commands to configure, interact with, and start Che. The CLI also contains commands, such as sync and ssh, for end users to interact with workspaces.
Command:
$ docker run -it --rm <DOCKER_PARAMETERS> eclipse/che-cli:<version> [COMMAND]
Following is the mandatory docker command parameter for the CLI image:
-v <LOCAL_PATH>:/data
The user, instance, and log data are saved here.
The following tables lists the optional docker command parameters that you can use with the CLI image.
| Optional Docker parameter | Description |
|---|---|
|
IP address or hostname where Che serves its users |
|
Port on which Che binds itself |
|
Prefix name for the Che container |
|
The instance, user, log data is saved here |
|
Backup files are saved here |
|
Che git repository - uses local binaries and manifests |
|
Che assembly - uses local binaries |
|
Where |
|
Where unison profile for optimizing the |
|
Source repository to convert into workspace with the |
The following table lists the commands that you can use with the Docker CLI image.
| Command | Description |
|---|---|
|
Start action on Che instance |
|
Backs up Che configuration and data to the |
|
Generates a Che configuration from variables; run on any |
|
Stops services, and deletes che instance data |
|
Use |
|
Pulls Docker images for the current Che version |
|
Displays information about Che and the CLI |
|
Displays system state and debugging information |
|
Initializes a directory with a Che install |
|
Saves Che container images into TAR files for offline installation |
|
Restarts the Che services |
|
Restores Che configuration and data from the |
|
Removes the container images for |
|
SSH to a workspace if SSH agent is enabled |
|
Starts the Che services |
|
Stops the Che services |
|
Synchronizes workspace with local directory mounted to |
|
Starts test on the Che instance |
|
Upgrades Che from one version to another with migrations and backups |
|
Installed version and upgrade paths |
The following table lists the global command options that you can use with the Docker CLI image.
| Command option | Description |
|---|---|
|
Skips networking, version, nightly, and preflight checks |
|
Runs CLI in offline mode, loading images from the disk |
|
Enable debugging of the Che server |
|
Activates trace output for debugging the CLI |
The CLI has the following three primary phases:
-
The initialization phase is executed by the
initcommand. It installs version-specific files into the directory mounted to/data/. This includes the universal configuration file namedche.env, a version identifier, and a location where configuration files are saved. The configuration is executed by theconfigcommand. Theconfigcommand takes theche.envconfiguration file and the OS of your host system as input and generates an OS-specific set of configuration files in thedata/instancedirectory." -
The configuration phase runs an initialization if a directory is not found. Every execution of the
configcommand overwrites the files in the/data/instance/directory with the latest configuration. This ensures that if an administrator modifies any configuration file, the instance’s configuration files are updated consistently. The CLI generates a large number of configuration files specific to running Che. The configuration files are sourced from the Puppet templates that are stored in the GitHub repository under/dockerfiles/init/. -
The start phase is executed by the
startcommand. It uses a configuration-generateddocker-compose-container.ymlfile to launch Eclipse Che. The start phase always executes aconfigcommand, so any files that were edited in the/data/instance/directory are overwritten with the generated configuration from the CLI.
The CLI hides most error conditions from the standard output. Internal stack traces and error output are redirected to the cli.log file, which is saved in the host directory where :/data is mounted.
You can override any value in the che.env file for a single execution by passing the -e NAME=VALUE argument on the command line. The CLI detects the values on the command line and ignores those imported from the che.env file.
Following are some selected commands and their uses.
action-
The
actioncommand executes some actions on the Eclipse Che instance or on a workspace running inside Che. To list all workspaces on Che, use theaction list-workspacescommand. To execute a command on a workspace, use theaction execute-command <workspace-name> <action>command; here, the<action>parameter is interpreted by the shell. backup-
The
backupcommand creates TAR files from theinstance/directory and places them in the/backup/directory. These files are restoration-ready. config-
The
configcommand generates a Che instance configuration that is placed in theinstance/directory. It uses Puppet to generate Docker Compose configuration files to run Che and its associated server. Che server configuration is generated as ache.propertiesfile that is mounted in the Che server when it boots. This command is executed on everystartorrestart.If you are using a
eclipse/che:<version>image and it does not match the version in theinstance/che.verfile, the configuration aborts to prevent you from running a configuration for a different version.It respects the
--no-force,--pull,--force, and--offlinecommand options. destroy-
The
destroycommand deletes theche.envfile and the/docs/andinstance/directories, including user workspaces, projects, data, and user database. To skip the confirmation warning message, pass the--quietargument in the command. To delete thecli.logfile, pass the--cliargument. By default, thecli-logfile is retained for traceability. dir-
The
dircommand boots a new Eclipse Che instance with a workspace for the:/chedirdirectory defined as volume mount in the parameter.For example, if you give
$HOME/my-projectas a parameter, a new Che instance is created using$HOME/my-projectas a project in the IDE. Inside the IDE, the/projects/directory contains amy-project/directory with your host directory. Any changes inside the IDE are reflected in your host directory. Updating a file on your local computer updates the content of the file inside the IDE.initInitializes the directory specified and adds a default
Chefileif there is none.upBoots Eclipse Che with workspace on directory.
downStops Eclipse Che and any workspaces.
sshConnects to the running workspace by using the
sshcommand.statusDisplays if an instance of Eclipse Che is running or not for the specified directory.
download-
The
downloadcommand is used to download container images stored in your image repository. This command downloads images that are used by the CLI as utilities, for Che to do initialization and configuration, and for the runtime images that Che needs when it starts. This command respects the--offline,--pull,--force, and--no-force(default) command options. It is invoked by theche init,che config, orche startcommands.The
downloadcommand is invoked by theche initcommand before initialization to download images for the version specified byeclipse/che:<version>.To override the Docker-formatted container images used by the CLI, set the following environment variables:
-
IMAGE_INITto override the defaulteclipse/che-init:<version>Docker-formatted container image. -
IMAGE_CHEto override the defaulteclipse/che-server:<version>Docker-formatted container image.For example, if you want to use a given tag in your own Docker account for both images, add the following parameters to the
dockercommand:-e IMAGE_INIT=myDockerAccount/che-init:givenTag -e IMAGE_CHE=myDockerAccount/che-server:givenTag
-
info-
The
infocommand displays system state and debugging information. The--networkcommand option runs a test to take theCHE_HOSTvariable value to test network connectivity by simulating the browser > Che and Che > workspace connectivity. The--bundlecommand option generates a support diagnostic bundle in a TAR file, which includes the output of certain commands and the execution logs. init-
The
initcommand initializes an empty directory with a Che configuration and instance directory. The user data and runtime configuration are stored in the empty directory. You must provide a<path>:/datavolume mount for Che to create theinstance/andbackup/sub-directories of<path>. After initialization, ache.envfile is placed in the root directory of the path that you mounted to/data/.- Overriding the location of the
instance/directory -
Mount an additional local directory to the
/data/instance/directory. - Overriding the location of where backups are stored
-
Mount an additional local directory to the
/data/backup/directory.
The following variables can be set in your local environment shell before running. These variables are respected during initialization:
Variable Description CHE_HOSTThe IP address or DNS name of the Che service. We use
eclipse/che-ipto attempt discovery if not set.CHE_PORTThe port the Che server will run on and expose in its container for your clients to connect to.
Che depends on container images. The images are used to:
-
Provide cross-platform utilities within the CLI. For example, to perform a
curloperation, you use a small container image to perform this function. This is done as a precautionary measure because many operating systems do not havecurlinstalled. -
Find the master version and upgrade manifest, which is saved within the CLI container image in the
/version/sub-directory. -
Perform initialization and configuration of Che as done with the
eclipse/che-initcommand. This image contains templates to be installed on your computer used by the CLI to configure Che for your specific OS.You can control how Che downloads these images with command-line options. All image downloads are performed using the
docker pullcommand.Mode Description --no-forceThe default behavior. Downloads an image if not found locally. A local check of the image inspects if an image of a matching name is present in your local registry and then skips pulling the image if it is found. This mode does not check DockerHub for a newer version of the same image.
--pullAlways perform a
docker pullcommand when an image is requested. If there is a newer version of the same tagged image at DockerHub, it pulls it, or uses the one in the local cache. This slows the execution but keeps your images up-to-date.--forcePerforms a forced removal of the local image using the
docker rmicommand and then pulls it again from DockerHub. Use this to clean your local cache and to ensure that all images are new.--offlineLoads tar-archived container images from the
backup/directory during the pre-boot mode of the CLI. Used if you are performing an installation or start while disconnected from the Internet.You can reinstall Che on a directory that is already initialized and preserve your
che.envvalues by passing the--reinitflag.
- Overriding the location of the
offline-
The
offlinecommand saves all the container images that Che requires in/backup/*.tarfiles. Each image is saved as its own file. If thebackup/directory is available on a machine that is disconnected from the Internet and you start Che with the--offlinecommand option, the CLI pre-boot sequence loads all the container images in thebackup/directory.The
--listoption lists all the core images and optional stack images that can be downloaded. The core system images and the CLI are always saved if an existing TAR file is not found. The--image:<image-name>command option downloads a single-stack image and can be used multiple times on the command line. You can use the--all-stacksoption or the--no-stacksoption to download all or none of the optional stack images. restart-
The
restartcommand performs astopaction followed by astartaction, respecting the--pull,--force,--offline,--skip:config,--skip:preflight, and--skip:postflightcommand options. restore-
The
restorecommand restores the/instancedirectory to its previous state. The start-stop-restart cycle ensures that the proper Docker images are available or downloaded if not found.Use this command with caution because it deletes the existing
instance/directory. As a precautionary measure, set these values to different directories when performing a restore action. rmi-
The
rmicommand deletes the container images that Che has downloaded for this version from the local registry. ssh-
The
sshcommand connects the current terminal where the command is started to the terminal of a machine of the workspace. If no machine is specified in the command, it connects to the default development machine. The syntax is:ssh <workspace-name> [machine-name]
The SSH connection only works with a configured workspace SSH key. A default SSH key is automatically generated when a workspace is created.
sync-
The
synccommand synchronizes contents of a workspace with a local directory mounted to:/sync. The syntax is:-v <path-on-your-machine>:/sync eclipse/che sync <workspace-name>
To display a log of the underlying unison tool, use the
--unison-verboseflag. start-
The
startcommand starts Che and its services using thedocker-composecommand. In the absence of valid configuration, it performs aninitcommand. Everystartandrestartcommand runs theconfigcommand to generate a new configuration set using the latest configuration files placed into theinstance/directory. The starting sequence also tests if any ports required by Che are currently being used by other services and to verify access to key APIs.- Skipping the generation of configuration
-
Use the
--skip:configoption. - Skipping checks
-
Use the
--skip:preflightand--skip:postflightoptions. - Automatically printing server logs during the boot
-
Use the
--followoption. To interrupt the output, press Ctrl+c, or use the shell commands to interrupt the output.
stop-
The default stop is a graceful stop where each workspace is stopped and confirmed shut down before stopping system services. If workspaces are configured to snap on stop, all snaps are completed before the system service shutdown begins. You can ignore workspace stop behavior and shut down only system services using the
–forceflag. test-
The
testcommand performs tests on your local instance of Che. For example, to check the ability to create a workspace, start the workspace by using a custom workspace runtime, and then use it. For a list of all tests available, use thetestcommand. upgrade-
The
upgradecommand manages the sequence of upgrading Che from one version to another. For a list of available versions that you can upgrade to, run theche versioncommand.The Che upgrade is done by using a
eclipse/che:<version>image that is newer than the version you currently have installed. For example, if you have<version>installed and you want to upgrade to<version+1>:-
To get the new version of Che:
$ docker pull eclipse/che:<version+1>
You now have two
eclipse/cheimages (one for each version). -
Use the new image to upgrade the old installation:
$ docker run <volume-mounts> eclipse/che:<version+1> upgrade
The
upgradecommand has numerous checks to prevent you from upgrading Che if the new image and the old version are not compatible. For the upgrade procedure to proceed, the CLI image must be newer than the value ofinstance/che.ver.Following is a list of actions that the upgrade process performs in the background:
-
Performs a version compatibility check.
-
Downloads new Docker images that are needed to run the new version of Che.
-
Stops Che if it is currently running and triggers a maintenance window.
-
Backs up your installation.
-
Initializes the new version.
-
Starts Che.
-
-
For a list of available versions that you can upgrade to, run the che version command.
The --skip-backup option allows you to skip the backup operation during the update. Skipping the backup operation speeds up the upgrade because the backup operation can be time consuming if the /instance directory contains many user worksapces and projects making it a large directory.
version-
The
versioncommand provides information on the current version and the available versions that are hosted in Che repositories. Theche upgradecommand enforces upgrade sequences and prevents you from upgrading one version to another version where data migrations cannot be guaranteed.
Developing and testing the CLI
You can customize the CLI using a variety of techniques. This section discusses how engineers develop and test the CLI on their local machines.
Structure of the Che CLI
The Che CLI is constructed of multiple Docker images within the Che source repository.
/dockerfiles/base (1) /dockerfiles/cli (2) /dockerfiles/init (3)
| 1 | Common functions and commands |
| 2 | CLI entrypoint, overrides, and version information |
| 3 | Manifests used to configure Che on a host installation |
The Che CLI is written in Bash. The cli image depends upon both the base image and the init image. In the source repository, the build.sh script builds these Docker images either one at a time or collectively as a group.
Rebuilding images every time you want to test a small change to Bash script can be tedious. To avoid rebuilding the images every time and for every change to a Bash script, mount the contents during the image execution. You cannot mount the entrypoint.sh file, but you can mount the following:
-
To mount the contents of the
baseimage:-v <path-to-che-repo>/dockerfiles/scripts/base/scripts:/base/scripts
-
To mount the contents of the
initimage:-v <path-to-che-repo>:/repo
If you run the Che CLI in this configuration, any changes made to the Bash files or templates in those repositories are used without having to first rebuild the CLI image.
Customizing the Che CLI
The Che CLI was designed to be overridden to allow different CLIs to be created from the same base structure. The CLI is created with the following minimal assets:
/dockerfiles/cli/build.sh (1) /dockerfiles/cli/Dockerfile (2) /dockerfiles/cli/scripts (3) /dockerfiles/cli/scripts/entrypoint.sh (4) /dockerfiles/cli/scripts/cli.sh (5) /dockerfiles/cli/version (6)
| 1 | Local file to build the image |
| 2 | Image definition, must FROM eclipse/che-base:nightly |
| 3 | Contains additional commands in the form of cmd_<name>.sh |
| 4 | The entrypoint of the CLI container, with the usage() method |
| 5 | Defines CLI-specific product names and variables |
| 6 | Contains version-specific data that the CLI requires |
You can add additional commands to the Che CLI beyond the base set of commands that are provided by adding a file of the name cmd_<name>.sh into the scripts/ directory.
The version/ directory contains information about the latest version and a sub-directory for each version that is available for installation. Each version sub-directory has version-specific data that the CLI depends on to create a manifest of container images that must be downloaded to support the product that is going to be run. When a release of the Che CLI is generated, the CI systems automatically update the version/ directory with the version-specific information contained in the release.
Puppet templates
The Che CLI uses Puppet to generate OS-specific configuration files based on environment variables set by the user either with the -e <VALUE> option on the command line, or by modifying their che.env file.
A Puppet configuration utility parses files contained in the /dockerfiles/init/modules/ and /dockerfiles/init/manifests/ directories to take the templates contained in the /init/ directory, matches them with user-specific variables, and generates an instance-specific configuration in the instance/ directory. Puppet has logic constructs that allow us to generate different kinds of constructs with logic based on the values provided by the end users.
This Puppet-based approach allows to simplify the outputs for end users and limit the locations where end users need to configure various parts of the system. An example of this is that we generate two docker-compose.yml files from a single Puppet template. The docker-compose.yml and docker-compose-container.yml files are located in the user’s instance/ directory.
docker-compose.yml-
A configuration file that allows a user to run Docker Compose for Che on their host. They can run the
docker-compose upcommand in that directory. docker-compose-container.yml-
A configuration file for running Docker Compose from within a container, which is what the CLI does.
The syntax of Docker Compose changes in each of these scenarios as the files being referenced from within the compose syntax are different. There is a single template for Docker Compose in the init image. It is then applied in two configurations using Puppet.
CLI tests
There are existing bats tests for the Che CLI, which run automatically with each execution of the build.sh script located in the dockerfiles/cli/ directory. To skip them, pass the --skip-tests argument when running the build script. To only run the tests, execute the test.sh script located in the same directory. The tests utilize the eclipse/che-bats docker image, which is built from the Dockerfile placed in the dockerfiles/bats/ directory.