I'm working with Fn Project as part of Oracle Cloud Functions and I'm looking to include some helper functions that I wrote myself that are currently used in a few other programs. I'd like to include these functions without having to copy and paste them into my source code, and I feel like there's a way to do this that I haven't managed to find.
Here is what my directory structure looks like. Names have been changed to make it easier to understand.
- helper
- foo.py
- other
- example.py
- functions
- myfunc
- func.py
- func.yaml
- requirements.txt
Currently, in example.py
I have the following:
from helper import foo
...
foo.bar()
When I write func.py I write the same thing but when I run fn deploy -app test_app
and then fn invoke test_app myfunc
it errors out on the import statement (I ran the basic hello world function with from helper import foo
at the top:
Error invoking function. status: 502 message: function failed
My first instinct was to put helper
in the requirements.txt file but that only works with pip
packages. How do I ensure that my own code is included?
Any help would be much appreciated!
Update
So far my only solution has been to literally copy and paste my code into the source file, which is not very maintainable.
Once you do
from helper import foo
insidefunc.py
, the entire code including the library import will be done infunc.py
. Using the commandpip freeze > requirements.txt
in your main directory, you can list all the dependent libraries of your project inside therequirements.txt
. Hence when you create the docker image it will install everything fromrequirements.txt
.