Environment Creation

Creating environments via the command line can be useful for various solutions, such as managing complex DevOps scenarios. Let’s explore how this can be accomplished.

1. First, we’ll look at several ways this operation can be performed.

The simplest method to create a new environment with CLI is to manually declare the required parameters through the appropriate command. Just run the createenvironment method with your customized parameters:


~/jelastic/environment/control/createenvironment --env '{"shortdomain" : " {env_name}", "engine" : " {engine_type}"}' --nodes '[{"nodeType" : " {node_type}", "fixedCloudlets" : {cloudlets_amount}, "flexibleCloudlets" : {cloudlets_amount}}]'

In the highlighted example, replace the placeholders with the following data:

In the highlighted example, replace the placeholders with the following data:

{env_name} – a chosen name for the new environment.

{engine_type} – the selected engine to be used in this environment.

{node_type} – the stack type identifier, which corresponds to the list of available options.

{cloudlets_amount} – the total number of fixed and flexible cloudlets to allocate for a particular node.

Tip: You can find more detailed information about available parameters within the corresponding API method description and in the CreateEnvironment API overview.

Create Environment API overview

Take note that in the image provided above, the CLI response indicated a result property equal to 0. This indicates that the operation was successful and without errors. This applies to all commands you run.

Another option supported by the platform CLI is to use a JSON file containing all of your environment’s parameters. Once created, this file can be used multiple times, which is much faster and more convenient than defining everything manually each time.

For example, let’s create a simple JSON file with the following environment topology:


{
"env": {
"shortdomain": "{env_name}",
"engine": "{engine_type}"
},
"nodes": [
{
"nodeType": "{node_type}",
"fixedCloudlets": "{cloudlets_amount}",
"flexibleCloudlets": "{cloudlets_amount}"
}
]
}

Just ensure to modify the highlighted parameters as described in the previous step.

Now, to create an environment, simply use the createenvironment method with a single –myparams parameter, which includes the path to your .json file as its value (or just its name if it’s located within the user’s home folder):


~/jelastic/environment/control/createenvironment --myparams {path_to_file}

Additionally, you have the option to redefine or add certain settings (namely –shortdomain,, and –displayName) to the env section of your configuration file. You can specify these settings inside square brackets within the method parameters. For example, using the optional –shortdomain string (as shown in the image below), you can override the same-named setting from JSON, allowing the environment to be created with the same topology but under a different name.

2. Creating a Docker-based environment is almost similar to the methods described above, but involves a few specific parameters. To deploy a Docker container using the platform CLI, execute the following command:


~/jelastic/environment/control/createenvironment --env '{"shortdomain" : "{env_name}"}' --nodes '[{"nodeType" : "docker", "fixedCloudlets" : {cloudlets_amount}, "flexibleCloudlets" : {cloudlets_amount}, "docker" : {"image" : "{image_name}"}}]'

According to the command above, the `nodeType` parameter needs to be set to `docker`, and the newly added `{image_name}` placeholder should be replaced with the address of the Docker template you’d like to deploy (in the `server.com/images/image_name:tag` format).

As per the command above, the parameter should be configured as `docker`. Additionally, replace the newly added `{image_name}` placeholder with the address of the Docker template you wish to deploy, adhering to the `server.com/images/image_name:tag` format.

Here’s a breakdown:

  • If the template is located within the Registry Hub, you can skip the registry hostname.
  • Optionally, you can add the version tag after the “:” separator at the end of the image address.
  • To authenticate at a private registry, declare the additional `registry` parameter with the URL to it, and provide the appropriate credentials (i.e., password and username) as values.
Tip: You can find more detailed information about available parameters within the corresponding API method description and at the CreateEnvironment API overview.

Create Docker Environment

In a short while, your Docker-based environment will be created and ready to use.