It looks like you're trying to figure out a clean way to share code between multiple Azure Function Apps without all the hassle of deploying duplicate files or using symlinks. Here are a couple of strategies you can consider:
Monorepo Structure: Instead of separate directories for each function app, you could structure your project as a monorepo where both function apps and shared code coexist. You would then create a deployment package that includes both function apps and the shared code directory. This way, everything is part of the same project, and you can deploy it all at once.
Using Zip Deployment with Shared Code: As mentioned in the relevant documentation, you can create a zip package that encapsulates your entire project, including the shared code. When you deploy using the Azure CLI with the --build-remote
flag, it might help in correctly deploying the structure you need. Your zip file would look something like this:
workspace.zip/
|-- func_app_one/
| |-- __init__.py
| |-- function.json
| |-- your_function_file.py
|-- func_app_two/
| |-- __init__.py
| |-- function.json
| |-- your_other_function_file.py
|-- shared_code/
| |-- __init__.py
| |-- shared_util.py
Packaging as a Library: If the shared code is significant and reused frequently, consider packaging it as a Python module. You can install it via pip from a private PyPi server or even directly from a GitHub repo. This way, your function apps can have a clean import statement like from shared_code import my_function
.
Use Azure Storage for Shared Code: Another approach is to store the shared code in Azure Blob Storage and download it into each function app at runtime. You'd have to handle the downloading and importing logic but it could keep your directory clean.
Deploy with Azure Functions CI/CD: Utilize CI/CD pipelines to build and package your application for each function app while ensuring that the shared code is included as well.
Hope this gives you some useful ideas!