☁️Deploy a Python Application on a Huawei CodeArts CI/CD Pipeline
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.
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.
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:
- Firstly, create a project by selecting a scrum template.
- Then, enter a name and click ‘OK’.
Basic information:
- Work Template: Scrum (System)
- Name: Python Flask Application
- Others: Default
Step-2: Creating Repository:
- After creating a project, go to Code > Repo page from the left side menu.
- Click on “New Repository” to create a repository. There are 3 repository types Common, Template, and Import.
- Select the repository type as an “Import” to pull the repository from GitHub and click “Next”.
- Select “Git URL” in the Import From Section. To import the source code enter the Source Repository URL of the GitHub repository.
- 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
Step-3: Creating Building Actions
- After creating a repository, go to CICD > Build page. Click “Create Task” to create a building task.
- Enter the basic information such as project name, code source, and repository, and click “Next”.
- In the CodeArts Build service, there are several templates to provide easy of use for developers. In this exercise, “Blank Template” will be selected.
- After opening the blank template on the left side GUI click “Add Action” select “Run Shell Commands” and then, “Upload Release Repo”
- 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
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. 👌
Go to the Artifact > Release Repos and check the building material like below.
Step-4: Creating Host Cluster on Basic Resources
- Before moving to the deploy actions, you must create a host cluster and add the target host that computing instances for running the application.
- Go to Settings> General > Basic Resources and click “Create Host Cluster”
- Enter the basic information such as “Cluster Name”, “OS”, “Host Connection Mode”, etc.
- On the “Target Host” section, click “Add Host” Select your host from the list shown, and import it.
- Enter detailed information about the host such as “Host Name”, “Authorization”, “Username”, “Password” and “SSH Port”.
- 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.
Step-5: Creating Deploy Actions
- Go to the CICD > Deploy page on the left side menu. Then, click “Create Application”.
- Enter the basic information about the project such as “Name”, “Project”, etc.
- Select the “Deploy a General Application” template to deploy the project by using the shell script.
- Go to the “Environment Management” section on the top menu, and click “Create Environment”.
- Enter basic information about the environment such as “Environment Name”, “Resource Type” and “OS”.
- On the “Resources” page, select the host that you create in Step 4.
- Click “Import” and the virtual machine on which the deployment process will be performed has been selected.
- Go to the “Parameters” and enter the detailed information for deployment like given information below.
- Copy and paste the following command on the “Deployment Action” > “Run Shell Command”.
- 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
Step-6: Creating Pipeline
- Go to the CICD > Pipeline and click “Create Pipeline”
- Enter the basic information as given below.
- Select the “Python-Build” template and click “OK”.
- After you create a template, click “Build-Task” enter the information, and select the build task that you created on the Step 3
- Click on “ + Stage” to add the deploy stage. Then, click on “+ Job” to add a Deploy extension.
- Select the deploy task you created on step-5 and click “OK”.
- Finally, the pipeline is ready! Click “Execute”
Step-7: Accessing the Web Application on the Browser
- Go to the “Elastic Cloud Server” service and copy the Elastic IP of the host to which you deploy the application.
- Paste it on the browser, the URL should be like below.
- If you can view the web page like the one below, congratulations.
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.