Skip to content

Commit

Permalink
add sample, update resource links
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroe committed Jul 24, 2024
1 parent 3f0607d commit 0d21c56
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 3 deletions.
1 change: 1 addition & 0 deletions docker/AzureFunctionsBaseImage.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,34 @@ 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
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
1 change: 1 addition & 0 deletions docker/samples/AzureFunctions/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local.settings.json
48 changes: 48 additions & 0 deletions docker/samples/AzureFunctions/.gitignore
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions docker/samples/AzureFunctions/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
6 changes: 6 additions & 0 deletions docker/samples/AzureFunctions/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions docker/samples/AzureFunctions/function_app.py
Original file line number Diff line number Diff line change
@@ -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__}!")
16 changes: 16 additions & 0 deletions docker/samples/AzureFunctions/host.json
Original file line number Diff line number Diff line change
@@ -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)"
}
}

0 comments on commit 0d21c56

Please sign in to comment.