Building functions

Building a function creates an OCI container image for your function that can be pushed to a container registry. It does not run or deploy the function, which can be useful if you want to build a container image for your function locally, but do not want to automatically run the function or deploy it to a cluster, for example, in a testing scenario.

Local builds

You can build a container image for your function locally without deploying it to a cluster, by using the build command.

Prerequisites

  • You have a Docker daemon on your local machine. This is already provided if you have used the Quickstart installation.

Procedure

The build command uses the project name and the image registry name to construct a fully qualified container image name for the function. If the function project has not previously been built, you are prompted to provide an image registry.

funckn func

To build the function, run the following command:

  1. func build

To build the function, run the following command:

  1. kn func build

On-cluster Builds

If you do not have a local Docker daemon running, or you are using a CI/CD pipeline, you might want to build your function on the cluster instead of using a local build. You can create an on-cluster build by using the func deploy --remote command.

Prerequisites

  • The function must exist in a Git repository.
  • You must configure your cluster to use Tekton Pipelines. See the on-cluster build documentation.

Procedure

When running the command for the first time, you must specify the Git URL for the function:

funckn func

  1. func deploy --remote --registry <registry> --git-url <git-url> -p hello
  1. kn func deploy --remote --registry <registry> --git-url <git-url> -p hello

After you have specified the Git URL for your function once, you can omit it in subsequent commands.