Generally, you must create an application before creating an environment. In special cases, you can create an application together with an environment. For more information, see the webxctl apply command for creating an application.

Overview

Before creating an environment, familiarize yourself with the working directory and the Wpfile file.

Working directory: sets the default application and default environment for all operations in the current directory. For example, you can run the wpctl list command to read the default application in the current working directory, and list all the environments of the application. You can also run the wpctl info command to view the information about the default application and default environment in the current working directory.

Wpfile: stores the configuration information for creating or updating an environment. The Wpfile file and the --type flag in the apply command are mutually exclusive. For more information about the configuration items in the Wpfile file, see Configure the deployment environment configuration file Wpfile.

You can run the apply command in one of the following ways:

Run the wpctl apply command

After you run the wpctl apply command, the system reads the settings of the current working directory. If the Wpfile file exists in the current working directory, the system reads the configuration items of the Wpfile file and uses them as the settings of the apply command. The name of the Wpfile file cannot be changed. For more information, see Use flags to control the apply command in this topic.

$ pwd
/Users/***/Documents/webp/webp-cli-demo
$ ls
<Empty directory>
$ wpctl info // Check whether the default environment is specified in the current working directory.
No env in this app:demo-test
$ wpctl env:apply --env demo-test-env --create-on-absent
please input new package source : file:///Users/jungle/go/src/github.com/aliyun/aliyun-cli/hello.war
[No envId to do configSetting diff, you are going to create a env]
...
[OK] Create environment name demo-test-env (2s)
...

Run the wpctl apply your_Wpfile command

You can specify a Wpfile file, the name of which can be changed, such as jenkins or zookeeper. When you run the wpctl apply your_Wpfile command, the system ignores the settings of the working directory and reads the configuration items of the specified Wpfile file. In this case, you can also specify flags to create or update an environment. For more information, see Use flags to control the apply command in this topic. The methods for specifying your Wpfile file are as follows:

  • file://
  • https://
  • http://
  • Local file path, which can be a relative path or absolute path
$ wpctl env:apply your_Wpfile --app your_app --env your_env --create-on-absent
...
[No envId to do configSetting diff, you are going to create a env]
...
[Adding config settings below]
+----+----------------------------------+-------------------------+--------------------------------+
| NO |               PATH               |          NAME           |             VALUE              |
+----+----------------------------------+-------------------------+--------------------------------+
|  1 | platform                         | category                | Tomcat                         |
|  2 | platform                         | stackName               | Aliyun Linux 2.1903 - Java 8 - |
|    |   ...                            |                         | Tomcat 8.5                     |
...
[OK] Create environment name your_env (2s)
...

Use flags to control the apply command

You can use the following three factors to control the action of the apply command:
  • --app and --env: specify an application and an environment, respectively.
  • Default application and default environment in the working directory.
  • --create-on-absent: creates an application or environment if the object specified by the --app or --env flag does not exist.
    Table 1. Control the action on the environment
    No. --env Default environment in the working directory --create-on-absent Action
    1 Used N/A Used Updates the environment specified by the --env flag, or creates an environment if the specified one does not exist.
    2 Used N/A N/A Updates the environment specified by the --env flag, or reports an error if the specified environment does not exist.
    3 Not used Used N/A Updates the default environment.
    4 Not used Not used N/A Reports an error.
    Table 2. Control the action on the application
    No. --app Default application in the working directory --create-on-absent Action
    1 Used N/A Used Performs operations on the application specified by the --app flag, or creates an application if the specified one does not exist.
    2 Used N/A Not used Performs operations on the application specified by the --app flag, or reports an error if the specified application does not exist.
    3 Not used Used N/A Performs operations on the default application.
    4 Not used Not used N/A Reports an error.

Create an environment based on a configuration template

You can create an environment for an application based on a saved configuration template of the application. When running the apply command, use the --template flag to specify the template ID. Then, the system ignores all flags other than --env, --app, and --create-on-absent.

Save the environment configuration

After creating an environment, you can save the configuration in one of the following ways:

Method 1: Save as a Wpfile file on your local computer.

$ wpctl env:dump
Saving Wpfile to /Users/***/Documents/webp/webp-cli-demo/Wpfile

Method 2: Save as a configuration template.

$ wpctl env:save --name demo-template
[OK] Start to create configTemplate name:demo-template (1s)
Template demo-template created, Id is wct-***