Replies: 3 comments 3 replies
-
@calleo you should be able to use a From what I can tell you need to ensure just 3 things:
|
Beta Was this translation helpful? Give feedback.
-
Thank you @jsirois for that suggestion! I could get it to work using the PEX-binary. Here's how I did it: A Function App is a collection of Functions, which are deployed as a single artifact (zip-file). Each function is a sub-folder of that package, which contains the handler function and the config (function.json). To allow me to deploy multiple function to a single Function App I created one three folders:
You can see how it's done over here: https://github.com/calleo/pants-azure-function-example I don't understand how PEX loads 3rd party dependencies, but it works, even though the zip-file doesn't follow the recommended layout. I was having problems deploying multiple functions at first, but I believe the issue was that my handler functions were in files named This approach will not work when using the V2 programming model, which requires a |
Beta Was this translation helpful? Give feedback.
-
We deploy an azure function with a Docker container, so things are a bit different. It deploys several related functions (a mix of Durable and regular functions).
This is kindof gross, but we're migrating away from Azure functions. target(
name="application",
dependencies=[
FunctionA:FunctionA,
...
]
)
pex_binary(
name="deps",
dependencies=["//:application"],
entrypoint="shim.py",
layout="packed",
include_sources=False,
include_requirements=True,
include_tools=True,
)
pex_binary(
name="srcs",
dependencies=["//:application"],
entrypoint="shim.py",
layout="packed",
include_sources=True,
include_requirements=False,
include_tools=True,
)
docker_image(
name="docker0",
dependencies=["://srcs", "://deps"],
) The dockerfile needs to do some shuffling: FROM mcr.microsoft.com/azure-functions/python:4-python3.10-buildenv as deps
WORKDIR /home/site/wwwroot/
COPY ./deps.pex deps.pex
RUN PEX_TOOLS=1 /usr/local/bin/python3 deps.pex venv --scope=deps --compile /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/python:4-python3.10-buildenv as srcs
WORKDIR /home/site/wwwroot/
COPY ./srcs.pex srcs.pex
RUN PEX_TOOLS=1 /usr/local/bin/python3 srcs.pex venv --scope=srcs --compile /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/python:4-python3.10-appservice as srcs
COPY --from=deps /home/site/wwwroot/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=srcs /home/site/wwwroot/srcs.pex /home/site/wwwroot
# you might need to copy in the other descriptors like host.json and function.json depending on how you defined dependencies and targets |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am very new to Pants, but I am trying to consolidate a number of repositories of Azure Functions into a single one and use Pants to have a consistent development workflow and package them up before they are deployed.
Azure functions can be deployed in a number of ways using the Azure CLI, but I believe using the "zip deploy" method would suit Pants the best.
In short, any local Python files and config-files (json) are added to the zip and all 3rd part dependencies are installed into a sub-directory. It's a lot like the pex-files, but folder structure is different.
Azure docs: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-configuration#install-local-packages
Another alternative would be to replicate this folder structure (see link below) in the dist folder and let Azure install dependencies from a requirements-file:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#folder-structure
Then deploy from that folder using the Azure CLI.
Perhaps it's possible to combine existing Pants-functionality to build such an archive?
Beta Was this translation helpful? Give feedback.
All reactions