Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 00451d4

Browse files
committed
chore(tests, docs): Update after new knative func cli updates
This commit updates documentation to account for the latest version of https://github.com/knative/func which has requirements for valid func.yaml files. It also removes func.yaml files and updates tests to use the BP_FUNCTION environment variable. Signed-off-by: Joe Eltgroth <[email protected]>
1 parent 9ab1b25 commit 00451d4

File tree

27 files changed

+159
-80
lines changed

27 files changed

+159
-80
lines changed

DEPLOYING.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44

55
You can build your function using our provided builder, which already includes buildpacks and an invoker layer:
66
```
7-
pack build my-function --path . --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
7+
pack build my-function --path . --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=path.function
88
```
9-
Where `my-function` is the name of your runnable function image, later used by Docker.
9+
Where:
10+
* `my-function` is the name of your runnable function image, later used by Docker.
11+
* `path` is the name of the file or package where the function resides.
12+
* `function` is the name of the method or function.
13+
14+
Examples:
15+
* Python: BP_FUNCTION=func.main. `func` is the name of the .py file. main is the `method`.
16+
* Java: BP_FUNCTION=function.Handler. `function` the package. `Handler` is the class that implements Function.
1017

1118
## Local Deployment
1219

buildpacks/java/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ The buildpack will do the following if detection passed:
2323
To get started you'll need to create a directory where your function will be defined.
2424

