Container Registry allows you to build images from source code with the following features: continuous integration, security, high concurrency, stability, and high efficiency. This topic describes how to build images by using Container Registry Enterprise Edition.

Background information

The image building service of Container Registry features security, stability, and high efficiency:
  • Security: During an image build, the system distributes a single image build task to a new, exclusive, and environment-isolated machine. This ensures the absolute security of code and image assets.
  • Stability: If you use a source code repository to build multiple images, the time consumption of each image build is stable because each image build task is run on an exclusive machine.
  • High efficiency:
    • By default, the system uses the efficient building tool BuildKit. BuildKit has the highest building capabilities, especially for multi-stage builds scenarios, and supports rich building features.
    • The system hosts common base images. During image building, the system can use base images without the need to pull images. Base images help reduce the building time.
    • The system uses the remote cache to accelerate image building.
      Note If you want to use this feature, submit a ticket in the .
The image building service of Container Registry supports multiple code hosting platforms. You can also accelerate image building by using data centers outside China and generate accelerated images.
  • Five code hosting platforms are supported.
    Code hosting platform Edition Limit
    Github Container Registry Personal Edition N/A
    GitLab All editions N/A
    Alibaba Cloud Code All editions An image build is not automatically triggered when the code changes.
    Apsara DevOps Codeup All editions N/A
    GitEE All editions N/A
  • If you use data centers outside China to accelerate image building, you can turn on Intelligently Build Overseas Sources. The system uses the acceleration link when it pulls images from the data centers outside China. This prevents cross-border network issues.
  • Generate accelerated images: The system allows you to load resources of a container image on demand. The accelerated version of the container image is automatically generated after the container image is pushed. For more information, see Load resources of a container image on demand.

Step 1: Bind your instance to a source code hosting platform

Before you build images, you must bind your instance to a source code hosting platform. For more information, see Bind a source code hosting platform.

Step 2: Create an image repository

Create an image repository and bind it to a code repository. All image builds triggered by the code repository are pushed to the image repository.

  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click the required Container Registry Enterprise Edition instance.
  5. On the management page of the Container Registry Enterprise Edition instance, choose Repositories > Repositories in the left-side navigation pane.
  6. On the Repositories page, click Create Repository.
  7. In the Repository Info step, set the Namespaces, Repository Name, Repository Type, Tags, Summary, and Description parameters, and click Next.
    Note If you select Immutable next to Tags, all images except for those with the latest tag in the repository cannot be overwritten. After you set an image tag as immutable, you can rely on the tag to correlate the deployed image version with the build that produced the image.
  8. In the Code Source step, set the Code Source, Build Settings, and Build Rules parameters, and click Create Repository.
    Parameter Description
    Code Source The code source.
    Build Settings
    • Automatically Build Images When Code Changes: If you select this option, an image is automatically built when code is committed from a branch.
    • Build With Servers Deployed Outside Mainland China: If you select this option, images are built in a data center outside mainland China and then pushed to the image repository.
    • Build Without Cache: If you select this option, the system pulls the dependent base image for every image to be built. This may prolong the build time.
    Build Rules After the repository is created, you can go to the Build page to create build rules. For more information, see Create a repository and build images.
    On the Repositories page, click the created image repository. If you can view Build in the left-side navigation pane of the repository management page, the image repository is bound to the source code repository.

Step 3: Configure an image build rule

  1. Log on to the Container Registry console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Instances.
  4. On the Instances page, click the required Container Registry Enterprise Edition instance.
  5. On the management page of the Container Registry Enterprise Edition instance, choose Repositories > Repositories in the left-side navigation pane.
  6. On the Repositories page, find the created image repository and click Manage in the Actions column.
  7. In the left-side navigation pane, click Build. In the Build Rules section, click Add Build Rule. In the Build Information step of the Add Build Rule dialog box, set the following parameters and click Next.
    Parameter Description
    Type Specify the type of the source code repository. Valid values: Branch and Tag.
    Branch/Tag Select or enter a branch or a tag. Regular expressions are supported. If you specify the release-(?<imageTag>\w*) regular expression, the system automatically builds an image of V1 when the source code under the release-v1 branch is updated. The image cannot be built immediately. For more information about how to specify regular expressions, see Use regular expressions in named capturing groups.
    Note After you specify regular expressions, images can be built only by the system. You cannot manually build images.
    Dockerfile Directory The directory where the Dockerfile resides. You must specify a relative directory. The parent directory is the root directory of the code branch.
    Dockerfile Filename The name of the Dockerfile. The default name is Dockerfile.
  8. In the Tag step, set the parameters, click Save, and then click Next.
    Note Click Add Configuration to add an image tag. You can specify up to three image tags.
    Parameter Description
    Image Tag The tag of the image, for example, latest. You can enable named capturing groups. For example, you can use the captured content if you specify a named capturing group for Branch/Tag.
    Build Time The time when source code is pushed in UTC+8 format, for example, 20201015 or 202010151613.
    Note This parameter is optional. If you set this parameter, images can be built only by the system. You cannot manually build images.
    Commit ID The number of characters to be obtained from the commit ID of the most recently pushed code. By default, the first six characters are used. You can drag the slider to change the number of characters.
    Note This parameter is optional. If you set this parameter, images can be built only by the system. You cannot manually build images.
  9. In the Build Configurations step, set the following parameters and click Confirm.
    Parameter Description
    Build Architecture The architecture for which you want to build images. You can select multiple architectures.If you select multiple architectures, multiple container images for the architectures are built for each image tag.
    Build Parameters The runtime parameters of the image build. Each build parameter is a key-value pair that is case-sensitive. You can set a maximum of 20 build parameters.
  10. Trigger the image build rule.
    You can use one of the following methods to trigger an image build rule:
    • In the Build Rules section of the Build page, find the image build rule and click Build in the Actions column.
    • Submit code to the master branch of the source code repository to trigger the build rule.
    Note
    • In the Build Log section of the Build page, find the triggered image build and click Cancel in the Actions column to cancel the image build task.
    • In the Build Log section of the Build page, find the triggered image build and click Log in the Actions column to view the image build log.

Additional information

  • Use data centers outside China to accelerate image building

    The Dockerfile of your project may need to be downloaded from a website outside China, but the cross-border network is unstable. To resolve this issue, you can turn on Intelligently Build Overseas Sources on the Build page. By default, the switch is turned off.

  • Build images by using the cache

    On the Build page, turn off Build Without Cache. By default, the switch is turned off. This way, image building can be accelerated.