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

Using CodeArts to Quickly Set Up a Project (CCE)

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 CCE. For details about deployment using ECS, see Using CodeArts to Quickly Set Up a Project (ECS).

Preparations

  1. You have purchased CodeArts. For details, see Purchasing CodeArts.
  2. You have purchased a CCE cluster. The cluster is configured according to Table 1 and Table 2. Default values can be retained for configurations not listed in the tables.
    Table 1 Cluster configurations

    Category

    Item

    Suggestion

    Basic Settings

    Billing Mode

    Select Pay-per-use.

    Cluster Version

    You are advised to select the latest version.

    Network Settings

    Network Model

    Select VPC network.

    VPC

    Select a VPC. If no proper VPC is available in the list, click Create VPC to create one.

    Master Node Subnet

    Select a subnet. If no proper subnet is available in the list, click Create Subnet to create one.

    Container CIDR Block

    Select Auto select.

    Table 2 Node configurations

    Category

    Item

    Suggestion

    Compute Settings

    Billing Mode

    Select Pay-per-use.

    Node Type

    Select Elastic Cloud Server (VM).

    Specifications

    Select 2 vCPUs and 8 GB memory or higher.

    Container Engine

    Select Docker.

    OS

    Select Public image > CentOS 7.6.

    Login Mode

    Select Password.

    Password

    Enter a password.

    Network Settings

    Node IP

    Select Random.

    EIP

    Select Do not use.

  3. You have created an organization in SoftWare Repository for Container (SWR). In this example, organization name web-demo is used as an example.

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.

Preparing a Dockerfile

A Dockerfile is a text file that contains the instructions and descriptions required for building an image. For details about Dockerfile, see the Docker official website.

  1. Click a repository name to go to the repository.
  2. Click Create above the file list. Select Create File from the drop-down list.

    Figure 2 Creating a file

  3. Enter the file name Dockerfile and then enter the following content:

    FROM openjdk:8-alpine
    ADD target /demo
    COPY ./target/demoapp.jar /demo
    CMD ["java","-jar","/demo/demoapp.jar"]

  4. Enter a commit message and click OK.

Building and Pushing an Image

Use a build task to compile the software source code into an image and push and archive the image to SWR.

  1. In the navigation bar, choose CICD > Build.
  2. Click Create Task and configure task information.

    1. Basic information: Configure the following information and click Next.
      Table 3 Basic information

      Item

      Suggestion

      Task Name

      Enter a custom name (Web-Demo-docker as an example).

      Code Source

      Select Repo.

      Source Code Repository

      Select Web-Demo.

      Branch

      Select master.

    2. Build Template: Select the Blank Template and click Next.

  3. Configure build actions.

    1. Click Add Build Actions, find Build with Maven in the list, and click Add.
    2. Click Add step. In the step list, find Build Image and Push to SWR. Click Add.
    3. Configure Build Image and Push to SWR by referring to the following table. (Retain the default values for the fields not listed in the table.)
      Table 4 Configuring image information

      Item

      Suggestion

      Organization

      Enter the organization name web-demo created in Preparations.

      Image Tag

      v1.0.0

  4. After the configuration is complete, click Create and Run.

    When is displayed, the task is successfully executed. If the build fails, rectify the fault based on the failed action information and error information in logs.

  5. Log in to the SWR console. In the navigation pane, choose My Images.

    There is a record whose Name is demo and Organization is web-demo.

    Click the image name to view details. The image version is v1.0.0.

Creating a Workload

