Skip to content

Commit

Permalink
Merge pull request #1892 from jyaistMap/next
Browse files Browse the repository at this point in the history
Synching next with changes in master
  • Loading branch information
jyaistMap committed Aug 9, 2024
2 parents 2bd37df + aa04733 commit e384c90
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 38 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/DockerBuild.AzureFunctionsBaseImage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: DockerBuild.AzureFunctionsImage

permissions:
contents: read
packages: write

on:
# allow it to be run on-demand
workflow_dispatch:
inputs:
version:
description: "Version of ArcGIS API for Python to install in the image"
type: string
default: "2.3.1"
python_version:
description: "Python version to base image on"
type: string
default: "3.11"
is_latest_release:
description: "Version of ArcGIS API for Python is Latest current release"
type: boolean
default: false
is_default_supported_python:
description: "Python version is default supported version (i.e. python used by Pro and Enterprise)"
type: boolean
default: false

jobs:
build-and-push:
name: Build Docker image and push to ghcr.io
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/esri/arcgis-python-api-azure-functions
tags: |
type=raw,value=${{ inputs.version }}-python${{ inputs.python_version }}
type=raw,value=${{ inputs.version }},enable=${{ inputs.is_default_supported_python && github.ref_name == github.event.repository.default_branch }}
type=raw,value=latest,enable=${{ inputs.is_latest_release && inputs.is_default_supported_python && github.ref_name == github.event.repository.default_branch }}
type=schedule,pattern={{date 'YY.MM'}},enable=${{ inputs.is_latest_release && inputs.is_default_supported_python && github.ref_name == github.event.repository.default_branch }}
- id: docker_build
name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v6
with:
# relative path to the place where source code with Dockerfile is located
context: .
file: ./docker/AzureFunctionsBaseImage.Dockerfile
build-args: |
python_version=${{ inputs.python_version }}
arcgis_version=${{ inputs.version }}
tags: ${{ steps.meta.outputs.tags }}
provenance: false
platforms: linux/amd64
push: true
16 changes: 10 additions & 6 deletions .github/workflows/DockerBuild.LambdaBaseImage.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: DockerBuild.LambdaImage

permissions:
contents: read
packages: write

on:
# allow it to be run on-demand
workflow_dispatch:
inputs:
version:
description: "Version of ArcGIS API for Python to install in the image"
type: string
default: "2.3.0"
default: "2.3.1"
python_version:
description: "Python version to base image on"
type: string
Expand All @@ -28,22 +32,22 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Github Packages
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/esri/arcgis-python-api-lambda
Expand All @@ -55,7 +59,7 @@ jobs:
- id: docker_build
name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
# relative path to the place where source code with Dockerfile is located
context: .
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/DockerBuild.NotebookImage.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
name: DockerBuild.NotebookImage

permissions:
contents: read
packages: write

on:
# allow it to be run on-demand
workflow_dispatch:
inputs:
version:
description: "Version of ArcGIS API for Python to install in the image"
type: string
default: "2.2.0"
default: "2.3.1"
python_version:
description: "Python version to base image on"
type: string
default: "3.9"
default: "3.11"
is_latest_release:
description: "Version of ArcGIS API for Python is Latest current release"
type: boolean
Expand All @@ -32,18 +36,18 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Github Packages
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/esri/arcgis-python-api-notebook
Expand All @@ -55,7 +59,7 @@ jobs:
- id: docker_build
name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
# relative path to the place where source code with Dockerfile is located
context: ./docker
Expand Down
17 changes: 17 additions & 0 deletions docker/AzureFunctionsBaseImage.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG python_version=3.11
# azure-functions python image, defaults to python 3.11
FROM mcr.microsoft.com/azure-functions/python:4-python${python_version}

# set metadata
LABEL org.opencontainers.image.authors="[email protected]"
LABEL org.opencontainers.image.description="Azure Functions image with arcgis Python API and its Linux dependencies preinstalled"
LABEL org.opencontainers.image.licenses=Apache
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
RUN pip3 install "arcgis==${arcgis_version}.*" && rm -rf /home/.cache/pip
2 changes: 1 addition & 1 deletion docker/LambdaBaseImage.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LABEL org.opencontainers.image.source=https://github.com/esri/arcgis-python-api
# install dependencies, then clean yum cache
RUN yum -y install gcc gcc-c++ krb5-devel krb5-server krb5-libs && yum clean all && rm -rf /var/cache/yum
# install arcgis
ARG arcgis_version="2.3.0"
ARG arcgis_version="2.3.1"
# adding .* ensures the latest patch version is installed
RUN pip3 install "arcgis==${arcgis_version}.*" --target "${LAMBDA_TASK_ROOT}" && rm -rf /root/.cache/pip
# set entrypoint to app.py handler method
Expand Down
6 changes: 3 additions & 3 deletions docker/NotebookImage.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ARG python_version="3.9"
FROM jupyter/base-notebook:python-${python_version}
ARG python_version="3.11"
FROM quay.io/jupyter/base-notebook:python-${python_version}

ARG python_version
ARG arcgis_version="2.2.0"
ARG arcgis_version="2.3.1"
ARG sampleslink="https://github.com/Esri/arcgis-python-api/releases/download/v${arcgis_version}/samples.zip"
ARG githubfolder="arcgis-python-api"
ENV DOCKER_STACKS_JUPYTER_CMD="notebook"
Expand Down
38 changes: 37 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Some useful docker images for utilizing the ArcGIS API for Python in your workfl

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

Expand All @@ -24,3 +24,39 @@ def handler(event, context):
```

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.

## AzureFunctionsBaseImage

#### 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:
- `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://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)"
}
}
Loading

0 comments on commit e384c90

Please sign in to comment.