☁️Deploy a Python Application on a Huawei CodeArts CI/CD Pipeline

Hakanaktas
Huawei Developers
Published in
7 min readAug 7, 2024
Huawei Cloud Codearts

Introduction

Continuous Integration and Continuous Deployment (CI/CD) are key components of modern DevOps that streamline the transition from code development to deployment through an automated pipeline. This approach helps improve consistency and efficiency in software releases.

Codearts CI/CD Architecture

The fundamental aim of employing CI/CD is to enhance the efficiency and reliability of software delivery processes. This approach automates the integration and deployment phases, allowing for continuous code validation through automated builds and tests. CI/CD addresses key challenges such as reducing the risk of human error, minimizing code integration issues, and accelerating time to market.

Huawei Cloud CodeArts Services

In this article, we will explore setting up a CI/CD pipeline using Huawei Cloud’s CodeArts service, focusing on the practical steps involved.

Step-1: Creating Project:

  1. Firstly, create a project by selecting a scrum template.
  2. Then, enter a name and click ‘OK’.

Basic information:

  • Work Template: Scrum (System)
  • Name: Python Flask Application
  • Others: Default
Creating Project Page

Step-2: Creating Repository:

  1. After creating a project, go to Code > Repo page from the left side menu.
  2. Click on “New Repository” to create a repository. There are 3 repository types Common, Template, and Import.
  3. Select the repository type as an “Import” to pull the repository from GitHub and click “Next”.
  4. Select “Git URL” in the Import From Section. To import the source code enter the Source Repository URL of the GitHub repository.
  5. Give detailed information about what will be created repository.

Basic information:

  • Repository Type: Import (Import a repository from Git URL, SVN, GitHub, and GitLab)
  • Import From: Git URL
  • Source Repository URL: https://github.com/hakanaktas1/codearts-python-flask.git
  • Visibility: Public
  • Repository Name: codearts-python-flask
  • Initial Settings: Enable
  • Visibility: Public
  • Branch: Default branch
  • Schedule: Enable
Creating Repository

Step-3: Creating Building Actions

  1. After creating a repository, go to CICD > Build page. Click “Create Task” to create a building task.
  2. Enter the basic information such as project name, code source, and repository, and click “Next”.
  3. In the CodeArts Build service, there are several templates to provide easy of use for developers. In this exercise, “Blank Template” will be selected.
  4. After opening the blank template on the left side GUI click “Add Action” select “Run Shell Commands” and then, “Upload Release Repo”
  5. Copy the following command and paste it on the terminal of “Run Shell Commands”. Enter the “Package Location” and “Package Name” information like below for “Upload to Release Repo”. Lastly, click “Save and Run”
tar -zcvf demo.tar.gz **

Basic information:

  • Name: flask-build
  • Project: Python Flask Application
  • Source Code: Repo
  • Repository: codearts-python-flask
  • Default Branch: Master
  • Build Templates: Blank Templates
  • Package Location: ./demo.tar.gz
  • Version: v1
  • Package Name: flask
  • Action Control > Execute this action with the sudo permission: Enable
Creating Building Actions

After finishing the building, you can check the progress on the left side menu and also, from by building logs. If there are any errors it shows and gives solution suggestions.

Since we see the success log at the end of the logs, there is no problem and we can continue. 👌

Build Logs

Go to the Artifact > Release Repos and check the building material like below.

Artifact > Release Repos Checking

Step-4: Creating Host Cluster on Basic Resources

  1. Before moving to the deploy actions, you must create a host cluster and add the target host that computing instances for running the application.
  2. Go to Settings> General > Basic Resources and click “Create Host Cluster”
  3. Enter the basic information such as “Cluster Name”, “OS”, “Host Connection Mode”, etc.
  4. On the “Target Host” section, click “Add Host” Select your host from the list shown, and import it.
  5. Enter detailed information about the host such as “Host Name”, “Authorization”, “Username”, “Password” and “SSH Port”.
  6. Click “OK” to add and you should see the cluster below.

Basic information:

Cluster Name: flaskApp

OS: Linux

Host Connection Mode: Direct Connection

Execution Resource Pool: Official

Host Name: ecs-flask

Authorization: Password

Username: root

SSH Port: 22

Note: Make sure that port 22 for SSH connection and 8080 for Web Application are open in the security group to which the host belongs.

Cluster creation for deployment

Step-5: Creating Deploy Actions

  1. Go to the CICD > Deploy page on the left side menu. Then, click “Create Application”.
  2. Enter the basic information about the project such as “Name”, “Project”, etc.
  3. Select the “Deploy a General Application” template to deploy the project by using the shell script.
  4. Go to the “Environment Management” section on the top menu, and click “Create Environment”.
  5. Enter basic information about the environment such as “Environment Name”, “Resource Type” and “OS”.
  6. On the “Resources” page, select the host that you create in Step 4.
  7. Click “Import” and the virtual machine on which the deployment process will be performed has been selected.
  8. Go to the “Parameters” and enter the detailed information for deployment like given information below.
  9. Copy and paste the following command on the “Deployment Action” > “Run Shell Command”.
  10. Finally, everything is ready for deployment. Just click “Save & Deploy”.
cd /usr/local
nohup python3 app.py &

Basic information:

Name: deployenv-flask

Template: Deploy a General Application

Environment: env

Resource Type: Host

OS: Linux

Download Software Package > Source: Artifact

Download Software Package > Environment: env

Download Software Package > Software Package: /flask/v1/flask_targz.tar.gz

Download Software Package > Download Path: /usr/local

Decompress File > Environment: env

Decompress File > File Path: /usr/local/web_app/flask_targz.tar.gz

Decompress File > Target Path: /usr/local/web_app

Action Control > Execute this action with the sudo permission: Enable

Creating Deploying

Step-6: Creating Pipeline

  1. Go to the CICD > Pipeline and click “Create Pipeline”
  2. Enter the basic information as given below.
  3. Select the “Python-Build” template and click “OK”.
  4. After you create a template, click “Build-Task” enter the information, and select the build task that you created on the Step 3
  5. Click on “ + Stage” to add the deploy stage. Then, click on “+ Job” to add a Deploy extension.
  6. Select the deploy task you created on step-5 and click “OK”.
  7. Finally, the pipeline is ready! Click “Execute”
Codearts Pipeline GUI

Step-7: Accessing the Web Application on the Browser

  1. Go to the “Elastic Cloud Server” service and copy the Elastic IP of the host to which you deploy the application.
  2. Paste it on the browser, the URL should be like below.
  3. If you can view the web page like the one below, congratulations.
Basic Python Flask Web Application Screen Shot-1
Basic Python Flask Web Application Screen Shot-2

Conclusion

Deploying a Python application through a CodeArts CI/CD pipeline offers a streamlined, efficient, and reliable approach to software deployment. By automating the build, test, and deployment stages, CodeArts helps teams focus on writing quality code and accelerating their development cycles. The integration with Huawei Cloud’s ecosystem further enhances scalability and performance, making it an ideal choice for projects of varying complexity.

Throughout this process, we’ve seen how CodeArts simplifies the setup of continuous integration and delivery, ensuring that every change is tested and deployed in a consistent manner. This not only reduces the likelihood of human errors but also enables faster iterations and more robust software. As organizations increasingly adopt DevOps practices, leveraging tools like CodeArts becomes essential for maintaining competitive edge and operational efficiency in software development.

Whether you are working on a small-scale application or a complex, enterprise-grade system, deploying with CodeArts CI/CD pipeline provides a reliable foundation for continuous delivery, allowing you to innovate and adapt to changing requirements with confidence.

References

--

--