Building Images and Pushing Them to SWR
CodeArts Build provides a hybrid language build platform with simple configurations, supports one-click task creation, configuration, and execution, and automates activities such as code obtaining, building, and packaging.
Deployment failures often occur due to inconsistent environments. For example, the upgraded JDK in the R&D debugging environment is not marked in the environment list. As a result, the production environment is not upgraded accordingly, causing failures. To avoid problems caused by environment inconsistency, we package microservice applications and environments into images in this example to ensure that the environments (development and debugging, test, QA, and production) are consistent.
This section describes how developer Chris builds and archives images to SWR.
Preset Tasks
The sample project presets five build tasks.
Preset Task |
Description |
---|---|
phoenix-sample-ci |
Basic build task |
phoenix-sample-ci-test |
For building images in the test environment |
phoenix-sample-ci-worker |
For creating a Worker function image |
phoenix-sample-ci-result |
For creating a Result function image |
phoenix-sample-ci-vote |
For creating a Vote function image |
This section uses the phoenix-sample-ci task as an example. The built-in actions and their functions are described in the table below. After configuring the task parameters, you can execute the task.
Build Action |
Description |
---|---|
Build Vote Image and Push It to SWR |
Create a Vote image using the vote/Dockerfile file, and push the image to SWR for storage. |
Build Result Image and Push It to SWR |
Create a Result image using the result/Dockerfile file, and push the image to SWR for storage. |
Install Worker Dependency Using Maven |
Use Maven to install the dependencies required by the Worker function. |
Build Worker Image and Push It to SWR |
Create a Worker image using the worker/Dockerfile file, and push the image to SWR for storage. |
Create Postgres and Redis Dockerfiles |
Use shell commands to generate a Dockerfile for creating Postgres (database) and Redis (cache) images. |
Build Postgres Image and Push It to SWR |
Create a Postgres image using the Dockerfile generated in action Create Postgres and Redis Dockerfiles, and push the image to SWR for storage. |
Build Redis Image and Push It to SWR |
Create a Redis image using the Dockerfile generated in action Create Postgres and Redis Dockerfiles, and push the image to SWR for storage. |
Replace Image Version of Docker-Compose Deployment File |
To ensure that the correct image can be pulled and then deployed on ECS, run shell commands to perform the following operations:
|
Replace Image Version of Kubernetes Deployment File |
To ensure that the correct image can be pulled and then deployed on CCE, run shell commands to perform the following operations:
|
Upload Kubernetes Deployment File to Release Repo |
Upload all .yaml files modified in action Replace Image Version of Kubernetes Deployment File to the release repo for archiving. |
Upload Docker-Compose Deployment File to Release Repo |
Upload the docker-stack.tar.gz package generated in action Replace Image Version of Docker-Compose Deployment File to the release repo for archiving. |
Configuring and Executing a Task
- Go to the Phoenix Mall project, and choose CICD > Build from the navigation pane.
- In the Operation column of the phoenix-sample-ci task, click
and choose Edit.
- Click the Parameters tab, and set default values for the parameters listed in the following table.
Table 3 Setting parameters Name
Default Value
codeBranch
master
dockerOrg
The name of the organization created in Configuring SWR
version
1.0.0
dockerServer
The SWR server address obtained in Configuring SWR
- Click Save and Execute. In the displayed dialog box, click OK to start the build task.
If
is displayed, the task is successfully executed. Record the character string starting with # (for example,
).
If the task fails, rectify the fault based on the failed action and the error message in logs. For details, see CodeArts Build FAQs.
- Check the build artifact.
- In the navigation pane, choose Artifact > Release Repos.
- In the repository named after the project, find the docker-stack and phoenix-sample-ci folders.
- In the docker-stack folder, find the folder named after the character string recorded in 4. Then find the build artifact docker-stack.tar.gz in this folder.
- In the phoenix-sample-ci/1.0.0 folder, find the 10 archived .yaml files.
Figure 1 Checking the release repo - Go to the SWR console, choose Organizations from the navigation pane, and click the name of the organization created in Configuring SWR.
Click the Images tab. Then find the five images (redis, postgres, worker, result, and vote) in the list.
Figure 2 Viewing SWR - Click the names of the five images in sequence to go to their details page. View the image tag on the Tags tab page.
- The tag of redis is alpine.
- The tag of postgres is 9.4.
- The tags of worker, result, and vote are the same as those recorded in 4.
Configuring Auto Compilation upon Code Commits
After the following configuration is complete, code changes will automatically trigger the application build task, achieving continuous integration.
- Go to the Phoenix Mall project, and choose CICD > Build from the navigation pane.
- In the Operation column of the phoenix-sample-ci task, click
and choose Edit.
- Click the Schedule tab, toggle on
next to Run upon Code Commit, and click Save.
Since the default value of codeBranch on the Parameters tab is master, the build is automatically run when the code in master is changed.
Figure 3 Configuring the execution plan - Modify the project code and commit it to master. Then check whether the build task is automatically executed.
Configuring Scheduled Execution
You can perform the following operations to schedule the build task for a specific time:
- On the details page of task phoenix-sample-ci, click Edit.
- Click the Schedule tab.
- Enable Scheduled Execution (
means enabled), select days and time, disable Run upon code change, and click Save.
For this example, select All, and set the execution time to 12:00. (This example uses the default time zone. You can change it to the one you use.)
Figure 4 Scheduling executions - Check whether the build task is automatically executed at the configured time.
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