Building an Image and Pushing It to SWR
Upload the build artifact to SWR.
If necessary dependency packages and tools are missing, you can create a custom image from a Dockerfile and push the image to SWR. For details about how to use the pushed image, see Using a Custom Build Environment.
Tutorial Video
Learn to create a custom Maven image and push it to SWR.
Preparations
- You have created an organization in SWR. For details about organization restrictions, see notes and constraints of SWR.
- If you want to push the created image to SWR of other Huawei Cloud users, perform the following operations.
- Access the CodeArts Build homepage from the project list.
- In the navigation pane, choose .
- Select IAM user from the Create Endpoint drop-down list box. In the displayed dialog box, enter the following information and click Confirm.
- Service Endpoint Name: Assign a custom name to the endpoint. Enter a maximum of 256 characters, including letters, digits, hyphens (-), underscores (_), periods (.), and spaces.
- Access key ID (AK) and secret access key (SK) are used like passwords to authenticate users who make API requests.
On the CodeArts Build homepage, click Console, hover the cursor on the username in the upper right corner, and choose My Credentials from the drop-down list. In the navigation pane on the left, choose Access Keys to create a user key.
- If you want to push the created image to other image repositories, perform the following operations.
- Access the CodeArts Build homepage from the project list.
- In the navigation pane, choose .
- Select Docker repository from the Create Endpoint drop-down list box. In the displayed dialog box, enter the following information and click Confirm.
- Service Endpoint Name: Assign a custom name to the endpoint. Enter a maximum of 256 characters, including letters, digits, hyphens (-), underscores (_), periods (.), and spaces.
- Repository Address: Enter the address of the target image repository.
- Username: Enter the username for logging in to the repository.
- Password: Enter the password used for logging in to the repository.
Build on GUI
Add Build Image and Push to SWR after Build with Maven, when configuring build actions.
Retain the default values for the Build with Maven action. If the current parameter settings do not meet your requirements, modify the parameter settings by referring to Building with Maven. For details about the parameters for the Build Image and Push to SWR action, see Table 1.
Parameter |
Description |
---|---|
Action Name |
Assign a custom name to the build action. The name can contain:
|
Tool Version |
Select the Docker version, or use the default one. Currently, CodeArts Build supports Docker 18.03 and Docker 20.10. |
Image Repository |
Select the target image repository. You can push the image to Huawei Cloud SWR and other image repositories. |
Authorized User |
Specify the user to which the target image repository belongs. You can push the image to the current user or other user's image repository. Ensure that you have permissions to edit or manage all images in the organization. For details, see User Permissions. |
IAM Account |
Expand the drop-down list and select the service endpoint created in Preparations for the specific IAM account. Then, use the service endpoint to push the files to the user's SWR. This parameter is mandatory when Authorized User is set to Other. |
Push Region |
Select the target region of your push. The built image will be pushed to the SWR repository in this region. |
Docker Repository Endpoint |
Select the Docker repository service endpoint created in Preparations and push the image to the corresponding repository through the service endpoint. |
Organization |
Select the organization created in Preparations from the drop-down list box. The image will be placed in this organization after being pushed to SWR. |
Image Name |
Enter the name of the created image. The value must start with a digit or letter and can contain 1 to 255 characters, including only lowercase letters, digits, underscores (_), and hyphens (-). |
Image Tag |
Specify the image tag, which can be customized. You can use Image name:Tag to uniquely specify an image. The value can contain 1 to 128 characters, including only letters, digits, periods (.), underscores (_), and hyphens (-). It cannot start with periods or hyphens. |
Working Directory |
Work directory of docker build. The context path parameter in the docker build command is the relative path of the root directory of the repository. When Docker builds an image, the docker build command packs all content under the context path and sends it to the container engine to help build the image. |
Dockerfile Path |
Path of the Dockerfile. Set this parameter to a path relative to the working directory. For example, if the working directory is the root directory and the Dockerfile is in the root directory, set this parameter to ./Dockerfile. |
Add Build Metadata to Image |
Specify whether to add the build information to the image. After the image is created, run the docker inspect command to view the image metadata. |
Continue After Failure |
Specify whether to proceed after the current action fails by setting the parameter to either Yes or No. |
Build with Code
Modify the code in the BUILD block in Creating a YAML File for Your Code-based Build by referring to the following sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
version: 2.0 # The value must be 2.0. steps: BUILD: - build_image: name: buildImage inputs: regions: ["x-x-x", "x-x-xxx"] organization: codeci_test image_name: demo image_tag: ${GIT_COMMIT} dockerfile_path: dockerfile/Dockerfile build_args: - name: aaa value: iuhascihsd # set_meta_data: true ignore_fail: true |
Parameter |
Type |
Description |
---|---|---|
regions |
List |
Optional. Select the region of SWR where the image is to be uploaded to. By default, the image is uploaded to SWR in the region where the current task is located. If multiple regions are configured, the built image will be pushed to SWR in each region in sequence after the image is created. |
organization |
String |
Enter the name of the organization to which the image belongs after being pushed to SWR. The organization name is the name of the organization created in Preparations. |
image_name |
String |
Optional. Enter the name of the created image. The value must start with a digit or letter and can contain 1 to 255 characters, including only lowercase letters, digits, underscores (_), and hyphens (-). The default value is demo. |
image_tag |
String |
Optional. Specify the image tag, which can be customized. You can use Image name:Tag to uniquely specify an image. The value can contain 1 to 128 characters, including only letters, digits, periods (.), underscores (_), and hyphens (-). It cannot start with periods or hyphens. The default value is v1.1. |
context_path |
String |
Optional. Work directory of docker build. The context path parameter in the docker build command is the relative path of the root directory of the repository. When Docker builds an image, the docker build command packs all content under the context path and sends it to the container engine to help build the image. The default value is .. |
dockerfile_path |
String |
Optional. Path of the Dockerfile. Set this parameter to a path relative to the working directory. For example, if the working directory is the root directory and the Dockerfile is in the root directory, set this parameter to ./Dockerfile. The default value is ./Dockerfile. |
build_args |
String |
|
set_meta_data |
Bool |
Optional. Specify whether to add the build information to the image. After the image is created, run the docker inspect command to view the image metadata.
The default value is false. |
ignore_fail |
String |
Whether to proceed after the current action fails.
|
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