☁️ Using Custom Executors in CodeArts Build

Ertugrul Basar
Huawei Developers
Published in
7 min readFeb 27, 2024
CodeArts

🔦Introduction

Hi everyone 🙌! In today’s article, I’ll show you how you can utilize a custom executor on CodeArts Build. In CodeArts Build, resources are used to execute build tasks. VMs are typically employed for this purpose. Executors can either be built-in or custom. Built-in executors are provided by CodeArts Build with out-of-the-box availability, while custom executors are provided by users. You have the option to select either a built-in or custom executor. A custom executor is an agent executor added to the agent pool. We’ll delve into this concept shortly. But before that, I want to mention why you might want to use custom executors instead of built-in ones.

What are the advantages of custom executors?

Utilizing a custom executor when building cloud tasks offers numerous advantages tailored to your application’s specific requirements. With a custom executor, you can customize task execution to suit your needs, integrating seamlessly with existing systems and frameworks while optimizing performance and resource utilization. This customization enables specialized task handling, such as implementing custom retry strategies, error handling mechanisms, and logging, ensuring efficient and reliable task processing. Additionally, a custom executor provides greater control and flexibility over task execution workflows, allowing for the implementation of security and compliance requirements while optimizing costs and mitigating vendor lock-in concerns. Overall, leveraging a custom executor empowers you to design task execution workflows that align precisely with your application’s demands, delivering enhanced efficiency, scalability, and reliability.

Before I begin the demo, I want to briefly overview the services we are going to use.

⚡️ CodeArts: CodeArts is a one-stop DevSecOps platform that provides out-of-the-box cloud services for requirement delivery, code commit, check, build, verification, deployment, and release throughout the entire software lifecycle. It consists of the following services: Req (Project Management), Repo (Code Hosting), Check (Code Quality), Build (Code Build), Artifact (Build Hosting), Deploy (Build Deployment), Pipeline (Continuous Delivery), TestPlan (Deployment Test).

⚡️ ECS: Elastic Cloud Server (ECS) is a versatile and scalable cloud computing service that empowers users to create and manage virtual servers in the cloud.

⚡️ SWR: SoftWare Repository for Container (SWR) provides easy, secure, and reliable management of container images throughout their lifecycles, featuring image push, pull, and deleting.

💻Demo

  • Prerequisites for this demo

⭐️ CodeArts Repository

You need to upload the files you are going to use to a repository. Additionally, if you want to use the files I have used in this exercise, you can refer to this link.

CodeArts Repository

⭐️ ECS Instance

This article is about using custom executors, and in this exercise, we will configure an ECS instance to serve as our custom executor. I’ll create an instance with 2 vCPUs and 4 GB of RAM. Additionally, for this demonstration, I’ve chosen the operating system as Ubuntu 22.04

ECS Instance

⭐️ SWR Organization

To upload the image we are going to create, we need an SWR Organization. You can refer to the screenshot below and create an organization.

SWR Organization

⭐️ AK/SK Credentials

In the next steps, we are going to need an AK/SK pair. You can refer to the screenshot below to obtain it.

AK/SK Credentials

1️⃣ Create a Build Task

In the CodeArts Build page, click on ‘Create Task’.

Creating a Build Task — 1

In the “Set Information” page, we will name the task and choose the source code repository. Then, we will click on ‘Next’.

Creating a Build Task — 2

In the “Build Template” page, I’ll choose the Blank Template and click on ‘Next’. After that, the build task will be created.

Creating a Build Task — 3

2️⃣ Configure Build Environment

After creating the task, we will configure the build environment. To do that, we will expand the step by clicking on “Advanced Executor Settings.” Then we will select “Custom executor.” Since we don’t have an agent pool, we need to click on ‘Manage’.

Creating a Build Task — 4

3️⃣ Create an Agent Pool

Here we will click on ‘Create Pool’ and name it. We will choose the Pool Type as LINUX_DOCKER as we need Docker to build the image we are going to create.

Creating Agent Pool

After creating the agent pool, now we will create an agent. Click on ‘Create Agent’.

Creating Agent — 1

Next, a pop-up will appear, and here there are some instructions to add the ECS we created as an agent. In this demo, I will configure the ECS, so we’ll come back to this step after we log into our ECS and configure it. Before that, if we look at the instructions, it says that the machine we want to use as an agent must have Java 8, Git, and Docker installed.

Creating Agent — 2

4️⃣ Configure ECS

Next, we will log in to our ECS instance and run the following commands.

apt-get update
apt-get install openjdk-8-jre
apt-get install git
apt-get install docker.io

After installing all of this, you can check it as shown in the screenshots below 👇

Creating Agent — 3

5️⃣ Generate Agent command

After configuring the ECS, we need a command that will allow it to work as an agent in the pool we have created. First, I will turn off the installments because we have already done them. After that, we need to enter the AK/SK pair and click on ‘Generate Command’. Then we will copy the command.

Creating Agent — 4

Next, we will enter that command in our ECS and wait for it to finish. If you see the depicted log, it means that the installation process is successful and done.

Creating Agent — 5

You can also see it on the agent pool page as depicted in the screenshot below 👇

Creating Agent — 6

6️⃣ Add the ‘Build Image and Push to SWR’ step to build task and run

Now that we have installed the agent, we can go back to the build task and choose the agent pool we have created. After that, we will add the ‘Build Image and Push to SWR’ step and choose the SWR organization we created. Then we will name our image and its tag. After configuring all of these, we can run the task.

Creating a Build Task — 5

7️⃣ See the results

After clicking on “Run,” a new page will appear, and here you can observe the real-time logs. As you can see in the screenshot below, the task is successful.

Logs of the Build Task

If we go into SWR > My Images, we can see that the image is uploaded there under the organization we created.

SWR Images

👉Conclusion

In conclusion, this demonstration illustrates how to configure an ECS instance as a custom executor and integrate it with SWR using CodeArts Build. This approach offers significant advantages, allowing for customized task execution, enhanced resource utilization, and greater control over the deployment workflow. With the ability to tailor the deployment environment to specific project requirements, developers can optimize efficiency and reliability while maintaining flexibility and scalability. This serves as a simple guideline for this matter; you can use this task and customize it to fit your tasks and business needs. Until the next article, take care!

💁References

--

--