You can build your function using our provided builder, which already includes buildpacks and an invoker layer:
pack build my-java-fn --path . --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.0.10
Where my-java-fn is the name of your runnable function image, later used by Docker.
You may use tilt >v0.27.2 in combination with TAP's VS Code plugin to enable live development features including Application Live View and Live Update.
You will have to update some fields in the root directory's Tiltfile to connect your live session to Kubernetes.
This assumes you have Docker Desktop properly installed and running.
With Docker Desktop running, authenticated, and the ports (default 8080) available:
docker run -it --rm -p 8080:8080 my-java-fn
With our functions, you should see some HTML or sample text returned indicating a success.
After deploying your function, you can interact with the function by running:
curl -w'\n' localhost:8080/hire \
-H "Content-Type: application/json" \
-d '{"firstName":"John", "lastName":"Doe"}' -i
Where
/hireas a path invokes that specific function
If you'd like to test this function, you may use this CloudEvent saved as cloudevent.json:
{
"specversion" : "1.0",
"type" : "hire",
"source" : "https://spring.io/",
"id" : "A234-1234-1234",
"datacontenttype" : "application/json",
"data": {
"firstName": "John",
"lastName": "Doe"
}
}
NOTE: that you should change the contents of the CloudEvent you're testing against as you update the function.
After deploying your function as an image, you can test with:
curl -X POST -H "Content-Type: application/cloudevents+json" -d @cloudevent.json http://localhost:8080
NOTE: The provided
config/workload.yamlfile uses the Git URL for this sample. When you want to modify the source, you must push the code to your own Git repository and then update thespec.source.gitinformation in theconfig/workload.yamlfile.
You need to select the accelerator option Include TAP deployment resources when generating the project for the steps below to function.
When you are done developing your app, you can simply deploy it using:
tanzu apps workload apply -f config/workload.yaml
If you would like deploy the code from your local working directory you can use the following command:
tanzu apps workload create my-java-fn -f config/workload.yaml \
--local-path . \
--source-image <REPOSITORY-PREFIX>/my-java-fn-source \
--type web
Determine the URL to use for the accessing the app by running:
tanzu apps workload get my-java-fn
NOTE: This depends on the TAP installation having DNS configured for the Knative ingress.
After deploying your function, you can interact with the function by using:
NOTE: Replace the placeholder with the actual URL.
curl -w'\n' <URL>/hire \
-H "Content-Type: application/json" \
-d '{"firstName":"John", "lastName":"Doe"}' -i
Where
/hireas a path invokes that specific function
If you'd like to test this function, you may use this CloudEvent saved as cloudevent.json:
{
"specversion" : "1.0",
"type" : "hire",
"source" : "https://spring.io/",
"id" : "A234-1234-1234",
"datacontenttype" : "application/json",
"data": {
"firstName": "John",
"lastName": "Doe"
}
}
NOTE: that you should change the contents of the CloudEvent you're testing against as you update the function.
curl -X POST -H "Content-Type: application/cloudevents+json" -d @cloudevent.json <URL>