Build an Image with Build Arguments
Use docker argument in Codefresh pipelines
Building a Docker image that requires build arguments is very easy with Codefresh pipelines.
The source code of the repository is located at https://github.com/codefreshdemo/cf-example-build-arguments. Feel free to fork it if you want to follow along.
If you don’t already have a Codefresh account, 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 dockerfile:
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
The same thing can also be achieved 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 could 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.