Maven deployment guide

更新时间:
复制 MD 格式

To deploy applications to EDAS using Maven, you need to create and customize configuration and account files. This topic describes the configuration items, how to specify configuration files, the priority of account configurations, and provides usage examples.

Configuration items

The configuration items for deploying applications are divided into three main categories:

  • Basic environment (ENV)
  • Application configuration (APP)
  • Storage configuration (OSS)

The supported configuration items are listed in the following table:

TypeKeyRequiredDescription
ENVregion_idYesThe ID of the region where the application is located.
endpointNoUsed to set the POP gateway endpoint for Apsara Stack.
APPapp_idYesThe application ID.
package_versionNoThe version of the deployment package. The default value is the version from the pom file plus the build time on the current machine. For example: "1.0 (2018-09-27 19:00:00)".
descNoThe deployment description.
group_idNoThe ID of the deployment group. The default is all groups.
batchNoThe number of deployment batches. The default is 1 and the maximum is 5.
batch_wait_timeNoThe waiting time between deployment batches, in minutes. By default, there is no waiting time.
stage_timeoutNoThe timeout for displaying the status of each stage in the change flow, in minutes. The default is 5 minutes. If `batch_wait_time` is also set, its value is automatically added to this timeout during calculation. At runtime, the plugin exits if a stage's waiting time exceeds this threshold.
OSSregion_idNoThe ID of the region where the destination bucket is located. By default, the region ID of the application is used.
bucketNoThe name of the destination bucket. By default, the free OSS bucket provided by EDAS is used. If you specify an OSS configuration, you must specify the bucket parameter. Otherwise, the free OSS bucket automatically allocated by EDAS is used.
keyNoThe custom path in OSS for uploading the application package. By default, the free OSS bucket provided by EDAS is used. If you use a specific OSS bucket, use this parameter to specify the package storage path. You can also use the following variables to parameterize the path configuration: `{region_id}`, `{app_id}`, and `{version}`. For example: `pkgs/petstore/{version}/store.war`. The default path is `{region_id}/{app_id}/{version}`.
access_key_idNoThe custom account ID for uploading the application package to OSS.
access_key_secretNoThe custom account key for uploading the application package to OSS.

Example 1

If User A has an application with the ID eb20dc8a-xxx in the China (Beijing) region and wants to deploy version 1.2 of the application to the group with the ID 06923bb9-xxx, the configuration file is as follows:

env:
  region_id: cn-beijing
app:
  app_id: eb20dc8a-xxx
  package_version: 1.2
  group_id: 06923bb9-xxx
            

Example 2

User B wants to deploy an application with the ID eb20dc8a-xxx and upload the deployment package as the my.war file to a bucket named release-pkg in the China (Beijing) region. The AccessKey ID for OSS is ABC, and the AccessKey secret is 123456****. The configuration file is as follows:

env:
  region_id: cn-beijing
app:
  app_id: eb20dc8a-xxx
oss:
  region_id: cn-beijing
  bucket: release-pkg
  key: my.war
  access_key_id: ABC
  access_key_secret: 123456****
            

Specify a configuration file

There are two ways to specify a configuration file:

  • Create a configuration file in any directory and use the -Dedas_config={configuration_file_path} parameter to specify its path.

  • If you do not specify a configuration file using a parameter, Cloud Toolkit uses the .edas_config.yaml file in the root directory of the packaged project by default. If the packaged project is a submodule of a Maven project, Cloud Toolkit uses the .edas_config.yaml file in the root directory of the submodule by default.

Important If a default configuration file exists and you also specify a file using the parameter, the file specified by the parameter takes precedence.

Account configuration and priority

Deploying applications using Cloud Toolkit requires Alibaba Cloud resources. Before you deploy an application, you must configure your Alibaba Cloud account information to ensure that you have the required permissions to use and manage resources and applications. Cloud Toolkit supports multiple configuration methods. The following methods are listed in descending order of priority:

Note If you use multiple configuration methods, the method with the higher priority overwrites the one with the lower priority.
  • Specify the AccessKey ID and AccessKey secret parameters on the command line. There are two ways to do this.

    • When you run a Maven packaging command, specify the parameters using -Daccess_key_id=xx -Daccess_key_secret=xx.

    • When you configure Cloud Toolkit in the pom.xml file, you can insert the AccessKey ID and AccessKey secret parameters. The following example shows the configuration:

      <plugin>
      <groupId>com.aliyun</groupId>
      <artifactId>edas-maven-plugin</artifactId>
      <version>2.30.0</version>
      <configuration>
      <accessKeyId>abc</accessKeyId>
      <accessKeySecret>123456****</accessKeySecret>
      </configuration>
      </plugin>
                                  
  • Specify an account file from the command line (recommended).

    When you run a Maven packaging command, specify the path of the account file in YAML format using -Daccess_key_file={account_file_path}. The following code provides a sample account file:

    access_key_id: abc
    access_key_secret: 123456****    
  • Use the default Alibaba Cloud account file.

    If you do not specify an account using the methods described above, Cloud Toolkit uses the Alibaba Cloud account that you previously configured for application deployment.

    • .aliyunclicredentials.aliyuncli/Users/username/.aliyuncli/credentials
          [default]
          aliyun_access_key_secret = 123456****
          aliyun_access_key_id = abc
    • .aliyunconfig.json.aliyun/Users/username/.aliyun/config.json
      {
      "current": "",
      "profiles": [{
            "name": "default",
            "mode": "AK",
            "access_key_id": "",
            "access_key_secret": "",
            "sts_token": "",
            "ram_role_name": "",
            "ram_role_arn": "",
            "ram_session_name": "",
            "private_key": "",
            "key_pair_name": "",
            "expired_seconds": 0,
            "verified": "",
            "region_id": "",
            "output_format": "json",
            "language": "en",
            "site": "",
            "retry_timeout": 0,
            "retry_count": 0
      }, {
            "name": "",
            "mode": "AK",
            "access_key_id": "abc",
            "access_key_secret": "xxx",
            "sts_token": "",
            "ram_role_name": "",
            "ram_role_arn": "",
            "ram_session_name": "",
            "private_key": "",
            "key_pair_name": "",
            "expired_seconds": 0,
            "verified": "",
            "region_id": "cn-hangzhou",
            "output_format": "json",
            "language": "en",
            "site": "",
            "retry_timeout": 0,
            "retry_count": 0
      }],
      "meta_path": ""
      }
                                  
  • System environment variables: If you do not use any of the preceding methods to configure the account, Cloud Toolkit attempts to retrieve the values of access_key_id and access_key_secret from system environment variables by calling System.getenv("access_key_id") and System.getenv("access_key_secret").