Create a Deployment on CCE to deploy and run the demo image.

  1. Log in to the CCE console and click the cluster purchased in Preparations to go to the details page.
  2. In the navigation bar, choose Workloads. Click Create Workload, complete the configuration by referring to the following table, and click Create Workload.

    Table 5 Creating workload

    Category

    Item

    Suggestion

    Basic Info

    Workload Type

    Select Deployment.

    Workload Name

    User-defined. In this example, enter web-demo.

    Pods

    Enter 1.

    Container Settings

    Image Name

    Click Select Image. In the dialog box that is displayed, select demo and click OK.

    Pull Policy

    Select Always.

    Image Tag

    Select v1.0.0.

    Advanced Settings

    Upgrade Mode

    Set Upgrade Mode to Replace upgrade.

  3. A message is displayed, indicating that the creation is successful. Click the View Workload Details to go back to the details page. There is one record in the Pods.

    If the pod status is Running, click the Access Mode tab, click Create, configure the service by referring to the following table, and click OK.

    If the instance status is abnormal, rectify the fault by referring to Workload Abnormalities.

    Table 6 Configuring access mode

    Item

    Suggestion

    Service Name

    User-defined. In this example, enter web-demo.

    Service Type

    Select LoadBalancer.

    Service Affinity

    Select Cluster-level.

    Load Balancer

    Choose Shared > Auto Create. Then enter a load balancer name (use web-demo-test in this example) and check the box next to "I have read Notes on Using Load Balancers".

    NOTE:

    If your account already has a load balancer, choose Shared > Use existing and select an existing load balancer.

    Port

    • Set Protocol to TCP.
    • Set Container Port to 8080.
    • Set Service Port to 8080.

  4. Move the cursor to the load balancer name in a displayed list under Service Type when is displayed next to a service name. Copy the Public IP displayed in the dialog box.
  5. Open a new browser page and enter http://IP:8080/test in the address box. Replace IP with the public network address copied in 4.

    If the following information is displayed, the image has been deployed and started running.

    Figure 3 Deployment result

Deploying an image

You can create applications on Deploy to automatically deploy images.

  1. Return to the CodeArts page and choose CICD > Deploy in the navigation bar.

    1. Click Create Application, enter the application name (web-demo-k8s as an example), and click Next.
    2. Select the Blank Template and click OK.

  2. Search for and add Step Kubernetes Quick Deployment (CCE Cluster) to the step list. Configure the steps by referring to the following table.

    Table 7 Configuring deployment actions

    Item

    Suggestion

    Region

    Select the region where the cluster located.

    Cluster Name

    Select the cluster purchased in Preparations.

    Namespace

    In this document, select default.

    Workload

    Select web-demo.

    Container

    Select a container name configured when Create Workload is selected.

  3. Click Save & Deploy.

    If is displayed, the test is successful. If the deployment fails, rectify the fault based on the failed action information and error information in logs.

Configuring a Pipeline to Automatically Update Image Deployment

Configure a pipeline to integrate the code repository, build, and deployment. When a code commit action occurs in the code repository, the pipeline is automatically executed for continuous delivery.

  1. Choose CICD > Pipeline from the navigation bar.
  2. Click Create Pipeline and configure the pipeline.

    1. Basic information: Configure the following information and click Next.
      Table 8 Pipeline basic information

      Item

      Suggestion

      Project

      Enter pipeline-web-demo.

      Pipeline Source

      Select Repo.

      Repository

      Select Web-Demo.

      Default Branch

      Select master.

    2. Template: Select Blank Template and click OK.

  3. Configure a workflow.

    1. Click next to Stage_1. In the Edit Stage dialog box, enter the name Build and click Confirm.
      Figure 4 Editing the stage name
    2. Click NewJob.

      Click Add next to Build in the NewJob window.

      Figure 5 Adding a job
    3. Configure task information by referring to the following table and click OK.
      Table 9 Editing a build task

      Item

      Suggestion

      Name

      Enter a custom name (use the default value in this document).

      Select Task

      Select Web-Demo-docker.

      Repository

      Select Web-Demo.

    4. Click Stage and change the stage name to Deploy.
    5. Click Job and add the Deploy extension.
    6. Select web-demo-k8s and select the job name configured in 3.c.

  4. Click the Execution Plan tab, select Code commit, select master from the branch filter drop-down list, and click Save.

    Figure 6 Configuring the execution plan

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

  6. 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 organization and the image.

    1. Log in to the SWR console.
    2. On the My Images page, select the image created in this example, and click Delete. In the displayed dialog box, click Yes.
    3. On the Organizations page, click the name of the organization to be deleted.

      Click Delete. In the dialog box that is displayed, click Yes.

  3. Delete the cluster.

    1. Log in to the CCE console. In the list, locate the cluster to be deleted and click .
    2. Select all options in the dialog box that is displayed and click Yes.