From 0d21c560885a94a5ab5a8eb812e6b856e27f98d4 Mon Sep 17 00:00:00 2001 From: Jay Roebuck Date: Wed, 24 Jul 2024 12:37:40 -0400 Subject: [PATCH] add sample, update resource links --- docker/AzureFunctionsBaseImage.Dockerfile | 1 + docker/README.md | 15 ++++-- docker/samples/AzureFunctions/.dockerignore | 1 + docker/samples/AzureFunctions/.gitignore | 48 +++++++++++++++++++ .../AzureFunctions/.vscode/extensions.json | 5 ++ docker/samples/AzureFunctions/Dockerfile | 6 +++ docker/samples/AzureFunctions/function_app.py | 14 ++++++ docker/samples/AzureFunctions/host.json | 16 +++++++ 8 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 docker/samples/AzureFunctions/.dockerignore create mode 100644 docker/samples/AzureFunctions/.gitignore create mode 100644 docker/samples/AzureFunctions/.vscode/extensions.json create mode 100644 docker/samples/AzureFunctions/Dockerfile create mode 100644 docker/samples/AzureFunctions/function_app.py create mode 100644 docker/samples/AzureFunctions/host.json diff --git a/docker/AzureFunctionsBaseImage.Dockerfile b/docker/AzureFunctionsBaseImage.Dockerfile index 0fa8f3680..4c7933090 100644 --- a/docker/AzureFunctionsBaseImage.Dockerfile +++ b/docker/AzureFunctionsBaseImage.Dockerfile @@ -10,6 +10,7 @@ LABEL org.opencontainers.image.source=https://github.com/esri/arcgis-python-api # install dependencies, then clean yum cache RUN apt-get update && apt-get install -y gcc libkrb5-dev krb5-config krb5-user && apt-get clean && rm -rf /var/lib/apt/lists/* +RUN pip3 install azure-functions && rm -rf /home/.cache/pip # install arcgis ARG arcgis_version="2.3.1" # adding .* ensures the latest patch version is installed diff --git a/docker/README.md b/docker/README.md index e72320133..966bf6ba6 100644 --- a/docker/README.md +++ b/docker/README.md @@ -29,6 +29,8 @@ Push to your _private_ AWS ECR instance, and configure lambda to run from this c #### ghcr.io/esri/arcgis-python-api-azure-functions:latest +[Sample](samples/AzureFunctions) + To use this image, setup your dockerfile like ``` FROM ghcr.io/esri/arcgis-python-api-azure-functions:latest @@ -36,18 +38,25 @@ COPY . /home/site/wwwroot ``` Your copied resources will need to include: -- `function.json`, such as https://github.com/Azure/azure-functions-docker-python-sample/blob/dev/HttpTrigger/function.json -- `main.py`, such as: +- `host.json`, with your appsettings +- `function_app.py`, such as: ``` import arcgis import azure.functions as func +app = func.FunctionApp() + +@app.http_trigger(route='GET /', methods=['get']) def main(req: func.HttpRequest) -> func.HttpResponse: return func.HttpResponse(f"Hello from Azure Functions using ArcGIS API for Python {arcgis.__version__}!") ``` +Push to the container registry of your choice. + For futher information, see: + +- https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#programming-model +- https://learn.microsoft.com/en-us/azure/azure-functions/functions-deploy-container-apps?tabs=acr%2Cbash&pivots=programming-language-python#create-and-test-the-local-functions-project - https://github.com/Azure/azure-functions-python-worker -- https://github.com/Azure/azure-functions-docker-python-sample - https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-custom-container \ No newline at end of file diff --git a/docker/samples/AzureFunctions/.dockerignore b/docker/samples/AzureFunctions/.dockerignore new file mode 100644 index 000000000..1927772bc --- /dev/null +++ b/docker/samples/AzureFunctions/.dockerignore @@ -0,0 +1 @@ +local.settings.json \ No newline at end of file diff --git a/docker/samples/AzureFunctions/.gitignore b/docker/samples/AzureFunctions/.gitignore new file mode 100644 index 000000000..f15ac3fc6 --- /dev/null +++ b/docker/samples/AzureFunctions/.gitignore @@ -0,0 +1,48 @@ +bin +obj +csx +.vs +edge +Publish + +*.user +*.suo +*.cscfg +*.Cache +project.lock.json + +/packages +/TestResults + +/tools/NuGet.exe +/App_Data +/secrets +/data +.secrets +appsettings.json +local.settings.json + +node_modules +dist + +# Local python packages +.python_packages/ + +# Python Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Azurite artifacts +__blobstorage__ +__queuestorage__ +__azurite_db*__.json \ No newline at end of file diff --git a/docker/samples/AzureFunctions/.vscode/extensions.json b/docker/samples/AzureFunctions/.vscode/extensions.json new file mode 100644 index 000000000..dde673dcd --- /dev/null +++ b/docker/samples/AzureFunctions/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} \ No newline at end of file diff --git a/docker/samples/AzureFunctions/Dockerfile b/docker/samples/AzureFunctions/Dockerfile new file mode 100644 index 000000000..1e34ec83a --- /dev/null +++ b/docker/samples/AzureFunctions/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/esri/arcgis-python-api-azure-functions:latest + +ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ + AzureFunctionsJobHost__Logging__Console__IsEnabled=true + +COPY . /home/site/wwwroot \ No newline at end of file diff --git a/docker/samples/AzureFunctions/function_app.py b/docker/samples/AzureFunctions/function_app.py new file mode 100644 index 000000000..856306ea7 --- /dev/null +++ b/docker/samples/AzureFunctions/function_app.py @@ -0,0 +1,14 @@ +# templated from `func init --worker-runtime python --docker` +# see https://learn.microsoft.com/en-us/azure/azure-functions/functions-deploy-container-apps?tabs=acr%2Cbash&pivots=programming-language-python#create-and-test-the-local-functions-project +# and https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#programming-model +import arcgis +import azure.functions as func + +# NOTE: this is anonymous for sample/testing only, +# configure your authentication properly for production +app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) + +@app.function_name('HttpTrigger1') +@app.route(route='hello') +def main(req: func.HttpRequest) -> func.HttpResponse: + return func.HttpResponse(f"Hello from Azure Functions using ArcGIS API for Python {arcgis.__version__}!") \ No newline at end of file diff --git a/docker/samples/AzureFunctions/host.json b/docker/samples/AzureFunctions/host.json new file mode 100644 index 000000000..e0991851b --- /dev/null +++ b/docker/samples/AzureFunctions/host.json @@ -0,0 +1,16 @@ +{ + "FUNCTIONS_WORKER_RUNTIME": "python", + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[4.*, 5.0.0)" + } +} \ No newline at end of file