Build Environment
About 319 wordsAbout 1 min
The build environment determines which software is available 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 industry CI vendors are moving in this direction.
When using Cloud Native Build
, ensure you have experience with Docker containers, or at least understand basic Docker concepts.
Configuration Methods
There are two ways to configure Docker containers:
- Specify an image (pre-built image). These images were previously created by others and pushed to image repositories.
- Specify a Dockerfile. At build start,
Cloud Native Build
will create an image from the Dockerfile (using cache under certain conditions).
Specifying an Image
main:
push:
- docker:
# Use this parameter to control the image
image: node:22
stages:
- stage1
- stage2
- stage3
Use the pipeline.docker.image parameter to specify the Docker Image. The value can be a public image from official sources or other accessible image repositories.
Specifying a Dockerfile
main:
push:
- docker:
# Use this parameter to control the Dockerfile
build: ./image/Dockerfile
stages:
- stage1
- stage2
- stage3
Use the pipeline.docker.build parameter to specify the Dockerfile.
VOLUME in Images
Images may contain VOLUME
commands. When starting plugin tasks, these volumes will be shared with the plugin tasks via the --volumes-from
parameter.
For example, preparing files in Dockerfile:
RUN mkdir /cache && echo 'hello world' > /cache/data.txt
VOLUME /cache
These can also be accessed in subsequent image-commands.
- name: Access pipeline volume in image-commands
image: alpine
commands:
- cat /cache/data.txt
Default Image
If neither method is declared, the default value cnbcool/default-build-env:latest
will be used.
Usage Examples
NodeJS
When needing a NodeJS build environment, you can directly use the official NodeJS image from Docker Hub.
main:
push:
- docker:
image: node:20
stages:
- name: Install dependencies
script: npm install
- name: Run tests
script: npm test