2525
From within this directory we require a few files to properly detect this as a Java function:
26-
* `func.yaml` (optional): We use this to configure the runtime environment variables. See the [Knative Func CLI docs](https://github.com/knative-sandbox/kn-plugin-func/blob/main/docs/guides/func_yaml.md) for more details.
26+
* `func.yaml` (optional): We use this to configure the runtime environment variables.
27+
This buildpack makes use of `envs` and `options`. The keys `name` and `runtime` are required to maintain compatibility with Knative func cli, but are not used by this buildpack.
28+
See [Knative's func.yaml documentation](https://github.com/knative/func/blob/main/docs/reference/func_yaml.md)
29+
for more `func.yaml` information.
2730
* `pom.xml` or `build.gradle`: These are used by the other Java buildpacks to compile your function.
2831
* Java package in folder `src/main/java/functions`: This is the default location your function will be detected. If you do choose to use another package to store your functions, you will need to define where your function is located with the `BP_FUNCTION` configuration for the buildpack.
2932

buildpacks/python/README.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ The Python Function Buildpack is a Cloud Native Buildpack that provides a Python
44

55
## Behaviour
66
This buildpack will participate if any of the following conditions are met:
7-
* A file with the name `func.yaml` is detected
7+
- The `BP_FUNCTION` environment variable is set.
8+
- A valid `func.yaml` exists in the function directory. See [func.yaml](#func.yaml)
89

910
The buildpack will do the following if detection passed:
1011
* Request for a Python runtime to be installed to a layer marked `build` and `launch`
@@ -37,18 +38,26 @@ From within this directory we require a few files to properly detect this as a P
3738
* You can find more details about the different accepted parameters [below](#fp).
3839
3940
* <a name="func.yaml"></a>`func.yaml` (optional): This is the configuration used to configure your function.
40-
* The python module and function name can be modified here by defining some environment variables in the `envs` section.
41-
```
42-
envs:
43-
- name: MODULE_NAME
44-
value: my_module
45-
- name: FUNCTION_NAME
46-
value: my_func
47-
```
48-
By defining the above, we will look for a `my_module.py` instead of `func.py` which contains a function with the name `my_func`.
41+
42+
The python module and function name can be modified here by defining some environment variables in the `envs` section.
43+
```
44+
name: test
45+
runtime: python
46+
envs:
47+
- name: MODULE_NAME
48+
value: my_module
49+
- name: FUNCTION_NAME
50+
value: my_func
51+
```
52+
By defining the above, we will look for a `my_module.py` instead of `func.py` which contains a function with the name `my_func`.
53+
54+
This buildpack makes use of `envs` and `options`. The keys `name` and `runtime` are required to maintain compatibility with Knative func cli, but are not used by this buildpack.
55+
See [Knative's func.yaml documentation](https://github.com/knative/func/blob/main/docs/reference/func_yaml.md)
56+
for more `func.yaml` information.
4957
5058
**NOTE**: The environment variables here (namely `MODULE_NAME` and `FUNCTION_NAME` will be overriden by the values specified by `BP_FUNCTION`)
5159
60+
5261
* `requirements.txt`: This file is required by the Python dependency. It is used to define your function's dependencies. If you do not have any, you still need to provide an empty file.
5362
5463
## <a name="fp"></a> Accepted Function Parameters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.PHONY: build publish deploy destroy clean
2+
3+
FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:txttopdfjavagradle
4+
5+
FUNCTION := out/image
6+
$(FUNCTION):
7+
@mkdir -p $(@D)
8+
pack build $(FUNCTION_IMAGE) --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=com.example.demo.DemoApplication
9+
printf $(FUNCTION_IMAGE) > $@
10+
11+
build: $(FUNCTION)
12+
13+
publish: $(FUNCTION)
14+
docker push $(shell cat $(FUNCTION))
15+
16+
.INTERMEDIATE: $(CONFIG)
17+
CREDS := ./creds.yaml
18+
CONFIG := out/config.yaml
19+
$(CONFIG): $(FUNCTION) $(CREDS) $(wildcard config/*)
20+
@mkdir -p $(@D)
21+
ytt -f config --data-values-file $(CREDS) -v function_image="$(shell cat $(FUNCTION))" > $@
22+
23+
config: $(CONFIG)
24+
25+
deploy: $(CONFIG) publish
26+
kapp deploy -a demo -f $(CONFIG)
27+
28+
destroy:
29+
kapp delete -a demo
30+
31+
clean:
32+
docker rmi $(FUNCTION_IMAGE)
33+
rm -rf ./out/
34+
35+
docker: $(FUNCTION)
36+
docker run --env-file aws.env --rm -p 8080:8080 -e 8080 --entrypoint function $(FUNCTION_IMAGE)

samples/java/cloudevents/txt-to-pdf-gradle/func.yaml

-3
This file was deleted.

samples/java/cloudevents/txt-to-pdf-maven/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: build publish deploy destroy clean
22

3-
FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:txttopdfjava
3+
FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:txttopdfjavamaven
44

55
FUNCTION := out/image
66
$(FUNCTION):

samples/java/cloudevents/txt-to-pdf-maven/spring-java-fn/func.yaml

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.PHONY: build publish deploy destroy clean
2+
3+
FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:reqresponsejavagradle
4+
5+
FUNCTION := out/image
6+
$(FUNCTION):
7+
@mkdir -p $(@D)
8+
pack build $(FUNCTION_IMAGE) --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=com.vmware.functions.Handler
9+
printf $(FUNCTION_IMAGE) > $@
10+
11+
build: $(FUNCTION)
12+
13+
publish: $(FUNCTION)
14+
docker push $(shell cat $(FUNCTION))
15+
16+
.INTERMEDIATE: $(CONFIG)
17+
CREDS := ./creds.yaml
18+
CONFIG := out/config.yaml
19+
$(CONFIG): $(FUNCTION) $(CREDS) $(wildcard config/*)
20+
@mkdir -p $(@D)
21+
ytt -f config --data-values-file $(CREDS) -v function_image="$(shell cat $(FUNCTION))" > $@
22+
23+
config: $(CONFIG)
24+
25+
deploy: $(CONFIG) publish
26+
kapp deploy -a demo -f $(CONFIG)
27+
28+
destroy:
29+
kapp delete -a demo
30+
31+
clean:
32+
docker rmi $(FUNCTION_IMAGE)
33+
rm -rf ./out/
34+
35+
docker: $(FUNCTION)
36+
docker run --env-file aws.env --rm -p 8080:8080 -e 8080 --entrypoint function $(FUNCTION_IMAGE)

samples/java/http/request-response-gradle/func.yaml

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.PHONY: build publish deploy destroy clean
2+
3+
FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:reqresponsejavamaven
4+
5+
FUNCTION := out/image
6+
$(FUNCTION):
7+
@mkdir -p $(@D)
8+
pack build $(FUNCTION_IMAGE) --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=com.vmware.functions.Handler
9+
printf $(FUNCTION_IMAGE) > $@
10+
11+
build: $(FUNCTION)
12+
13+
publish: $(FUNCTION)
14+
docker push $(shell cat $(FUNCTION))
15+
16+
.INTERMEDIATE: $(CONFIG)
17+
CREDS := ./creds.yaml
18+
CONFIG := out/config.yaml
19+
$(CONFIG): $(FUNCTION) $(CREDS) $(wildcard config/*)
20+
@mkdir -p $(@D)
21+
ytt -f config --data-values-file $(CREDS) -v function_image="$(shell cat $(FUNCTION))" > $@
22+
23+
config: $(CONFIG)
24+
25+
deploy: $(CONFIG) publish
26+
kapp deploy -a demo -f $(CONFIG)
27+
28+
destroy:
29+
kapp delete -a demo
30+
31+
clean:
32+
docker rmi $(FUNCTION_IMAGE)
33+
rm -rf ./out/
34+
35+
docker: $(FUNCTION)
36+
docker run --env-file aws.env --rm -p 8080:8080 -e 8080 --entrypoint function $(FUNCTION_IMAGE)

samples/java/http/request-response-maven/func.yaml

-3
This file was deleted.

samples/python/cloudevents/s3-lambda/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
To deploy this, first create the container with the buildpack cli
22
```
3-
pack build <your_image_name_and_tag> --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
3+
pack build <your_image_name_and_tag> --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=main.main
44
```
55

66
Publish it to your registry:

samples/python/cloudevents/s3-lambda/func.yaml

-2
This file was deleted.

samples/python/cloudevents/sqs-lambda/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The folder `knative-function-encrypter` has the function that will be listening
6464
With docker running, build the image from this folder:
6565

6666
```
67-
pack build encrypter --path PATH/TO/knative-function-encrypter --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
67+
pack build encrypter --path PATH/TO/knative-function-encrypter --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=main.main
6868
```
6969

7070
Tag and push to your registry:

samples/python/cloudevents/sqs-lambda/knative-function-encrypter/func.yaml

-2
This file was deleted.

samples/python/cloudevents/txt-to-pdf/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:txttopdf
55
FUNCTION := out/image
66
$(FUNCTION): app/*
77
@mkdir -p $(@D)
8-
pack build $(FUNCTION_IMAGE) --path ./app/ --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
8+
pack build $(FUNCTION_IMAGE) --path ./app/ --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=main.main
99
printf $(FUNCTION_IMAGE) > $@
1010

1111
build: $(FUNCTION)

samples/python/cloudevents/txt-to-pdf/app/func.yaml

-8
This file was deleted.

samples/python/http/adder/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This example will take two number and add them up only if the requestor is authe
99
## Usage
1010
1. We want to first build the image:
1111
```
12-
pack build adder --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
12+
pack build adder --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=func.main
1313
```
1414
1515
1. After the image is successfully built we can run it in docker.

samples/python/http/adder/func.yaml

-2
This file was deleted.

templates/java/cloudevents-gradle/func.yaml

-3
This file was deleted.

templates/java/cloudevents-maven/func.yaml

-3
This file was deleted.

templates/java/http-gradle/func.yaml

-3
This file was deleted.

templates/java/http-maven/func.yaml

-3
This file was deleted.

templates/python/cloudevents/func.yaml

-8
This file was deleted.

templates/python/http/func.yaml

-8
This file was deleted.

tests/testdata/template_and_smoke/template-ce/Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ template-ce.path := $(abspath $(path))
77
$(eval $(call INCLUDE_FILE, $(ROOT_DIR)/builder))
88

99
template-ce.image := kn-fn-test/template-ce
10-
template-ce.image_paths := $(shell find $(template-ce.path) -mindepth 1 -maxdepth 1 -type l)
11-
$(template-ce.image_paths): $(PACK) $(builder.image.out)
12-
cd $@ && $(PACK) build $(template-ce.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --pull-policy if-not-present --clear-cache
10+
template-ce.java_image_paths := $(shell find $(template-ce.path) -mindepth 1 -maxdepth 1 -type l | grep java-)
11+
template-ce.python_image_paths := $(shell find $(template-ce.path) -mindepth 1 -maxdepth 1 -type l | grep python-)
12+
$(template-ce.java_image_paths): $(PACK) $(builder.image.out)
13+
cd $@ && $(PACK) build $(template-ce.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --env BP_FUNCTION=functions.Handler --pull-policy if-not-present --clear-cache
14+
$(template-ce.python_image_paths): $(PACK) $(builder.image.out)
15+
cd $@ && $(PACK) build $(template-ce.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --env BP_FUNCTION=func.main --pull-policy if-not-present --clear-cache
1316

1417
template-ce.clean := $(addsuffix .clean,$(template-ce.image_paths))
1518
$(template-ce.clean):
1619
-docker rmi -f $(template-ce.image):$(basename $(notdir $@))
1720

1821
.PHONY: template-tests.images
19-
template-tests.images .PHONY: $(template-ce.image_paths)
22+
template-tests.images .PHONY: $(template-ce.java_image_paths) $(template-ce.python_image_paths)
2023
clean .PHONY: $(template-ce.clean)

tests/testdata/template_and_smoke/template-http/Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ template-http.path := $(abspath $(path))
77
$(eval $(call INCLUDE_FILE, $(ROOT_DIR)/builder))
88

99
template-http.image := kn-fn-test/template-http
10-
template-http.image_paths := $(shell find $(template-http.path) -mindepth 1 -maxdepth 1 -type l)
11-
$(template-http.image_paths): $(PACK) $(builder.image.out)
12-
cd $@ && $(PACK) build $(template-http.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --pull-policy if-not-present --clear-cache
10+
template-http.java_image_paths := $(shell find $(template-http.path) -mindepth 1 -maxdepth 1 -type l | grep java-)
11+
template-http.python_image_paths := $(shell find $(template-http.path) -mindepth 1 -maxdepth 1 -type l | grep python-)
12+
$(template-http.java_image_paths): $(PACK) $(builder.image.out)
13+
cd $@ && $(PACK) build $(template-http.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --env BP_FUNCTION=functions.Handler --pull-policy if-not-present --clear-cache
14+
$(template-http.python_image_paths): $(PACK) $(builder.image.out)
15+
cd $@ && $(PACK) build $(template-http.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --env BP_FUNCTION=func.main --pull-policy if-not-present --clear-cache
1316

1417
template-http.clean := $(addsuffix .clean,$(template-http.image_paths))
1518
$(template-http.clean):
1619
-docker rmi -f $(template-http.image):$(basename $(notdir $@))
1720

1821
.PHONY: template-tests.images
19-
template-tests.images .PHONY: $(template-http.image_paths)
22+
template-tests.images .PHONY: $(template-http.java_image_paths) $(template-http.python_image_paths)
2023
clean .PHONY: $(template-http.clean)

0 commit comments

Comments
 (0)