Build an Image with build arguments
Use Docker arguments in Codefresh pipelines
Building a Docker image that requires build arguments is very easy with Codefresh pipelines.
The source code of the repository is at https://github.com/codefreshdemo/cf-example-build-arguments. Feel free to fork it if you want to follow along.
If you don’t have a Codefresh account already, you can easily create a free one from the sign-up page.
Using Docker build arguments
The example application is a very simple NodeJS application with the following DYouockerfile:
This Dockerfile expects two build arguments:
NODE_VERSIONis the version of Node image to use as base
APP_DIRis the source directory to be used inside the container
Building a Dockerfile passing values for build arguments
When you build an image locally on your workstation, you can define build arguments with the
docker build . -t my-node-app --build-arg NODE_VERSION=8 --build-arg APP_DIR=/usr/src/app
You can get the same result within a Codefresh pipeline:
This pipeline checks out the source code of the repository and then builds the Dockerfile by passing the values
/usr/src/app to the two arguments.
Using Codefresh variables as build arguments
In the previous pipeline, the Docker build arguments are defined in the pipeline itself, but you can also use pipeline variables, shared configuration, or any other standard mechanism you already have in place.
In this case, you can also use any of the built-in Codefresh variables.
CI/CD pipeline examples
Build step in pipelines
Build an Image with the Dockerfile in root directory
Build an Image by specifying the Dockerfile location
Build an Image from a different Git repository
Build and push an Image