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
- You have purchased CodeArts. For details, see Purchasing CodeArts.
- 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
.Login Mode
Select Password.
Password
Enter a password.
Network Settings
Node IP
Select Random.
EIP
Select Do not use.
- 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.
- 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.
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 2 Creating a file
- 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"]
- 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 bar, choose .
- Click Create Task and configure task information.
- 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.
- Build Template: Select the Blank Template and click Next.
- 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 step. In the step 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 the table.)
Table 4 Configuring image information Item
Suggestion
Organization
Enter the organization name web-demo created in Preparations.
Image Tag
v1.0.0
- 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.
- Log in to the SWR console. In the navigation pane, choose
.
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.
- Log in to the CCE console and click the cluster purchased in Preparations to go to the details page.
- In the navigation bar, choose Create Workload, complete the configuration by referring to the following table, and click Create Workload.
. Click
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.
- 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 web-demo-test in this example) and check the box next to "I have read Notes on Using Load Balancers".
. Then enter a load balancer name (useNOTE:If your account already has a load balancer, choose
and select an existing load balancer.Port
- Set Protocol to TCP.
- Set Container Port to 8080.
- Set Service Port to 8080.
- 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.
- 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.
- Return to the CodeArts page and choose
in the navigation bar.
- Click Create Application, enter the application name (web-demo-k8s as an example), and click Next.
- Select the Blank Template and click OK.
- 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.
- 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 from the navigation bar.
- Click Create Pipeline and configure the pipeline.
- 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.
- 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 4 Editing the stage name
- Click NewJob.
Click Add next to Build in the NewJob window.
Figure 5 Adding a job
- 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.
- Click Stage and change the stage name to Deploy.
- Click Job and add the Deploy extension.
- Select web-demo-k8s and select the job name 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, and click Save.
Figure 6 Configuring the execution plan
- 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 organization and the image.
- Log in to the SWR console.
- On the My Images page, select the image created in this example, and click Delete. In the displayed dialog box, click Yes.
- On the Organizations page, click the name of the organization to be deleted.
Click Delete. In the dialog box that is displayed, click Yes.
- Delete the cluster.
- Log in to the CCE console. In the list, locate the cluster to be deleted and click .
- 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.