Build Environment

The build environment defines the software available during build tasks.

Cloud Native Build uses Docker containers as the build environment.

Compared to traditional virtual machine containers, Docker containers offer significant advantages. As a result, many CI vendors in the industry are adopting this approach.

When using Cloud Native Build, ensure you are experienced with Docker containers or have a basic understanding of Docker fundamentals.

# Configuration Methods

There are two ways to configure Docker containers:

  1. Specify an image - These images were previously created and pushed to the image repository.
  2. Specify a Dockerfile - Cloud Native Build will use the Dockerfile to build the image on-the-fly (or use image cache under certain conditions) during the build process.

# Specify an Image

main:
  push:
    - docker:
        # Specify the image to use with this parameter
        image: node:22
      stages:
        - stage1
        - stage2
        - stage3

Specify an existing image in the image repository through the image parameter. It can be a publicly available image from official image repositories or other accessible image sources, or a private image (it requires additional parameters to specify the username and password).

# Specify a Dockerfile

main:
  push:
    - docker:
        # Specify the Dockerfile to use with this parameter
        build: ./image/Dockerfile
      stages:
        - stage1
        - stage2
        - stage3

Specify the path of a Dockerfile through the build parameter.

# VOLUME in the Image

The image may contain VOLUME commands. When the plugin task container starts, these volumes are shared with the plugin task using the --volumes-from parameter.

If the Dockerfile contains the following content:

RUN mkdir /cache && echo 'hello world' > /cache/data.txt

VOLUME /cache

It can be accessed in subsequent image-commands as well.

- name: Access pipeline volume in image-commands
  image: alpine
  commands:
    - cat /cache/data.txt

# Default Image

If neither the image nor the build parameter is specified, the default image cnbcool/default-build-env:latest will be used.

# Use Cases

# NodeJS

When you need to use the NodeJS build environment, you can directly use the official NodeJS image from Docker Hub.

main:
  push:
    - docker:
        image: node:16
      stages:
        - name: Install Dependencies
          script: npm install
        - name: Run Test Cases
          script: npm test