Skip to content

Commit 5a2ceed

Browse files
authored
Merge pull request #1876 from Esri/jtroe/azure-functions-docker
add Azure Functions dockerfile
2 parents 8800b43 + 0d21c56 commit 5a2ceed

File tree

9 files changed

+213
-1
lines changed

9 files changed

+213
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: DockerBuild.AzureFunctionsImage
2+
3+
on:
4+
# allow it to be run on-demand
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "Version of ArcGIS API for Python to install in the image"
9+
type: string
10+
default: "2.3.1"
11+
python_version:
12+
description: "Python version to base image on"
13+
type: string
14+
default: "3.11"
15+
is_latest_release:
16+
description: "Version of ArcGIS API for Python is Latest current release"
17+
type: boolean
18+
default: false
19+
is_default_supported_python:
20+
description: "Python version is default supported version (i.e. python used by Pro and Enterprise)"
21+
type: boolean
22+
default: false
23+
24+
jobs:
25+
build-and-push:
26+
name: Build Docker image and push to ghcr.io
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Docker Buildx
34+
id: buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: Login to Github Packages
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- name: Docker meta
45+
id: meta
46+
uses: docker/metadata-action@v5
47+
with:
48+
images: |
49+
ghcr.io/esri/arcgis-python-api-azure-functions
50+
tags: |
51+
type=raw,value=${{ inputs.version }}-python${{ inputs.python_version }}
52+
type=raw,value=${{ inputs.version }},enable=${{ inputs.is_default_supported_python && github.ref_name == github.event.repository.default_branch }}
53+
type=raw,value=latest,enable=${{ inputs.is_latest_release && inputs.is_default_supported_python && github.ref_name == github.event.repository.default_branch }}
54+
type=schedule,pattern={{date 'YY.MM'}},enable=${{ inputs.is_latest_release && inputs.is_default_supported_python && github.ref_name == github.event.repository.default_branch }}
55+
56+
- id: docker_build
57+
name: Build image and push to GitHub Container Registry
58+
uses: docker/build-push-action@v6
59+
with:
60+
# relative path to the place where source code with Dockerfile is located
61+
context: .
62+
file: ./docker/AzureFunctionsBaseImage.Dockerfile
63+
build-args: |
64+
python_version=${{ inputs.python_version }}
65+
arcgis_version=${{ inputs.version }}
66+
tags: ${{ steps.meta.outputs.tags }}
67+
provenance: false
68+
platforms: linux/amd64
69+
push: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG python_version=3.11
2+
# azure-functions python image, defaults to python 3.11
3+
FROM mcr.microsoft.com/azure-functions/python:4-python${python_version}
4+
5+
# set metadata
6+
LABEL org.opencontainers.image.authors="[email protected]"
7+
LABEL org.opencontainers.image.description="Azure Functions image with arcgis Python API and its Linux dependencies preinstalled"
8+
LABEL org.opencontainers.image.licenses=Apache
9+
LABEL org.opencontainers.image.source=https://github.com/esri/arcgis-python-api
10+
11+
# install dependencies, then clean yum cache
12+
RUN apt-get update && apt-get install -y gcc libkrb5-dev krb5-config krb5-user && apt-get clean && rm -rf /var/lib/apt/lists/*
13+
RUN pip3 install azure-functions && rm -rf /home/.cache/pip
14+
# install arcgis
15+
ARG arcgis_version="2.3.1"
16+
# adding .* ensures the latest patch version is installed
17+
RUN pip3 install "arcgis==${arcgis_version}.*" && rm -rf /home/.cache/pip

docker/README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Some useful docker images for utilizing the ArcGIS API for Python in your workfl
88

99
To use this image, setup your dockerfile like:
1010
```
11-
FROM ghcr.io/esri/arcgis-python-api-lambda
11+
FROM ghcr.io/esri/arcgis-python-api-lambda:latest
1212
COPY app.py ${LAMBDA_TASK_ROOT}
1313
```
1414

@@ -24,3 +24,39 @@ def handler(event, context):
2424
```
2525

2626
Push to your _private_ AWS ECR instance, and configure lambda to run from this container image. As of this writing, public AWS ECR instances are not supported for lambda.
27+
28+
## AzureFunctionsBaseImage
29+
30+
#### ghcr.io/esri/arcgis-python-api-azure-functions:latest
31+
32+
[Sample](samples/AzureFunctions)
33+
34+
To use this image, setup your dockerfile like
35+
```
36+
FROM ghcr.io/esri/arcgis-python-api-azure-functions:latest
37+
COPY . /home/site/wwwroot
38+
```
39+
40+
Your copied resources will need to include:
41+
- `host.json`, with your appsettings
42+
- `function_app.py`, such as:
43+
44+
```
45+
import arcgis
46+
import azure.functions as func
47+
48+
app = func.FunctionApp()
49+
50+
@app.http_trigger(route='GET /', methods=['get'])
51+
def main(req: func.HttpRequest) -> func.HttpResponse:
52+
return func.HttpResponse(f"Hello from Azure Functions using ArcGIS API for Python {arcgis.__version__}!")
53+
```
54+
55+
Push to the container registry of your choice.
56+
57+
For futher information, see:
58+
59+
- https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#programming-model
60+
- 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
61+
- https://github.com/Azure/azure-functions-python-worker
62+
- https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-custom-container
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local.settings.json
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
bin
2+
obj
3+
csx
4+
.vs
5+
edge
6+
Publish
7+
8+
*.user
9+
*.suo
10+
*.cscfg
11+
*.Cache
12+
project.lock.json
13+
14+
/packages
15+
/TestResults
16+
17+
/tools/NuGet.exe
18+
/App_Data
19+
/secrets
20+
/data
21+
.secrets
22+
appsettings.json
23+
local.settings.json
24+
25+
node_modules
26+
dist
27+
28+
# Local python packages
29+
.python_packages/
30+
31+
# Python Environments
32+
.env
33+
.venv
34+
env/
35+
venv/
36+
ENV/
37+
env.bak/
38+
venv.bak/
39+
40+
# Byte-compiled / optimized / DLL files
41+
__pycache__/
42+
*.py[cod]
43+
*$py.class
44+
45+
# Azurite artifacts
46+
__blobstorage__
47+
__queuestorage__
48+
__azurite_db*__.json
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions"
4+
]
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ghcr.io/esri/arcgis-python-api-azure-functions:latest
2+
3+
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
4+
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
5+
6+
COPY . /home/site/wwwroot
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# templated from `func init --worker-runtime python --docker`
2+
# 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
3+
# and https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#programming-model
4+
import arcgis
5+
import azure.functions as func
6+
7+
# NOTE: this is anonymous for sample/testing only,
8+
# configure your authentication properly for production
9+
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
10+
11+
@app.function_name('HttpTrigger1')
12+
@app.route(route='hello')
13+
def main(req: func.HttpRequest) -> func.HttpResponse:
14+
return func.HttpResponse(f"Hello from Azure Functions using ArcGIS API for Python {arcgis.__version__}!")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"FUNCTIONS_WORKER_RUNTIME": "python",
3+
"version": "2.0",
4+
"logging": {
5+
"applicationInsights": {
6+
"samplingSettings": {
7+
"isEnabled": true,
8+
"excludedTypes": "Request"
9+
}
10+
}
11+
},
12+
"extensionBundle": {
13+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
14+
"version": "[4.*, 5.0.0)"
15+
}
16+
}

0 commit comments

Comments
 (0)