×
Community Blog Deploying Applications to EDAS with Cloud Toolkit Maven Plug-in

Deploying Applications to EDAS with Cloud Toolkit Maven Plug-in

This article shows you how to use the Cloud Toolkit Maven plug-in to deploy applications to Alibaba Cloud EDAS.

For EDAS developers, if you are using a WAR or JAR package to deploy an application, you can use the Cloud Toolkit Maven plug-in to deploy applications to Alibaba Cloud EDAS.

Step 1: Add the Maven Dependency

In the pom.xml file of the project, add the following<build> dependency.

<build>
 <plugins>
     <plugin>
         <groupId>com.alibaba.cloud</groupId>
         <artifactId>toolkit-maven-plugin</artifactId>
         <version>1.0.0</version>
     </plugin>
 </plugins>
</build>

Query the latest version from the official central repository of Maven.

Step 2: Configure the Yaml File

Create an. edas_config.yaml file under the root directory of the project. If the packaged project is a Maven submodule, create the file in the submodule directory. The file contains the following content:

env:
  region_id: cn-beijing
app:
  app_id: eb20dc8a-0000-567-1234-5f6a54550453

Among the preceding configuration items, region_id indicates the region ID of the application instance, while app_id indicates the application ID. The values of the preceding configuration items are examples. Replace them with your actual application values. For information about other configuration items, see "More configuration items."

Step 3: Associate with an EDAS Account

Create an account file and configure Access Key ID and Access Key Secret in yaml format. To view Access Key ID and Access Key Secret, log on to the Alibaba Cloud user information management system. The following provides a configuration example:

access_key_id: 123456
access_key_secret: 7891011

Step 4: Complete the Deployment

Go to the root directory (or the submodule directory if multiple Maven modules are used) and run this packaging command:

mvn package toolkit:deploy --proudct=edas -Daccess_key_file= {Account file path}

1

After this command is run, the following message is displayed, indicating that you have successfully deployed the application in EDAS:

More Configuration Items

Configuration items for deploying applications are classified as follows:

  • Basic environment (env)
  • Application configuration (app)
  • Storage configuration (oss)

The currently supported configuration items are listed in the following table.

2

Configuration Example 1: Specify the Group and the Deployment Package Version

For example, an application whose ID is eb20dc8a-e6ee-4f6d-a36f-5f6a54550453 is deployed in Beijing. The group ID is 06923bb9-8c5f-4508-94d8-517b692f30b9, and the deployment package version is 1.2. In this case, the configuration is as follows:

env:
  region_id: cn-beijing
app:
  app_id: eb20dc8a-e6ee-4f6d-a36f-5f6a54550453
  package_version: 1.2
  group_id: 06923bb9-8c5f-4508-94d8-517b692f30b9

Configuration Example 2: Specify an OSS Storage Space

For example, we want to deploy the application whose ID is eb20dc8a-e6ee-4f6d-a36f-5f6a54550453 and upload the deployment package to our own bucket named release-pkg in Beijing. The file object name is my.war, the OSS account ID is ABC, and the OSS account key is 1234567890. In this case, the configuration is as follows:

env:
  region_id: cn-beijing
app:
  app_id: eb20dc8a-e6ee-4f6d-a36f-5f6a54550453
oss:
  region_id: cn-beijing
  bucket: release-pkg
  key: my.war  
  access_key_id: ABC
  access_key_secret: 1234567890

Specify a Configuration File

  • If no configuration file is specified, this plug-in uses the .edas_config.yaml file in the root directory of the packaged project as the configuration file. If the packaged project is a submodule of the Maven project, the configuration file is under the root directory of the submodule by default, but not under the root directory of the entire Maven project.
  • You can also specify a configuration file by setting the -Dedas_config=xxx parameter.
  • If the default configuration file exists while another configuration file is specified, the plug-in uses the latter.

Description of Account Configurations and Priorities

When deploying an application with this plug-in, you must provide an Alibaba Cloud Access Key for application deployment. Currently, the plug-in supports multiple configuration methods. If duplicate configuration methods are present, the configuration method with a higher priority overrides that with a lower priority. Configuration methods in descending order of priority:

  • AK/SK parameter specified in the command line: You can specify access_key_id and access_key_secret in either of the following ways:
  • If you package the project by running Maven commands, specify both parameters with -Daccess_key_id=xx -Daccess_key_secret=xx.
  • When configuring this plug-in in the pom file, configure the AK and SK parameters as follows:
<plugin>
  <groupId>com.aliyun</groupId>
  <artifactId>edas-maven-plugin</artifactId>
  <version>2.30.0</version>
  <configuration>
      <accessKeyId>abc</accessKeyId>
      <accessKeySecret>1234567890</accessKeySecret>
  </configuration>
</plugin>
  • Specify the account file in the command line (recommended): When you package the project by running Maven commands, specify the account file in yaml format with -Daccess_key_file={account file path. Example:
access_key_id: abc
access_key_secret: 1234567890
  • Use the default Alibaba Cloud account file: If you choose not to specify an account in either of the preceding ways, the plug-in uses the configured Alibaba Cloud account to deploy the application.
  • aliyuncli: If you have used the latest aliyuncli tool and configured your Alibaba Cloud account, Alibaba Cloud generates the .aliyuncli sub-directory under the current Home directory and creates the credentials file in the .aliyuncli sub-directory to store your account information. Here, we use the Mac system as an example and assume the system user is "jack", so the following information is stored in the /Users/jack/.aliyuncli/credentials file:
[default]
aliyun_access_key_secret = 1234567890
aliyun_access_key_id = abc

The plug-in uses this account file as the account for deploying the application.

  • aliyun: If you have used a legacy Aliyun tool and configured the Alibaba Cloud account, the Aliyun tool generates the .aliyun sub-directory under the current Home directory and creates the config.json file in the .aliyun sub-directory. Here, we use the Mac system as an example and assume the system user is "jack", so the account information is stored in the /Users/jack/.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: Finally, the plug-in attempts to retrieve the values of access_key_id and access_key_secret from system environment variables. Namely, the plug-in retrieves these values from System.getenv("access_key_id") and System.getenv("access_key_secret") in the Java code.
0 0 0
Share on

Nick(倪超)

9 posts | 1 followers

You may also like

Comments

Nick(倪超)

9 posts | 1 followers

Related Products