As we have seen from my other articles , it is possible to use the FN project with different programming languages using predefined container images, the officially supported languages are:

  • go
  • java
  • Node.js
  • ruby
  • Python
  • C#

you can do it with the runtime directive, for example:

fn init --runtime python test

the command will produce a func.yaml file of this type

1
2
3
4
5
6
7
8
schema_version: 20180708
name: hello
version: 0.0.1
runtime: python
build_image: fnproject/python:3.9-dev
run_image: fnproject/python:3.9
entrypoint: /python/bin/fdk /function/func.py handler
memory: 256

However, in some cases, the predefined images are not sufficient, either for extra language support, extra drivers, or other missing tools.

To solve this problem it is possible to use your own Dockerfile in your own custom environment, we can extend the basic FN image or start from a totally different image.

As a demo, I created this example in the specific the func.yaml file will look like this:

1schema_version: 20180708
2name: customimage
3version: 0.0.1
4runtime: docker
5memory: 256

in this way, FN uses a local Dockerfile saved at the same level to create the function execution environment, from the example the Dockerfile will look like this:

 1FROM fnproject/python:3.9
 2WORKDIR /function
 3ADD requirements.txt /function/
 4
 5RUN pip3 install --target /python/ --no-cache --no-cache-dir -r requirements.txt &&\
 6    rm -fr ~/.cache/pip /tmp* requirements.txt func.yaml Dockerfile .venv &&\
 7    chmod -R o+r /python
 8
 9# install Oracle database client
10RUN microdnf install oracle-instantclient-release-el8 &&\
11    microdnf install oracle-instantclient-basic &&\
12    microdnf clean all
13
14ADD . /function/
15
16RUN chmod -R o+r /function
17
18ENV PYTHONPATH=/function:/python
19
20ENTRYPOINT ["/python/bin/fdk", "/function/func.py", "handler"]

In this Dockerfile we have customized the official Python 3.9 with Oracle’s database client.

It is possible to do local tests without having to distribute the image in the remote repository every time using the specific option –local in the deployment phase

fn deploy --app app --local

by running the FN server locally it will be possible to execute the function code in the same way as on the OCI but locally

Then launch on a separate terminal session the FN server instance:

fn start

and in another the classic invocation command, for example

echo -n '{"name": "Oracle"}' | fn invoke app hello