Using CodeArts to Quickly Set Up a Project (ECS)
This section describes how to use the built-in code repository of CodeArts to develop, build, and deploy projects for continuous delivery.
The following describes deployment using ECS. For details about deployment using Cloud Container Engine (CCE), see Using CodeArts to Quickly Set Up a Project (CCE).
Preparations
- You have purchased CodeArts. For details, see Purchasing CodeArts.
- You have purchased an ECS. The following table lists the mandatory configurations. You can select the configurations that are not listed in the table based on the site requirements. After the purchase is complete, add inbound rules for ports 22 and 8080 by referring to Configuring Security Group Rules.
Creating a Project
A project is the basis for using services on CodeArts. Subsequent operations can be performed only after a project is created.
- Log in to the CodeArts console.
- Click and select a region.
- Click Access Service.
- Click Create Project.
- Select Scrum, enter the project name Demo, and click OK.
Creating a Code Repository
You can use a code repository to manage project code versions. This section describes how to use the built-in template Java Web Demo to create a code repository.
- On the navigation bar, choose .
- Click next to New Repository and select Template Repository.
Figure 1 Creating a code repository
- On the page displayed, select Java Web Demo and click Next.
- Enter the code repository name Web-Demo and click OK.
Checking Code
You can use CodeArts Check to perform static code check and control code quality.
- On the navigation bar, choose Web-Demo-codecheck is displayed on the page.
. The automatically created task
This section uses built-in tasks associated with code repository templates.
In an actual development project, click Create Task. For details, see Creating a Code Check Task.
- Locate the row that contains the task and click Execute immediately.
If the code check task has been run, click the task name to access overview page and click Start Check to run the task again.
- When is displayed, the task is successfully executed. Click the task name, go to the Overview tab page, and view the check result.
If the task fails, check and fix errors based on the message displayed on the page.
Building and Archiving Software Packages
You can use CodeArts Build to compile the source code of the software into a target file, packs the configuration file and resource file, and archives them to a release repo.
- In the navigation bar, choose Web-Demo-cloudbuild is displayed.
. The automatically created build task
This section uses built-in tasks associated with code repository templates.
In an actual development project, you need to click Create Task and create a task based on the service scenario. For details, see Creating a Build Task.
- Click in the row where the task is located to start the task. If a dialog box is displayed, confirm the parameter settings and click Confirm.
- When is displayed, the task is successfully executed. Click the task name. On the Build History page that is displayed, find the Build ID of the latest build in the list and record the ID.
If the build fails, rectify the fault based on the failed action information and error information in logs.
Figure 2 Build ID
- Choose Release Repos tab.
in the navigation bar and click the
In the repository named after the project, go to the folder named after the build task and the folder named after the build number in sequence to find the generated software package demoapp.jar.
Figure 3 Viewing the software package
Deploying the Build Package
You can use CodeArts Deploy to deploy software packages in the release repo to a VM and run it.
- Configuring the Target Host
- In the navigation bar, choose .
- Click Create Host Cluster, enter the name hosts, set the OS to Linux, and click Save.
- Click Add Target Host. In the dialog box that is displayed, configure the following information, agree to statements, and click OK.
Table 1 Add a target host Item
Suggestion
Host Name
Enter a custom host name. For easy identification, set this parameter to the name of the ECS purchased on Preparations.
IP
Enter the IP address of the ECS purchased in Preparations.
Username
Enter root.
Password
Enter the password set when you purchase the ECS in Preparations.
SSH Port
Enter 22.
- A host record is displayed on the page. If Succeed is displayed in the Verification Result column, the host is added successfully.
If the host fails to be added, check the host configuration based on the failure details.
- Choose Web-Demo-deploy is displayed on the page.
from the navigation bar. The automatically created application
This section uses built-in applications associated with code repository templates.
In an actual development project, click Create Application and create an application based on the service scenario. For details, see Creating an Application.
- Click and choose Edit from the drop-down list.
- Click the Environment Management tab and configure the host environment.
- Click Create Environment, enter the environment name host-group, select the resource type Hosts and operating system Linux, and click Save.
- A new environment record is added to the list. Click the environment name. In the window that is displayed, click the Resource tab.
- Click Import Host. In the dialog box that is displayed, select the host cluster created in 1 from the drop-down list, select the host from the list, and click Import.
- A message is displayed, indicating that the import is successful. Close the window.
- Click the Parameters tab and set task parameters by referring to the following table.
Parameter Name
Value
host_group
Select the environment name host-group added in 4.
package_url
This parameter is not required. Click in the corresponding row to delete it.
service_port
Enter 8080.
package_name
Enter demoapp.
- Click the Deployment Actions tab and configure information.
- Stop Spring Boot: If you perform this step for the first time, this step will fail because no service is running on the target host. Therefore, do not select Enable this action.
- Install the JDK: Change the JDK version to openjdk-1.8.0.
- Select the deployment source. Set the parameters based on the following table.
Table 2 Deployment source configuration Item
Value
Source
Click Build task.
Build Task
Select Web-Demo-cloudbuild.
Download Path
Enter /usr/local/${package_name}/.
- Health Test Through URLs: This step is optional. Determine whether to enable it as required. (In this document, do not select Enable this action.)
- Click Save & Deploy. If a dialog box is displayed, confirm the parameter settings and click OK.
Wait until is displayed on the page. If the deployment fails, rectify the fault based on the failed action information and error information in logs.
- View the deployment result.
Open a new browser page and enter the access address http://IP:8080/test. IP is the IP address of the ECS purchased in Preparations.
If the following information is displayed, the deployment is successful.
Figure 4 Deployment result
Configuring a Pipeline
You can use a CodeArts pipeline to connect code check, build, and deployment tasks. When code changes, the pipeline is automatically triggered for continuous delivery.
- Choose Pipelines tab, the automatically created pipeline Web-Demo-pipeline is displayed.
from the navigation bar. On the
This document uses the built-in pipeline associated with the code repository template.
In an actual development project, click Create Pipeline and create a pipeline based on the service scenario. For details, see Creating a Pipeline.
- Click and choose Edit from the drop-down list.
- On the Task Orchestration tab page, configure the pipeline.
- APITest is not involved in this document. Therefore, remove the API test task from the pipeline.
Click corresponding to apitest. In the dialog box that is displayed, click OK.
Figure 5 Deleting a job
- Click the codecheck task.
- Click the deploy job, associated the build task cloudbuild, and set other parameters based on the parameter settings in Deploying the Build Package.
- APITest is not involved in this document. Therefore, remove the API test task from the pipeline.
- Click the Execution Plan tab, select Code Commit, select master from the branch filter drop-down list.
Figure 6 Configuring the execution plan
- Click Save to exit the editing mode.
- Go to Deploy, edit the deployment actions, and select Enable this action in Stop Spring Boot.
- Go to the code repository and search for and open the TestController.java file.
Click , change hello world to hello world again, submit the information, and click OK.
Figure 7 Modifying code
- Return to the Pipeline page. You can see that the pipeline is running.
When is displayed, access http://IP:8080/test again. The following figure shows the access result.
If the task fails to be executed, check the failure cause. You can open the step details page to view the task logs and rectify the fault based on the logs.
Figure 8 Pipeline execution result
Releasing Resources
To avoid unnecessary fees, you can release resources after completing this example.
Released resources cannot be restored. Exercise caution when performing this operation.
- Delete a project.
- Choose .
- Click Delete Project, in the displayed dialog box, enter the project name and click Delete.
- Delete the ECS.
- Log in to the ECS console, locate the ECS to be deleted in the list, click More, and choose Delete from the drop-down list.
- Select all options in the dialog box that is displayed and click Yes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.