Version: 4.11

Custom Build Scripts

custom

Using custom as build tool allows you to define a custom command for building images. This is particularly useful if you want to use a remote build system such as Google Cloud Build.

warning

Make sure your custom build command terminates with exit code 0 when the build process was successful.

command

The onChange option expects an array of strings which represent paths to files or folders that should be watched for changes. DevSpace uses these paths and the hash values it stores about these paths for evaluating if an image should be rebuilt or if the image building can be skipped because the context of the image has not changed.

info

It is highly recommended to specify this option when using custom as build tool in order to speed up the build process.

Example: Building Images With custom Build Command

images:
backend:
image: john/appbackend
build:
custom:
command: ./build
args:
- "--arg1"
- "--flag"
- "flag-value"
- "--arg2"

Explanation:
The image backend would be built using the command ./build arg1 --flag=flag-value arg2 "[IMAGE]:[TAG]" while [IMAGE] would be replaced with the image option (in this case: john/appbackend) and [TAG] would be replaced with the tag generated according to the tagging schema.

imageFlag

The onChange option expects a string which states the name of the flag that is used to pass the image name (including auto-generated tag) to the custom build script defined in command.

Default Value For imageFlag

imageFlag: "" # Defaults to passing image and tag as an argument instead of using a flag

Example: Defining imageFlag For custom Build Command

images:
backend:
image: john/appbackend
build:
custom:
command: ./build
imageFlag: image
args:
- "--arg1"
- "--flag"
- "flag-value"
- "--arg2"

Explanation:
The image backend would be built using the command ./build arg1 --flag=flag-value arg2 --image="[IMAGE]:[TAG]" while [IMAGE] would be replaced with the image option (in this case: john/appbackend) and [TAG] would be replaced with the tag generated according to the tagging schema.

args

The args option expects an array of strings which represent additional flags and arguments that should be passed to the custom build command before the argument containing [IMAGE]:[TAG].

Default Value For args

args: []

Example: Using args and appendArgs For Custom Builds

images:
backend:
image: john/appbackend
build:
custom:
command: ./build
args:
- "--flag1"
- "flag-value-1"
- "arg1"
- "arg2"
appendArgs:
- "arg3"
- "--flag2"
- "flag-value-2"

Explanation:
The image backend would be built using the command ./build --flag1=flag-value-1 arg1 arg2 [IMAGE]:[TAG] arg3 --flag2=flag-value-2 while [IMAGE] would be replaced with the image option (in this case: john/appbackend) and [TAG] would be replaced with the tag generated according to the tagging schema.

appendArgs

The appendArgs option expects an array of strings which represent additional flags and arguments that should be passed to the custom build command after the argument containing [IMAGE]:[TAG].

Default Value For appendArgs

appendArgs: []

Example

See "Example: Using args and appendArgs For Custom Builds"

onChange

The onChange option expects an array of strings which represent paths to files or folders that should be watched for changes. DevSpace uses these paths and the hash values it stores about these paths for evaluating if an image should be rebuilt or if the image building can be skipped because the context of the image has not changed.

info

It is highly recommended to specify this option when using custom as build tool in order to speed up the build process.

Default Value For onChange

onChange: []

Example: OnChange Option For custom Build Command

images:
backend:
image: john/appbackend
build:
custom:
command: ./build
imageFlag: image
onChange:
- some/path/
- another/path/file.txt

Explanation:
The image backend would be built using the command ./build --image="[IMAGE]:[TAG]" and DevSpace would skip the build if none of the files within some/path/ nor the file another/path/file.txt has changed since the last build.