|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * /serverless/functions/serverless-functions-getting-started.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="serverless-functions-creating-on-cluster-builds_{context}"] |
| 7 | += Building and deploying functions on the cluster |
| 8 | + |
| 9 | +You can use the Knative (`kn`) CLI to initiate a function project build and then deploy the function directly on the cluster. To build a function project in this way, the source code for your function project must exist in a Git repository branch that is accessible to your cluster. |
| 10 | + |
| 11 | +:FeatureName: {FunctionsProductName} |
| 12 | +include::snippets/technology-preview.adoc[leveloffset=+1] |
| 13 | + |
| 14 | +.Prerequisites |
| 15 | + |
| 16 | +* {pipelines-title} must be installed on your cluster. |
| 17 | +
|
| 18 | +* You have installed the OpenShift (`oc`) CLI. |
| 19 | +
|
| 20 | +* You have installed the Knative (`kn`) CLI. |
| 21 | +
|
| 22 | +.Procedure |
| 23 | + |
| 24 | +. In each namespace where you want to run {pipelines-shortname} and deploy a function, you must create the following resources: |
| 25 | + |
| 26 | +.. Create the functions buildpacks Tekton task to be able to build the function image: |
| 27 | ++ |
| 28 | +[source,terminal] |
| 29 | +---- |
| 30 | +$ oc apply -f https://raw.githubusercontent.com/openshift-knative/kn-plugin-func/serverless-1.22.0/pipelines/resources/tekton/task/func-buildpacks/0.1/func-buildpacks.yaml |
| 31 | +---- |
| 32 | + |
| 33 | +.. Create the `kn func` deploy Tekton task to be able to deploy the function in the pipeline: |
| 34 | ++ |
| 35 | +[source,terminal] |
| 36 | +---- |
| 37 | +$ oc apply -f https://raw.githubusercontent.com/openshift-knative/kn-plugin-func/serverless-1.22.0/pipelines/resources/tekton/task/func-deploy/0.1/func-deploy.yaml |
| 38 | +---- |
| 39 | + |
| 40 | +. Create a function: |
| 41 | ++ |
| 42 | +[source,terminal] |
| 43 | +---- |
| 44 | +$ kn func create <function_name> -l <runtime> |
| 45 | +---- |
| 46 | + |
| 47 | +. After you have created a new function project, you must add the project to a Git repository and ensure that the repository is available to the cluster. Information about this Git repository is used to update the `func.yaml` file in the next step. |
| 48 | + |
| 49 | +. Update the configuration in the `func.yaml` file for your function project to enable on-cluster builds for the Git repository: |
| 50 | ++ |
| 51 | +[source,yaml] |
| 52 | +---- |
| 53 | +... |
| 54 | +build: git <1> |
| 55 | +git: |
| 56 | + url: <git_repository_url> <2> |
| 57 | + revision: main <3> |
| 58 | + contextDir: <directory_path> <4> |
| 59 | +... |
| 60 | +---- |
| 61 | +<1> Required. Specify `git` build type. |
| 62 | +<2> Required. Specify the Git repository that contains your function's source code. |
| 63 | +<3> Optional. Specify the Git repository revision to be used. This can be a branch, tag or commit. |
| 64 | +<4> Optional. Specify the function's directory path if the function is not located in the Git repository root folder. |
| 65 | + |
| 66 | +. Implement the business logic of your function. Then, use Git to commit and push the changes. |
| 67 | + |
| 68 | +. Deploy your function: |
| 69 | ++ |
| 70 | +[source,terminal] |
| 71 | +---- |
| 72 | +$ kn func deploy |
| 73 | +---- |
| 74 | ++ |
| 75 | +If you are not logged into the container registry referenced in your function configuration, you are prompted to provide credentials for the remote container registry that hosts the function image: |
| 76 | ++ |
| 77 | +.Example output and prompts |
| 78 | +[source,terminal] |
| 79 | +---- |
| 80 | +🕕 Creating Pipeline resources |
| 81 | +Please provide credentials for image registry used by Pipeline. |
| 82 | +? Server: https://index.docker.io/v1/ |
| 83 | +? Username: my-repo |
| 84 | +? Password: ******** |
| 85 | + Function deployed at URL: http://test-function.default.svc.cluster.local |
| 86 | +---- |
| 87 | + |
| 88 | +. To update your function, commit and push new changes by using Git, then run the `kn func deploy` command again. |
0 commit comments