Some CI/CD pipeline toolsets support native capability (GitLab, BitBucket) to execute with a container. In other some cases, (CircleCI, Travis) all pipeline activity can only be executed within containers.
For toolsets which do not support this functionality, but do allow for self-hosted agents or where a self-hosted agent is preferred/mandated i.e. execution within a private network, the CDAF container helpers can provide consistency for construction, execution and housekeeping.
Even with a toolset uses containers, if they support docker-in-docker, the CDAF container helpers can still be utilised.
The containerBuild option allows the execution of the build process from within a container. Unlike toolsets which reference a image that is used to create the build container, CDAF uses a Dockerfile, for the following advantages:
Build Prerequisites can be defined in code, without being limited to available published images
Once constructed the image image cache provides improved performance, without having to use a image registry
Working directory and user home directory are volume mounted, to allow caching of build dependencies, e.g. Maven, node_modules
Container Build Configuration
To execute the build within a container, add the containerBuild definition and containerImage to CDAF.solution. Note: complete definitions are provided in the GitHub samples for Windows and Linux.
The following samples have the default process commented out, and can be used to define a custom process.
To supply variables to the build process, prefix with CDAF_CB_ (see CDAF Environment Variables) and the variables will be mapped into the build container.
See GitHub samples for Windows and Linux for dockerfile and additional properties.
Like containerBuild, containerDeploy provides both image build and container task execution. The common use for container deploy where a command line interface is required.
Master of Deployment Success
The containerDeploy option allows the execution of the deploy process from within a container. Unlike toolsets which reference a image that is used to create the deploy container, CDAF uses a Dockerfile, for the following advantages:
Deploy Prerequisites can be defined in code, without being limited to available published images
Once constructed the image image cache provides improved performance, without having to use a image registry
Container Deploy Configuration
To execute the deploy within a container, add the containerDeploy definition and runtimeImage (if not supplied, containerImage will be used) to CDAF.solution. Note: complete definitions are provided in the GitHub samples for Windows and Linux.
The following samples have the default process commented out, and can be used to define a custom process.
To supply variables to the build process, prefix with CDAF_CD_ (see CDAF Environment Variables) and the variables will be mapped into the build container.
See GitHub samples for Windows and Linux for dockerfile and additional properties.
Custom Image
The default directory used for container deploy is containerDeploy, if this is not found, the default Dockerfile is used, with the default runtime files. If you have your own Dockerfile in containerDeploy, or a custom directory specified in CDAF.solutioncontainerDeploy property, then that will be used.
Runtime Files
The release.sh file is included in the default image, however, if using a default image, this needs to be explicitly defined in CDAF.solutionruntimeFiles property. This can be a space separated list of files.
runtimeFiles=$WORKSPACE_ROOT/release.sh
Runtime Retain
To skip image clean-up, set CDAF.solutionruntimeRetain property.