diff --git a/.github/workflows/DockerBuild.AzureFunctionsBaseImage.yaml b/.github/workflows/DockerBuild.AzureFunctionsBaseImage.yaml new file mode 100644 index 0000000000..81bcc73c73 --- /dev/null +++ b/.github/workflows/DockerBuild.AzureFunctionsBaseImage.yaml @@ -0,0 +1,69 @@ +name: DockerBuild.AzureFunctionsImage + +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 \ No newline at end of file diff --git a/docker/AzureFunctionsBaseImage.Dockerfile b/docker/AzureFunctionsBaseImage.Dockerfile new file mode 100644 index 0000000000..0fa8f36807 --- /dev/null +++ b/docker/AzureFunctionsBaseImage.Dockerfile @@ -0,0 +1,16 @@ +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="jroebuck@esri.com" +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/* +# 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 diff --git a/docker/README.md b/docker/README.md index 4d1807a7aa..e723201339 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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} ``` @@ -24,3 +24,30 @@ 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 + +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: + +``` +import arcgis +import azure.functions as func + +def main(req: func.HttpRequest) -> func.HttpResponse: + return func.HttpResponse(f"Hello from Azure Functions using ArcGIS API for Python {arcgis.__version__}!") +``` + +For futher information, see: +- 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