You can use the toolkit-maven-plugin plug-in that is provided by Maven to automatically deploy applications to SAE. This topic describes the typical scenarios in which you can use Maven to automatically deploy applications, the procedure, and the required parameters. This topic also describes how to deploy a multi-module project.
Prerequisites
Maven is installed and configured. For more information, see Downloading Apache Maven.
An application is created. You can use one of the following methods to deploy the application:
Background information
The toolkit-maven-plugin plug-in is an open source tool that can be used to build a complete lifecycle framework and deploy an environment for a project. The toolkit-maven-plugin plug-in provides the following features:
The plug-in is extensible and allows you to use Java or scripting languages to modify code.
In most cases, the toolkit-maven-plugin plug-in can build a specific number of projects based on the outputs of the predefined types, without the need to run scripts. For example, you can build a distribution job based on the metadata of your project, a JAR package, or a WAR package.
You can integrate toolkit-maven-plugin with your source code management system, such as Subversion or Git, without the need for additional configurations. You can also use toolkit-maven-plugin to manage the release of your project based on a tag.
Typical scenarios
Build a WAR or FatJar package in your on-premises environment to deploy an application
For example, you use an application that is deployed by using a WAR package in the China (Beijing) region, and you want to build a WAR package in your on-premises environment to redeploy the application. The following section describes the package configurations and deployment configurations:
Package file
apiVersion: V1 kind: AppPackage spec: packageType: War
Deployment file
apiVersion: V1 kind: AppDeployment spec: type: serverless target: appId: # The ID of the application that you want to deploy. If you configure this parameter, you do not need to configure the namespaceId or appName parameter. namespaceId: # The ID of the namespace to which the application belongs. If the application ID is not obtained, you can use the namespace to which the application belongs and the application name to deploy the application. appName: # The name of the application. If the application ID is not obtained, you can use the namespace to which the application belongs and the application name to deploy the application.
Use the address of an existing image to deploy an application
For example, you use an application that is deployed by using an image in the China (Beijing) region, and you want to use an existing image to redeploy the application. The following section describes the package configurations and deployment configurations:
Package file
apiVersion: V1 kind: AppPackage spec: packageType: Image imageUrl: registry.cn-beijing.aliyuncs.com/test/gateway:latest # The address of the image. acrInstanceId: # The ID of the Container Registry Enterprise Edition instance. If you want to use a Container Registry Enterprise Edition instance, configure this parameter.
Deployment file
apiVersion: V1 kind: AppDeployment spec: type: serverless target: appId: # The ID of the application that you want to deploy. If you configure this parameter, you do not need to configure the namespaceId or appName parameter. namespaceId: # The ID of the namespace to which the application belongs. If you do not know the application ID, you can use the namespace to which the application belongs and the application name to deploy the application. appName: # The name of the application. If you do not know the application ID, you can use the namespace to which the application belongs and the application name to deploy the application.
Build an image in your on-premises environment and upload the image to your repository to deploy an application
For example, you use an application that is deployed by using an image in the China (Beijing) region, and you want to compile and build an image in your on-premises environment and then upload the image to an Alibaba Cloud image repository to redeploy the application. The following section describes the package configurations and deployment configurations:
Package file
apiVersion: V1 kind: AppPackage spec: packageType: Image build: docker: dockerfile: Dockerfile # The Dockerfile. imageRepoAddress: # The address of the image repository. imageTag: # The image tag. imageRepoUser: # The username that is used to access the image repository. imageRepoPassword: # The password that is used to access the image repository. acrInstanceId: # The ID of the Container Registry Enterprise Edition instance. If you want to use a Container Registry Enterprise Edition instance, configure this parameter.
Deployment file
apiVersion: V1 kind: AppDeployment spec: type: serverless target: appId: # The ID of the application that you want to deploy. If you configure this parameter, you do not need to configure the namespaceId or appName parameter. namespaceId: # The ID of the namespace to which the application belongs. If you do not know the application ID, you can use the namespace to which the application belongs and the application name to deploy the application. appName: # The name of the application. If you do not know the application ID, you can use the namespace to which the application belongs and the application name to deploy the application.
Deploy an application
This section describes how to deploy a project in an on-premises environment to SAE by adding a plug-in dependency and specifying deployment information.
Add a plug-in dependency to the pom.xml file of the packaged project.
NoteWe recommend that you use the toolkit-maven-plugin plug-in of the latest version 1.1.8.
<build> <plugins> <plugin> <groupId>com.alibaba.cloud</groupId> <artifactId>toolkit-maven-plugin</artifactId> <version>1.1.8</version> </plugin> </plugins> </build>
Specify the plug-in information.
The plug-in information includes the account information, package information, and deployment information. For more information, see More parameters.
Specify the account information.
In the root directory of your packaged project, create an account configuration file that is in the
YAML
format. Set the name of the file to toolkit_profile.yaml and add the following information to the file:regionId: # The region where the application resides. accessKeyId: # The AccessKey ID that is used to access Alibaba Cloud resources. To reduce security risks, we recommend that you use the AccessKey ID of a RAM user. accessKeySecret: # The AccessKey secret that is used to access Alibaba Cloud resources. To reduce security risks, we recommend that you use the AccessKey secret of a RAM user.
Specify the package information.
In the root directory of your packaged project, create a package configuration file that is in the
YAML
format. If the packaged project is created for a Maven submodule, create the file in the directory of the submodule. Set the name of the file totoolkit_package.yaml
and add the following information to the file:apiVersion: V1 kind: AppPackage spec: packageType: # The type of the deployment package. Valid values:War, FatJar, Image, and url. The packageUrl parameter takes effect only if you set this parameter to url. packageUrl: # The URL of the package. This parameter can be configured only if you use a WAR or FatJar package to deploy your application. If you do not configure this parameter, the current package that is built by using Maven is used. imageUrl: # This parameter can be configured only if you set the packageType parameter to Image. You can also build a Docker image in your on-premises environment to deploy your application. acrInstanceId: # The ID of the Container Registry Enterprise Edition instance. If you want to use a Container Registry Enterprise Edition instance, configure this parameter.
Specify the deployment information.
In the root directory of your packaged project, create a deployment file that is in the
YAML
format. Set the name of the file totoolkit_deploy.yaml
and add the following information to the file:apiVersion: V1 kind: AppDeployment spec: type: serverless target: appId: # The ID of the application that you want to deploy. If you configure this parameter, you do not need to configure the namespaceId or appName parameter. namespaceId: # The ID of the namespace to which the application belongs. If you do not know the application ID, you can use the namespace to which the application belongs and the application name to deploy the application. appName: # The name of the application. If you do not know the application ID, you can use the namespace to which the application belongs and the application name to deploy the application.
Go to the directory where the pom.xml file resides and run the following command to build a deployment project.
ImportantIf you want to deploy a submodule, go to the directory where the pom.xml file resides in the submodule to deploy a project.
mvn clean package toolkit:deploy -Dtoolkit_profile=toolkit_profile.yaml -Dtoolkit_package=toolkit_package.yaml -Dtoolkit_deploy=toolkit_deploy.yaml
The following table describes the parameters in the preceding command.
Parameter
Description
toolkit:deploy
Specifies the system to deploy the application after the packaging operation is complete.
-Dtoolkit_profile
Specifies the account configuration file. If the account configuration file is in the same directory as pom.xml and the file name is
.toolkit_profile.yaml
, this parameter is not required. In this case, the account configuration file is automatically obtained by the plug-in.ImportantThe name of the
.toolkit_profile.yaml
file that is automatically obtained by the plug-in starts with a period (.).-Dtoolkit_package
Specifies the package file. If the package file is in the same directory as pom.xml and the file name is
.toolkit_package.yaml
, this parameter is not required. In this case, the plug-in automatically obtains the package file.ImportantThe name of the
.toolkit_package.yaml
file that is automatically obtained by the plug-in starts with a period (.).-Dtoolkit_deploy
Specifies the deployment file. If the deployment file is in the same directory as pom.xml and the file name is
.toolkit_deploy.yaml
, this parameter is not required. In this case, the plug-in automatically obtains the package file.ImportantThe name of the
.toolkit_deploy.yaml
file that is automatically obtained by the plug-in starts with a period (.).-Ddeploy_version
Specifies the version that you want to deploy. The specified version is assigned a higher priority than the Version that is specified in the
toolkit_deploy.yaml
file.NoteThis parameter is available only for toolkit-maven-plugin plug-ins of version 1.1.2 and later.
After you run the packaging command, the following information is displayed. If BUILD SUCCESS appears, the deployment is successful.
Deploy a multi-module project
In most cases, a project consists of multiple modules. You can use the toolkit-maven-plugin plug-in to deploy your multi-module project by using one of the following methods:
Run the packaging command and deployment command in your parent project
This method is available for toolkit-maven-plugin of version 1.0.3 and later.
When you run the toolkit:deploy
command in your parent project, add the -Ddeploy_artifacts
parameter to specify the artifact ID of the submodule that you want to deploy. If you want to deploy multiple submodules, separate them with commas (,).
The following section provides an example of the submodules of the CarShop project:
carshop
itemcenter-api
itemcenter
detail
To deploy the itemcenter and detail submodules, run the following command in the carshop directory:
mvn clean package toolkit:deploy -Ddeploy_artifacts=itemcenter,detail
By default, the plug-in separately deploys the corresponding applications by using the .edas_config.yaml
file of the itemcenter and detail submodules. You can also add the -Dedas_config
parameter to specify the configuration file.
Run the packaging command and deployment command in your submodule
This method is available for all versions of toolkit-maven-plugin.
Run the install
command in your parent project to install the dependencies of the submodule in your local Maven repository. Then, go to the directory of the submodule that you want to deploy and run the toolkit:deploy
command.
More parameters
References
The following table describes the operations that you can perform on an application after you deploy the application on SAE.
Operation | References |
Lifecycle management operations, such as updating, starting, stopping, and deleting an application, and scaling in or scaling out the instances for an application | |
Performance optimization operations, such as configuring auto scaling policies for an application, binding Server Load Balancer (SLB) instances to an application, and starting or stopping applications in batches | |
Application status-based operations, such as managing logs, configuring monitoring settings, viewing application events, and viewing change records |