Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.37k stars 4.79k forks source link

[QUERY] How to create azure web app with sitecontainers #46790

Open kaibocai opened 11 hours ago

kaibocai commented 11 hours ago

Library name and version

Azure.ResourceManager.AppService 1.2.0

Query/Question

How to create a azure container linux webapp with sitecontainer.

I don't find a good example how to do that. From Portal I can create such webapp by Image

With arm template I can create it by

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "sites_kcasewebapp01_name": {
            "defaultValue": "kcasewebapp01",
            "type": "String"
        },
        "serverfarms_ASP_kcasestamp01_b493_externalid": {
            "defaultValue": "/subscriptions/b75447b0-caf9-4fde-92ca-ba79a3a32705/resourceGroups/kcasestamp01/providers/Microsoft.Web/serverfarms/ASP-kcasestamp01-b493",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2023-12-01",
            "name": "[parameters('sites_kcasewebapp01_name')]",
            "location": "Australia Central",
            "kind": "app,linux",
            "properties": {
                "enabled": true,
                "hostNameSslStates": [
                    {
                        "name": "[concat(parameters('sites_kcasewebapp01_name'), '.azurewebsites.net')]",
                        "sslState": "Disabled",
                        "hostType": "Standard"
                    },
                    {
                        "name": "[concat(parameters('sites_kcasewebapp01_name'), '.scm.azurewebsites.net')]",
                        "sslState": "Disabled",
                        "hostType": "Repository"
                    }
                ],
                "serverFarmId": "[parameters('serverfarms_ASP_kcasestamp01_b493_externalid')]",
                "reserved": true,
                "isXenon": false,
                "hyperV": false,
                "dnsConfiguration": {},
                "vnetRouteAllEnabled": false,
                "vnetImagePullEnabled": false,
                "vnetContentShareEnabled": false,
                "siteConfig": {
                    "numberOfWorkers": 1,
                    "linuxFxVersion": "sitecontainers",
                    "acrUseManagedIdentityCreds": false,
                    "alwaysOn": true,
                    "http20Enabled": false,
                    "functionAppScaleLimit": 0,
                    "minimumElasticInstanceCount": 0
                },
                "scmSiteAlsoStopped": false,
                "clientAffinityEnabled": false,
                "clientCertEnabled": false,
                "clientCertMode": "Required",
                "hostNamesDisabled": false,
                "vnetBackupRestoreEnabled": false,
                "customDomainVerificationId": "7A49CD600E089AE55BA3948338B75D68B25C95371BC7B020B33E1F25051279D7",
                "containerSize": 0,
                "dailyMemoryTimeQuota": 0,
                "httpsOnly": true,
                "redundancyMode": "None",
                "publicNetworkAccess": "Enabled",
                "storageAccountRequired": false,
                "keyVaultReferenceIdentity": "SystemAssigned"
            }
        },
        {
            "type": "Microsoft.Web/sites/basicPublishingCredentialsPolicies",
            "apiVersion": "2023-12-01",
            "name": "[concat(parameters('sites_kcasewebapp01_name'), '/ftp')]",
            "location": "Australia Central",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('sites_kcasewebapp01_name'))]"
            ],
            "properties": {
                "allow": false
            }
        },
        {
            "type": "Microsoft.Web/sites/basicPublishingCredentialsPolicies",
            "apiVersion": "2023-12-01",
            "name": "[concat(parameters('sites_kcasewebapp01_name'), '/scm')]",
            "location": "Australia Central",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('sites_kcasewebapp01_name'))]"
            ],
            "properties": {
                "allow": false
            }
        },
        {
            "type": "Microsoft.Web/sites/config",
            "apiVersion": "2023-12-01",
            "name": "[concat(parameters('sites_kcasewebapp01_name'), '/web')]",
            "location": "Australia Central",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('sites_kcasewebapp01_name'))]"
            ],
            "properties": {
                "numberOfWorkers": 1,
                "defaultDocuments": [
                    "Default.htm",
                    "Default.html",
                    "Default.asp",
                    "index.htm",
                    "index.html",
                    "iisstart.htm",
                    "default.aspx",
                    "index.php",
                    "hostingstart.html"
                ],
                "netFrameworkVersion": "v4.0",
                "linuxFxVersion": "sitecontainers",
                "requestTracingEnabled": false,
                "remoteDebuggingEnabled": false,
                "httpLoggingEnabled": false,
                "acrUseManagedIdentityCreds": false,
                "logsDirectorySizeLimit": 35,
                "detailedErrorLoggingEnabled": false,
                "publishingUsername": "REDACTED",
                "scmType": "None",
                "use32BitWorkerProcess": true,
                "webSocketsEnabled": false,
                "alwaysOn": true,
                "managedPipelineMode": "Integrated",
                "virtualApplications": [
                    {
                        "virtualPath": "/",
                        "physicalPath": "site\\wwwroot",
                        "preloadEnabled": true
                    }
                ],
                "loadBalancing": "LeastRequests",
                "experiments": {
                    "rampUpRules": []
                },
                "autoHealEnabled": false,
                "vnetRouteAllEnabled": false,
                "vnetPrivatePortsCount": 0,
                "publicNetworkAccess": "Enabled",
                "localMySqlEnabled": false,
                "ipSecurityRestrictions": [
                    {
                        "ipAddress": "Any",
                        "action": "Allow",
                        "priority": 2147483647,
                        "name": "Allow all",
                        "description": "Allow all access"
                    }
                ],
                "scmIpSecurityRestrictions": [
                    {
                        "ipAddress": "Any",
                        "action": "Allow",
                        "priority": 2147483647,
                        "name": "Allow all",
                        "description": "Allow all access"
                    }
                ],
                "scmIpSecurityRestrictionsUseMain": false,
                "http20Enabled": false,
                "minTlsVersion": "1.2",
                "scmMinTlsVersion": "1.2",
                "ftpsState": "FtpsOnly",
                "preWarmedInstanceCount": 0,
                "elasticWebAppScaleLimit": 0,
                "functionsRuntimeScaleMonitoringEnabled": false,
                "minimumElasticInstanceCount": 0,
                "azureStorageAccounts": {}
            }
        },
        {
            "type": "Microsoft.Web/sites/hostNameBindings",
            "apiVersion": "2023-12-01",
            "name": "[concat(parameters('sites_kcasewebapp01_name'), '/', parameters('sites_kcasewebapp01_name'), '.azurewebsites.net')]",
            "location": "Australia Central",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('sites_kcasewebapp01_name'))]"
            ],
            "properties": {
                "siteName": "kcasewebapp01",
                "hostNameType": "Verified"
            }
        },
        {
            "type": "Microsoft.Web/sites/sitecontainers",
            "apiVersion": "2023-12-01",
            "name": "[concat(parameters('sites_kcasewebapp01_name'), '/test-container')]",
            "location": "Australia Central",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('sites_kcasewebapp01_name'))]"
            ],
            "properties": {
                "image": "asetestacr.azurecr.io/samples/nginx:latest",
                "targetPort": "80",
                "isMain": true,
                "authType": "UserCredentials",
                "userName": "asetestacr",
                "volumeMounts": [],
                "environmentVariables": []
            }
        }
    ]
}

