Updated on 2023-08-31 GMT+08:00

Packaging, Creating, and Pushing an Image

  1. Create a build task. Select the repository WebServer created in preparations as the code source, select Maven as the build template, and set the task name to Create a Docker Image Using WebServer.

    The Maven template is preconfigured with the actions Build with Maven and Upload to Release Repos and default build commands. In most scenarios, you can directly use the preset actions to build and release the generated software package to the release repos.

  2. Delete the action Upload to Release Repos.

    This section describes how to pack, create, and push the image on which the project requires to SWR. Therefore, the action Upload to Release Repos is not needed. If you need to archive the software package to the release repo, retain this step. The build package is automatically generated in the ./target directory by default.

  3. Configure the action Build with Maven and ensure that the build commands and cache configuration are correct.

    1. Check the build commands: The template provides default parameter settings. Only verify that the parameters are correct.
      • By default, the command reads the pom file from the root directory. In this example, the pom file of the WebServer project is in the root directory and requires no changes.
      • WebServer requires JDK 1.8 for compilation and running. Ensure that the tool version is maven3.5.3-jdk8-open.
      • The target of this build is packaging. The default command is mvn package. For details about the default parameters, see the description of the default commands for Build with Maven.
    2. Check the cache setting.
      • CodeArts Build supports caches to accelerate your build. You can determine whether to use the cache by Cache Setting.
      • Network jitter, concurrent builds, or other extreme conditions may result in abnormal cache. Consequently, build errors may occur and you need to clear the cache by referring to the Cache Clearing.
        Huawei Mirrors is automatically configured as the open-source dependency source. Dependencies can be automatically downloaded into CodeArts Build without any additional configuration. The following image sources have been proxied or synchronized on Huawei Mirrors:
        • Maven2: https://repo1.maven.org/maven2/
        • Jboss: https://repository.jboss.org/nexus/content/repositories/releases/
        • Jcenter: https://mvnrepository.com/repos/jcenter
        • Grails-core: https://repo.grails.org/grails/core/
        • Grails-plugins: https://repo.grails.org/grails/plugins/
        • Spring-release: https://repo.spring.io/libs-release/
        • Spring-plugins: https://repo.spring.io/plugins-release/

  4. Configure the public repository that is not provided by CodeArts.

    In this example, the WebServer uses the lib.jar file from the third-party repository https://test.repo.com/. You need to configure the lib.jar file in Build with Maven.

    The configuration is shown in the following figure.

    The repository of this type must meet the following requirements:

    • The repository address can be directly accessed from the public network (Chinese Mainland).
    • No identity authentication information is required for dependency download.

  5. Configure a self-hosted repo.

    The util-1.0.jar package of the WebUtil project has been released to the self-hosted repo. This section uses this dependency as an example to describe how to use the self-hosted repo in the Creating a Docker Image Using WebServer task.

    1. Edit the pom.xml file in the local WebServer code directory and add the util-1.0.jar dependency to the <dependencies></dependencies> file.
      <dependency>
          <groupId>com.xx.demo</groupId>
          <artifactId>util</artifactId>
          <version>1.0</version>
      </dependency>
    2. Save the pom.xml file and upload it to the WebServer code repository again.
    3. In the action Build with Maven, select the self-hosted repo endpoint created in the preparations.

  6. Add the action Build Image and Push to SWR after the action Build with Maven and enter the required image information.

    • Image Repository: Retain the default value.
    • Organization: Enter the name of the organization created in preparations.
    • Image Name: Set this parameter to webserver.
    • Image Tag: Set this parameter to v1.1.
    • Work Directory: Retain the default value.
    • Dockerfile Path: In preparations, Dockerfile has been stored in the root directory of the WebServer project. The current build directory is the root directory of the project. The default value is ./Dockerfile.

  7. Save and execute the task. After the task is successfully executed, you can view the build result.