Help Center/ CodeArts/ Getting Started/ Deploying a Code Development Pipeline on CCE
Updated on 2024-11-13 GMT+08:00

Deploying a Code Development Pipeline on CCE

This section describes how to use the built-in code repository of CodeArts to develop, build, and deploy projects for continuous delivery.

This chapter uses Cloud Container Engine (CCE) for container-based deployment.

To use traditional software package deployment, see Deploying a Code Development Pipeline on ECS.

Preparations

  1. You have signed up for Huawei Cloud. If you do not have a HUAWEI ID, create one by referring to Registering a HUAWEI ID and Enabling Huawei Cloud Services.
  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

    Parameter

    Suggestion

    Basic Settings

    Type

    Select CCE Standard Cluster.

    Billing Mode

    Select Pay-per-use.

    Cluster Name

    Enter a name.

    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.

    Default 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

    Parameter

    Suggestion

    Node Configuration

    Billing Mode

    Select Pay-per-use.

    Node Type

    Select Elastic Cloud Server (VM).

    Specifications

    Select 2 vCPUs and 4 GiB 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 named web-demo in SWR. For details, see Creating an Organization.

    If the system displays a message indicating that the organization already exists, use another name.

Enabling CodeArts Free Edition

  1. Go to the Buy CodeArts page.
  2. Select Free, read and agree to the statement, and click Subscribe.
  3. Check the subscription record on the CodeArts page.

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. Click Access Service on the CodeArts console.
  2. 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.

  1. In the navigation pane, choose Code > Repo.
  2. Click New Repository, select Template, and click Next.
  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 1 Creating a file

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

    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 pane, 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

      Parameter

      Suggestion

      Name

      Enter Web-Demo-docker.

      Code Source

      Select Repo.

      Repository

      Select Web-Demo.

      Branch

      Select master.

    2. Select Template: Select Blank Template and click OK.

  3. Configure build actions.

    1. Click Add Build Actions, find Build with Maven in the list, and click Add.
    2. Click Add Action. In the action 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 this table.)
      Table 4 Configuring image information

      Parameter

      Suggestion

      Organization

      Enter the name (web-demo) of the organization created in Preparations.

      Image Tag

      v1.0.0

  4. After the configuration is complete, click Save 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.

    Figure 2 Viewing images

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. Choose Workloads in the navigation pane, and click Create Workload.
  3. Complete the configurations by referring to the following table and click Create Workload.

    Table 5 Creating workload

    Category

    Parameter

    Suggestion

    Basic Info

    Workload Type

    Select Deployment.

    Workload Name

    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.

  4. When the creation is complete, click View Workload Details to go back to the details page. There is a record on the Pods tab.

    If the pod status is Running, click the Access Mode tab, click Create Service, 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

    Parameter

    Suggestion

    Service Name

    Enter web-demo.

    Service Type

    Select LoadBalancer.

    Service Affinity

    Select Cluster-level.

    Load Balancer

    • Choose Shared > Auto create.
    • Instance Name: Enter web-demo-test.
    • EIP: Select Auto create.

    Port

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

  5. Check the record displayed in the list.

    If is displayed in the record, hover over the load balancer name in the Access Type column, and copy the public IP address in the pop-up window.
    Figure 3 Copying the access address

  6. Open a new browser page and enter http://IP:8080/test in the address box. Replace IP with the public network address copied in 5.

    If the following information is displayed, the workload is running properly.

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

    1. Click Create Application.
    2. Enter web-demo-k8s for Name and click Next.
    3. Select the Blank Template and click OK.

  2. Search for and add action Kubernetes Quick Deployment (CCE Cluster). Configure this action by referring to the following table.

    Table 7 Configuring deployment actions

    Parameter

    Suggestion

    Region

    Select the region where the cluster located.

    Cluster Name

    Select the cluster purchased in Preparations.

    Namespace

    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 pane.
  2. Click Create Pipeline and configure the pipeline.

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

      Parameter

      Suggestion

      Name

      Enter pipeline-web-demo.

      Code 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 5 Editing the stage name
    2. Click Job.

      Click Add next to Build in the New Job window.

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

      Parameter

      Suggestion

      Name

      Retain the default value.

      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 configured in 3.c.

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

    Figure 7 Configuring the execution plan

  5. Click Save.
  6. 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 8 Modifying code

  7. 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 9 Pipeline execution result

Follow-up Operations

To avoid incurring unnecessary fees, you can release any unused resources once you have completed this example.

The following resources can be released.

Table 10 Releasing resources

Resource

Releasing Method

CodeArts project

Choose Settings > General > Basic Information, click Delete Project, and follow the prompts to delete the project.

SWR organization and image

  1. Log in to the SWR console.
  2. On the My Images page, select the image created in this example, click Delete, and follow the prompts to delete the image.
  3. On the Organizations page, click the name of the organization to be deleted. Click Delete and follow the prompts to delete the organization.

CCE cluster

Log in to the CCE console. Locate the target cluster in the list, click , select Delete Cluster, and follow the prompts to delete it.

Released resources cannot be restored. Exercise caution when performing this operation.