But with SDK I didn't figure out how to do it correctly.

Please share me some example for how to creating a linux webapp using container image. Thanks.

Environment

.NET SDK:
 Version:           8.0.403
 Commit:            c64aa40a71
 Workload version:  8.0.400-manifests.e99c892e
 MSBuild version:   17.11.9+a69bbaaf5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.403\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
 [aspire]
   Installation Source: VS 17.11.35327.3
   Manifest Version:    8.1.0/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json
   Install Type:        FileBased

Host:
  Version:      8.0.10
  Architecture: x64
  Commit:       81cabf2857

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.135 [C:\Program Files\dotnet\sdk]
  6.0.321 [C:\Program Files\dotnet\sdk]
  6.0.427 [C:\Program Files\dotnet\sdk]
  7.0.120 [C:\Program Files\dotnet\sdk]
  8.0.306 [C:\Program Files\dotnet\sdk]
  8.0.403 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
berndverst commented 9 hours ago

I think you might have to use the management SDK manually. Azure.ResourceManager.AppService

https://github.com/Azure/azure-sdk-for-net/blob/c166df86a014ca310f38b14245a4f9b66e06e1a5/sdk/websites/Azure.ResourceManager.AppService/src/Generated/SiteContainerResource.cs#L259-L284

https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.appservice.sitecontainerresource.update?view=azure-dotnet

Creates or Updates a site container for a site, or a deployment slot. Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/sitecontainers/{containerName} Operation Id: WebApps_CreateOrUpdateSiteContainer Default Api Version: 2023-12-01 Resource: SiteContainerResource

jsquire commented 8 hours ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.