Python function deployment using ARM template from a GitHub repo fails

Diana Annie Jenosh 0 Reputation points
2023-04-04T18:19:10.2466667+00:00

Hi, I have been trying to automate the creation of a Function App and deploy python code to a function belonging to the app. Creation of the function App is seamless, however, I tried multiple combinations but I am not able to get the python code in a Github repo deploy to the function. As the intention is to give users a one click deploy option, I chose the ARM and Github option. But, I am not sure if it works fine for Python on linux hosting app as I dint see any direct examples. I found that REST API and zip file based deployment can be options. Can you please confirm if a python function deployment is possible using GitHub repo based approach based on "Microsoft.Web/sites/sourcecontrols" ?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,679 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 19,646 Reputation points Microsoft Employee
    2023-04-05T10:37:38.12+00:00

    @Diana Annie Jenosh Thank you for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this. Yes, using Microsoft.Web/sites/sourcecontrols type in your ARM template you can connect the function app to specific GitHub repo and deploy the function code accordingly. To test this, I have created a sample ARM template which will deploy the function app (runtime python on Linux App service Plan) and also it will deploy the source code of function from the connected GitHub repo. Here is the ARM template:

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "storageAccountName":{
                "type": "string"
                
            },
            "serverFarmeName": {
                "type": "string"
               
            },
            "applicationInsightsName": {
                "type": "string"
               
            },
            "functionAppName":{
                "type" : "string"
            }
        },
        "functions": [],
        "variables": {},
        "resources": [
        {
            "type" : "Microsoft.Storage/storageAccounts",
            "apiVersion": "2021-08-01",
            "name":"[parameters('storageAccountName')]",
            "kind": "Storage",
            "location":"[resourceGroup().location]",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            }
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2021-03-01",
            "location":"[resourceGroup().location]",
            "name":"[parameters('serverFarmeName')]",
            "sku": {
                "name": "P1v2",
                "tier": "PremiumV2",
                "size": "P1v2",
                "family":"Pv2",
                "capacity": 1
            },
            "properties": {
                "hyperV": false,
                "isXenon": false,
                "reserved": true
            }
            
        },
        {
            "type": "Microsoft.Insights/components",
            "apiVersion": "2020-02-02-preview",
            "name":"[parameters('applicationInsightsName')]",
            "location":"[resourceGroup().location]",
            "properties": {
                "Application_Type": "web",
                "DisableIpMasking": true
            }
        },
        {
            "name": "[parameters('functionAppName')]",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2021-03-01",
            "location": "[resourceGroup().location]",
            "kind": "functionapp",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
                "[resourceId('Microsoft.Insights/components', parameters('applicationInsightsName'))]"
            ],
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('serverFarmeName'))]",
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~4"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId('Microsoft.Insights/components',parameters('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
                        },
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "python"
                        },
                        {
                            "name":"APPLICATIONINSIGHTS_CONNECTION_STRING",
                            "value":"[reference(resourceId('Microsoft.Insights/components',parameters('applicationInsightsName')),'2015-05-01').ConnectionString]"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "~18"
                        },
                    ],
                    "linuxFxVersion": "PYTHON|3.9",
                    "alwaysOn": true,
                    "use32BitWorkerProcess": true
                }
            },
            "resources" :[
                {
                    "type": "sourcecontrols",
                    "apiVersion": "2022-09-01",
                    "name":"web",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
                    ],
                    "properties": {
                        "branch":"master", 
                        "repoUrl": "<Pass_the_required_githubURl>", 
                        "isManualIntegration": true
                    }
                }
            ]
        }
        ],
        "outputs": {}
    }
    

    Note : Please do Update the branch name, and GitHub repo URL in source controls block in the above ARM template. We have tested this, and it is working fine from our end. I would suggest you check from your end as well. Feel free to reach back to me if you have any further questions on this.

    0 comments No comments