Help Center/ CodeArts/ Getting Started/ Using CodeArts to Quickly Set Up a Project (ECS)
Updated on 2023-11-28 GMT+08:00

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

  1. You have purchased CodeArts. For details, see Purchasing CodeArts.
  2. 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.

  1. Log in to the CodeArts console.
  2. Click and select a region.
  3. Click Access Service.
  4. Click Create Project.
  5. 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.

  1. On the navigation bar, choose Code > Repo.
  2. Click next to New Repository and select Template Repository.

    Figure 1 Creating a code repository

  3. On the page displayed, select Java Web Demo and click Next.
  4. 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.

  1. On the navigation bar, choose Code > Check. The automatically created task Web-Demo-codecheck is displayed on the page.

    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.

  2. 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.

  3. 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.

  1. In the navigation bar, choose CICD > Build. The automatically created build task Web-Demo-cloudbuild is displayed.

    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.

  2. 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.
  3. 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

  4. Choose Artifact in the navigation bar and click the Release Repos tab.

    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.

  1. Configuring the Target Host

    1. In the navigation bar, choose Settings > General > Basic Resources.
    2. Click Create Host Cluster, enter the name hosts, set the OS to Linux, and click Save.
    3. 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.

    4. 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.

  2. Choose CICD > Deploy from the navigation bar. The automatically created application Web-Demo-deploy is displayed on the page.

    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.

  3. Click and choose Edit from the drop-down list.
  4. Click the Environment Management tab and configure the host environment.

    1. Click Create Environment, enter the environment name host-group, select the resource type Hosts and operating system Linux, and click Save.
    2. A new environment record is added to the list. Click the environment name. In the window that is displayed, click the Resource tab.
    3. 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.
    4. A message is displayed, indicating that the import is successful. Close the window.

  5. 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.

  6. 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.)

  7. 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.

  8. 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.

  1. Choose CICD > Pipeline from the navigation bar. On the Pipelines tab, the automatically created pipeline Web-Demo-pipeline is displayed.

    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.

  2. Click and choose Edit from the drop-down list.
  3. On the Task Orchestration tab page, configure the pipeline.

    1. 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
    2. Click the codecheck task.
    3. Click the deploy job, associated the build task cloudbuild, and set other parameters based on the parameter settings in Deploying the Build Package.

  4. Click the Execution Plan tab, select Code Commit, select master from the branch filter drop-down list.

    Figure 6 Configuring the execution plan

  5. Click Save to exit the editing mode.
  6. Go to Deploy, edit the deployment actions, and select Enable this action in Stop Spring Boot.
  7. 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

  8. 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.

  1. Delete a project.

    1. Choose Settings > General > Basic Information.
    2. Click Delete Project, in the displayed dialog box, enter the project name and click Delete.

  2. Delete the ECS.

    1. 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.
    2. Select all options in the dialog box that is displayed and click Yes.