Build Strategy

Build Strategy is used to control the build process. There are two types of strategies, ClusterBuildStrategy and BuildStrategy. Both strategies define a group of steps necessary to control the application build process.

ClusterBuildStrategy is cluster-wide, while BuildStrategy is namespaced.

There are 4 built-in ClusterBuildStrategy in OpenFunction, you can find more details in the following sections.

openfunction

The openfunction ClusterBuildStrategy uses Buildpacks to build function images which is the default build strategy.

The following are the parameters of the openfunction ClusterBuildStrategy:

NameTypeDescribe
RUN_IMAGEstringReference to a run image to use
CACHE_IMAGEstringCache Image is a way to preserve cache layers across different builds, which can improve build performance when building functions or applications with lots of dependencies like Java functions.
BASH_IMAGEstringThe bash image that the strategy used.
ENV_VARSstringEnvironment variables to set during build-time. The formate is key1=value1,key2=value2.

Users can set these parameters like this:

  1. apiVersion: core.openfunction.io/v1beta2
  2. kind: Function
  3. metadata:
  4. name: logs-async-handler
  5. spec:
  6. build:
  7. shipwright:
  8. params:
  9. RUN_IMAGE: ""
  10. ENV_VARS: ""

buildah

The buildah ClusterBuildStrategy uses buildah to build application images.

To use buildah ClusterBuildStrategy, you can define a Function like this:

  1. apiVersion: core.openfunction.io/v1beta2
  2. kind: Function
  3. metadata:
  4. name: sample-go-app
  5. namespace: default
  6. spec:
  7. build:
  8. builder: openfunction/buildah:v1.23.1
  9. dockerfile: Dockerfile
  10. shipwright:
  11. strategy:
  12. kind: ClusterBuildStrategy
  13. name: buildah

The following are the parameters of the buildah ClusterBuildStrategy:

NameTypeDescribeDefault
registry-searchstringThe registries for searching short name images such as golang:latest, separated by commas.docker.io,quay.io
registry-insecurestringThe fully-qualified name of insecure registries. An insecure registry is a registry that does not have a valid SSL certificate or only supports HTTP.
registry-blockstringThe registries that need to block pull access.“”

kaniko

The kaniko ClusterBuildStrategy uses kaniko to build application images.

To use kaniko ClusterBuildStrategy, you can define a Function like this:

  1. apiVersion: core.openfunction.io/v1beta2
  2. kind: Function
  3. metadata:
  4. name: function-kaniko
  5. namespace: default
  6. spec:
  7. build:
  8. builder: openfunction/kaniko-executor:v1.7.0
  9. dockerfile: Dockerfile
  10. shipwright:
  11. strategy:
  12. kind: ClusterBuildStrategy
  13. name: kaniko

ko

The ko ClusterBuildStrategy uses ko to build Go application images.

To use ko ClusterBuildStrategy, you can define a Function like this:

  1. apiVersion: core.openfunction.io/v1beta2
  2. kind: Function
  3. metadata:
  4. name: function-ko
  5. namespace: default
  6. spec:
  7. build:
  8. builder: golang:1.17
  9. dockerfile: Dockerfile
  10. shipwright:
  11. strategy:
  12. kind: ClusterBuildStrategy
  13. name: ko

The following are the parameters of ko ClusterBuildStrategy:

NameTypeDescribeDefault
go-flagsstringValue for the GOFLAGS environment variable.“”
ko-versionstringVersion of ko, must be either ’latest’, or a release name from https://github.com/google/ko/releases.“”
package-directorystringThe directory inside the context directory containing the main package.“.”

Custom Strategy

Users can customize their own strategy. To customize strategy, you can refer to this.