Build Environment
The build environment determines which software is available in the environment when running build tasks.
Cloud Native Build
uses Docker containers as the build environment.
Compared to traditional virtual machine containers, Docker containers have significant advantages, and various CI vendors in the industry are also moving in this direction.
When using Cloud Native Build
, make sure you have experience using Docker containers
or at least have a basic understanding of Docker fundamentals.
# Configuration Methods
There are two ways to configure Docker containers:
- Specify an image (existing image). These images have been created by others and pushed to a container registry.
- Specify a Dockerfile.
Cloud Native Build
will use the Dockerfile to build the image on-the-fly (or use 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 the Docker Image using the pipeline.docker.image parameter. Its value can be a public image from the official image repository in the public network or other accessible image sources.
# Specify a Dockerfile
main:
push:
- docker:
# Specify the Dockerfile to use with this parameter
build: ./image/Dockerfile
stages:
- stage1
- stage2
- stage3
Specify the Dockerfile using the pipeline.docker.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.
For example, if the Dockerfile prepares a file:
RUN mkdir /cache && echo '[{"author_email": "git_user1@xxx.com"}]' > /cache/cache.json
VOLUME /cache
It can be accessed in subsequent image-commands
as well.
- name: Access pipeline volume in image-commands
image: alpine
commands:
- cat /cache/cache.json
# Default Image
If neither of the above methods is specified, the default value 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