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
- 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.
- 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.
- 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
- Go to the Buy CodeArts page.
- Select Free, read and agree to the statement, and click Subscribe.
- 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.
- Click Access Service on the CodeArts console.
- 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.
- In the navigation pane, choose Code > Repo.
- Click New Repository, select Template, and click Next.
- On the page displayed, select Java Web Demo and click Next.
- 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.
- Click a repository name to go to the repository.
- Click Create above the file list. Select Create File from the drop-down list.
Figure 1 Creating a file
- 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"]
- 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.
- In the navigation pane, choose CICD > Build.
- Click Create Task and configure task information.
- 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.
- Select Template: Select Blank Template and click OK.
- Basic Information: Configure the following information and click Next.
- Configure build actions.
- Click Add Build Actions, find Build with Maven in the list, and click Add.
- Click Add Action. In the action list, find Build Image and Push to SWR. Click Add.
- 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
- 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.
- 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.
- Log in to the CCE console and click the cluster purchased in Preparations to go to the details page.
- Choose Workloads in the navigation pane, and click Create Workload.
- 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.
- 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.
- 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
- 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.
- Return to the CodeArts page and choose CICD > Deploy in the navigation pane.
- Click Create Application.
- Enter web-demo-k8s for Name and click Next.
- Select the Blank Template and click OK.
- 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.
- 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.
- Choose CICD > Pipeline from the navigation pane.
- Click Create Pipeline and configure the pipeline.
- 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.
- Template: Select Blank Template and click OK.
- Basic Information: Configure the following information and click Next.
- Configure a workflow.
- Click next to Stage_1. In the Edit Stage dialog box, enter the name Build and click Confirm.
Figure 5 Editing the stage name
- Click Job.
Click Add next to Build in the New Job window.
Figure 6 Adding a job
- 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.
- Click Stage and change the stage name to Deploy.
- Click Job and add the Deploy extension.
- Select web-demo-k8s and select the job configured in 3.c.
- Click next to Stage_1. In the Edit Stage dialog box, enter the name Build and click Confirm.
- Click the Execution Plan tab, select Code commit, select master from the branch filter drop-down list.
Figure 7 Configuring the execution plan
- Click Save.
- 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
- 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.
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 |
|
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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot