Deploy applications to EDAS using toolkit-maven-plugin

更新时间:
复制 MD 格式

Cloud Toolkit lets you deploy applications to EDAS using Maven. This method is faster than the traditional process of packaging an application and deploying it from the console because you can deploy applications directly from the command line. This topic describes how to use the toolkit-maven-plugin to deploy an application to an ECS cluster in EDAS.

Prerequisites

Automate application deployment

  1. Add the following plugin dependency to the pom.xml file of your project.

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

    You can obtain the latest version of this plugin from the official Maven Central Repository.

  2. In the project directory, create a YAML file named .edas_config.yaml.

    Note
    • If the project that you want to deploy is a Maven submodule, create this file in the directory of the submodule.

    • The following configuration parameters are examples. You must replace them with your actual application parameters. For more information about configuration parameters, such as batch deployment, see Configuration items.

    • For more information about how to deploy multi-module projects, see Deploy multi-module projects.

    env:
         region_id: cn-beijing  # The region ID of the application instance
    app:
         app_id: eb20****-e6ee-4f6d-a36f-5f6a5455****  # The ID of the application that you want to deploy                      

    If you do not know the values for these parameters, follow these steps to retrieve them:

    1. Log on to the EDAS console. In the upper-left corner of the page, select the region that you want.

    2. In the navigation pane on the left, choose Application Management > Application List. On the Application List page, click the name of the application that you want to deploy.

    3. On the Basic Information page, click Deploy Application in the upper-right corner.

    4. On the Select Deployment Mode page, find the Regular Release (Single/Multi-batch) Start Deployment card and click Start Deployment in the upper-right corner of the card.

    5. Click Generate Maven Plugin Configuration to expand the section and view the parameter information.maven deploy

  3. In any directory, create a YAML account file and add your AccessKey ID and AccessKey secret to the file.

    access_key_id:<yourAccessKeyId>
    access_key_secret:<yourAccessKeySecret>                      
    Note
    • The AccessKey ID and AccessKey secret in this configuration are used only to generate request signatures. They are not used for other purposes, such as network transmission.

    • To view your AccessKey ID and AccessKey secret, log on to the Alibaba Cloud User Information Management page. We recommend that you use a Resource Access Management (RAM) user that has Application Management permissions to control application permissions and improve application security.

  4. Navigate to your project directory and run the following packaging command.

    Note

    If you are using a multi-module Maven project, navigate to the directory of the submodule.

    mvn clean package toolkit:deploy -Daccess_key_file={path_to_your_account_file}    
    • toolkit:deploy: Deploys the application using the toolkit-maven-plugin after the application is packaged. The application is deployed only if you add this parameter.

    • access_key_file: The path to the Alibaba Cloud account file. For more information about how to specify a key pair, see Account configuration and priority.

Verify the result

After you run the command, logs are displayed in the terminal. If the following log output is displayed, the deployment is successful.

Deploy multi-module projects

Multi-module projects use a common project structure. This Maven plugin supports the following two methods for deploying multi-module projects.

  • Run the packaging and deployment commands in the parent project: When you run the toolkit:deploy command in the parent project, add the -Ddeploy_artifacts parameter to specify the artifact IDs of the submodules that you want to deploy. To deploy multiple submodules, separate the artifact IDs with a comma.

    For example, a CarShop project contains the following submodules:

    carshop
       itemcenter-api
       itemcenter
       detail

    To deploy the itemcenter and detail submodules at the same time, run the following command in the carshop directory:

    mvn clean package toolkit:deploy -Ddeploy_artifacts=itemcenter,detail

    By default, this plugin deploys the corresponding applications based on the .edas_config.yaml files in the itemcenter and detail modules. You can also add the -Dedas_config parameter to specify a configuration file. For more information, see Specify a configuration file.

    Important

    This method requires toolkit-maven-plugin version 1.0.3 or later.

  • Run the packaging and deployment commands in a submodule:

    1. In the parent project, run the install command to install the submodule dependencies to the local Maven repository.

    2. Navigate to the directory of the submodule that you want to deploy and run the toolkit:deploy command.

    Note

    This method is supported by all versions of toolkit-maven-plugin.

More information

For more information about configuration items, how to specify a configuration file, and account configuration and priority, see Maven deployment instructions.