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

Chore(tests, docs): Update after Knative func cli updates #147

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions DEPLOYING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@

You can build your function using our provided builder, which already includes buildpacks and an invoker layer:
```
pack build my-function --path . --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
pack build my-function --path . --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=path.function
```
Where `my-function` is the name of your runnable function image, later used by Docker.
Where:
* `my-function` is the name of your runnable function image, later used by Docker.
* `path` is the name of the file or package where the function resides.
* `function` is the name of the method or function.

Examples:
* Python: BP_FUNCTION=func.main. `func` is the name of the .py file. main is the `method`.
* Java: BP_FUNCTION=function.Handler. `function` the package. `Handler` is the class that implements Function.

## Local Deployment

Expand Down
5 changes: 4 additions & 1 deletion buildpacks/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ The buildpack will do the following if detection passed:
To get started you'll need to create a directory where your function will be defined.

From within this directory we require a few files to properly detect this as a Java function:
* `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.
* `func.yaml` (optional): We use this to configure the runtime environment variables.
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.
See [Knative's func.yaml documentation](https://github.com/knative/func/blob/main/docs/reference/func_yaml.md)
for more `func.yaml` information.
* `pom.xml` or `build.gradle`: These are used by the other Java buildpacks to compile your function.
* 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.

Expand Down
29 changes: 19 additions & 10 deletions buildpacks/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ The Python Function Buildpack is a Cloud Native Buildpack that provides a Python

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

The buildpack will do the following if detection passed:
* Request for a Python runtime to be installed to a layer marked `build` and `launch`
Expand Down Expand Up @@ -37,18 +38,26 @@ From within this directory we require a few files to properly detect this as a P
* You can find more details about the different accepted parameters [below](#fp).

* <a name="func.yaml"></a>`func.yaml` (optional): This is the configuration used to configure your function.
* The python module and function name can be modified here by defining some environment variables in the `envs` section.
```
envs:
- name: MODULE_NAME
value: my_module
- name: FUNCTION_NAME
value: my_func
```
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`.

The python module and function name can be modified here by defining some environment variables in the `envs` section.
```
name: test
runtime: python
envs:
- name: MODULE_NAME
value: my_module
- name: FUNCTION_NAME
value: my_func
```
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`.

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.
See [Knative's func.yaml documentation](https://github.com/knative/func/blob/main/docs/reference/func_yaml.md)
for more `func.yaml` information.

**NOTE**: The environment variables here (namely `MODULE_NAME` and `FUNCTION_NAME` will be overriden by the values specified by `BP_FUNCTION`)


* `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.

## <a name="fp"></a> Accepted Function Parameters
Expand Down
36 changes: 36 additions & 0 deletions samples/java/cloudevents/txt-to-pdf-gradle/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: build publish deploy destroy clean

FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:txttopdfjavagradle

FUNCTION := out/image
$(FUNCTION):
@mkdir -p $(@D)
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
printf $(FUNCTION_IMAGE) > $@

build: $(FUNCTION)

publish: $(FUNCTION)
docker push $(shell cat $(FUNCTION))

.INTERMEDIATE: $(CONFIG)
CREDS := ./creds.yaml
CONFIG := out/config.yaml
$(CONFIG): $(FUNCTION) $(CREDS) $(wildcard config/*)
@mkdir -p $(@D)
ytt -f config --data-values-file $(CREDS) -v function_image="$(shell cat $(FUNCTION))" > $@

config: $(CONFIG)

deploy: $(CONFIG) publish
kapp deploy -a demo -f $(CONFIG)

destroy:
kapp delete -a demo

clean:
docker rmi $(FUNCTION_IMAGE)
rm -rf ./out/

docker: $(FUNCTION)
docker run --env-file aws.env --rm -p 8080:8080 -e 8080 --entrypoint function $(FUNCTION_IMAGE)
3 changes: 0 additions & 3 deletions samples/java/cloudevents/txt-to-pdf-gradle/func.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion samples/java/cloudevents/txt-to-pdf-maven/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build publish deploy destroy clean

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

FUNCTION := out/image
$(FUNCTION):
Expand Down

This file was deleted.

36 changes: 36 additions & 0 deletions samples/java/http/request-response-gradle/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: build publish deploy destroy clean

FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:reqresponsejavagradle

FUNCTION := out/image
$(FUNCTION):
@mkdir -p $(@D)
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
printf $(FUNCTION_IMAGE) > $@

build: $(FUNCTION)

publish: $(FUNCTION)
docker push $(shell cat $(FUNCTION))

.INTERMEDIATE: $(CONFIG)
CREDS := ./creds.yaml
CONFIG := out/config.yaml
$(CONFIG): $(FUNCTION) $(CREDS) $(wildcard config/*)
@mkdir -p $(@D)
ytt -f config --data-values-file $(CREDS) -v function_image="$(shell cat $(FUNCTION))" > $@

config: $(CONFIG)

deploy: $(CONFIG) publish
kapp deploy -a demo -f $(CONFIG)

destroy:
kapp delete -a demo

clean:
docker rmi $(FUNCTION_IMAGE)
rm -rf ./out/

docker: $(FUNCTION)
docker run --env-file aws.env --rm -p 8080:8080 -e 8080 --entrypoint function $(FUNCTION_IMAGE)
3 changes: 0 additions & 3 deletions samples/java/http/request-response-gradle/func.yaml

This file was deleted.

36 changes: 36 additions & 0 deletions samples/java/http/request-response-maven/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: build publish deploy destroy clean

FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:reqresponsejavamaven

FUNCTION := out/image
$(FUNCTION):
@mkdir -p $(@D)
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
printf $(FUNCTION_IMAGE) > $@

build: $(FUNCTION)

publish: $(FUNCTION)
docker push $(shell cat $(FUNCTION))

.INTERMEDIATE: $(CONFIG)
CREDS := ./creds.yaml
CONFIG := out/config.yaml
$(CONFIG): $(FUNCTION) $(CREDS) $(wildcard config/*)
@mkdir -p $(@D)
ytt -f config --data-values-file $(CREDS) -v function_image="$(shell cat $(FUNCTION))" > $@

config: $(CONFIG)

deploy: $(CONFIG) publish
kapp deploy -a demo -f $(CONFIG)

destroy:
kapp delete -a demo

clean:
docker rmi $(FUNCTION_IMAGE)
rm -rf ./out/

docker: $(FUNCTION)
docker run --env-file aws.env --rm -p 8080:8080 -e 8080 --entrypoint function $(FUNCTION_IMAGE)
3 changes: 0 additions & 3 deletions samples/java/http/request-response-maven/func.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion samples/python/cloudevents/s3-lambda/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
To deploy this, first create the container with the buildpack cli
```
pack build <your_image_name_and_tag> --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
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
```

Publish it to your registry:
Expand Down
2 changes: 0 additions & 2 deletions samples/python/cloudevents/s3-lambda/func.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion samples/python/cloudevents/sqs-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The folder `knative-function-encrypter` has the function that will be listening
With docker running, build the image from this folder:

```
pack build encrypter --path PATH/TO/knative-function-encrypter --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
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
```

Tag and push to your registry:
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion samples/python/cloudevents/txt-to-pdf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FUNCTION_IMAGE ?= us.gcr.io/daisy-284300/functions/demo:txttopdf
FUNCTION := out/image
$(FUNCTION): app/*
@mkdir -p $(@D)
pack build $(FUNCTION_IMAGE) --path ./app/ --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
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
printf $(FUNCTION_IMAGE) > $@

build: $(FUNCTION)
Expand Down
8 changes: 0 additions & 8 deletions samples/python/cloudevents/txt-to-pdf/app/func.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion samples/python/http/adder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This example will take two number and add them up only if the requestor is authe
## Usage
1. We want to first build the image:
```
pack build adder --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0
pack build adder --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:0.1.0 --env BP_FUNCTION=func.main
```

1. After the image is successfully built we can run it in docker.
Expand Down
2 changes: 0 additions & 2 deletions samples/python/http/adder/func.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions templates/java/cloudevents-gradle/func.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions templates/java/cloudevents-maven/func.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions templates/java/http-gradle/func.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions templates/java/http-maven/func.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions templates/python/cloudevents/func.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions templates/python/http/func.yaml

This file was deleted.

11 changes: 7 additions & 4 deletions tests/testdata/template_and_smoke/template-ce/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ template-ce.path := $(abspath $(path))
$(eval $(call INCLUDE_FILE, $(ROOT_DIR)/builder))

template-ce.image := kn-fn-test/template-ce
template-ce.image_paths := $(shell find $(template-ce.path) -mindepth 1 -maxdepth 1 -type l)
$(template-ce.image_paths): $(PACK) $(builder.image.out)
cd $@ && $(PACK) build $(template-ce.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --pull-policy if-not-present --clear-cache
template-ce.java_image_paths := $(shell find $(template-ce.path) -mindepth 1 -maxdepth 1 -type l | grep java-)
template-ce.python_image_paths := $(shell find $(template-ce.path) -mindepth 1 -maxdepth 1 -type l | grep python-)
$(template-ce.java_image_paths): $(PACK) $(builder.image.out)
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
$(template-ce.python_image_paths): $(PACK) $(builder.image.out)
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

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

.PHONY: template-tests.images
template-tests.images .PHONY: $(template-ce.image_paths)
template-tests.images .PHONY: $(template-ce.java_image_paths) $(template-ce.python_image_paths)
clean .PHONY: $(template-ce.clean)
11 changes: 7 additions & 4 deletions tests/testdata/template_and_smoke/template-http/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ template-http.path := $(abspath $(path))
$(eval $(call INCLUDE_FILE, $(ROOT_DIR)/builder))

template-http.image := kn-fn-test/template-http
template-http.image_paths := $(shell find $(template-http.path) -mindepth 1 -maxdepth 1 -type l)
$(template-http.image_paths): $(PACK) $(builder.image.out)
cd $@ && $(PACK) build $(template-http.image):$(notdir $@) --builder $(shell cat $(builder.image.out)) --pull-policy if-not-present --clear-cache
template-http.java_image_paths := $(shell find $(template-http.path) -mindepth 1 -maxdepth 1 -type l | grep java-)
template-http.python_image_paths := $(shell find $(template-http.path) -mindepth 1 -maxdepth 1 -type l | grep python-)
$(template-http.java_image_paths): $(PACK) $(builder.image.out)
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
$(template-http.python_image_paths): $(PACK) $(builder.image.out)
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

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

.PHONY: template-tests.images
template-tests.images .PHONY: $(template-http.image_paths)
template-tests.images .PHONY: $(template-http.java_image_paths) $(template-http.python_image_paths)
clean .PHONY: $(template-http.clean)