Mulai cepat: Membuat aplikasi App Service menggunakan templat ARM

Mulai Azure App Service dengan menyebarkan aplikasi ke cloud menggunakan pola dasr Azure Resource Manager (pola dasar ARM) dan Azure CLI di Cloud Shell. Templat Resource Manager adalah file JavaScript Object Notation (JSON) yang menentukan infrastruktur dan konfigurasi untuk proyek Anda. Anda tidak dikenakan biaya untuk menyelesaikan mulai cepat ini karena Anda menggunakan tingkat App Service gratis.

Untuk menyelesaikan mulai cepat ini, Anda memerlukan akun Azure dengan langganan aktif. Jika Anda tidak memiliki akun Azure, Anda dapat membuat akun secara gratis.

Lewati ke akhir

Jika Anda terbiasa menggunakan templat ARM, Anda dapat melompat ke akhir dengan memilih tombol iniButton to deploy the Resource Manager template to Azure.. Tombol ini membuka templat ARM di portal Azure.

Screenshot of the ARM Template in the Azure portal.

Di portal Azure, pilih Buat baru untuk membuat Grup Sumber Daya baru lalu pilih tombol Tinjau + buat untuk menyebarkan aplikasi.

Mulai Azure App Service dengan menyebarkan aplikasi ke cloud menggunakan pola dasr Azure Resource Manager (pola dasar ARM) dan Azure CLI di Cloud Shell. Templat Resource Manager adalah file JavaScript Object Notation (JSON) yang menentukan infrastruktur dan konfigurasi untuk proyek Anda. Anda tidak dikenakan biaya untuk menyelesaikan mulai cepat ini karena Anda menggunakan tingkat App Service gratis.

Untuk menyelesaikan mulai cepat ini, Anda memerlukan akun Azure dengan langganan aktif. Jika Anda tidak memiliki akun Azure, Anda dapat membuat akun secara gratis.

Lewati ke akhir

Jika Anda terbiasa menggunakan templat ARM, Anda dapat melompat ke akhir dengan memilih tombol iniButton to deploy the Resource Manager template to Azure.. Tombol ini membuka templat ARM di portal Azure.

Screenshot of the ARM Template in the Azure portal.

Di portal Azure, pilih Buat baru untuk membuat Grup Sumber Daya baru lalu pilih tombol Tinjau + buat untuk menyebarkan aplikasi.

Mulai Azure App Service dengan menyebarkan aplikasi ke cloud menggunakan pola dasr Azure Resource Manager (pola dasar ARM) dan Azure CLI di Cloud Shell. Templat Resource Manager adalah file JavaScript Object Notation (JSON) yang menentukan infrastruktur dan konfigurasi untuk proyek Anda. Paket premium diperlukan untuk menyebarkan aplikasi kontainer Windows. Lihat halaman harga App Service untuk detail harga.

Lewati ke akhir

Jika Anda terbiasa menggunakan templat ARM, Anda dapat melompat ke akhir dengan memilih tombol iniButton to deploy the Resource Manager template to Azure.. Tombol ini membuka templat ARM di portal Azure.

Screenshot of the ARM Template in the Azure portal.

Di portal Azure, pilih Buat baru untuk membuat Grup Sumber Daya baru lalu pilih tombol Tinjau + buat untuk menyebarkan aplikasi.

Meninjau templat

Templat yang digunakan di mulai cepat ini berasal dari Templat Mulai Cepat Azure. Ini menyebarkan paket App Service dan aplikasi App Service pada Windows. Ia kompatibel dengan aplikasi .NET Core, .NET Framework, PHP, Node.js, dan HTML Statis. Untuk Java, lihat Membuat aplikasi Java.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.25.53.49325",
      "templateHash": "16144177164140676603"
    }
  },
  "parameters": {
    "webAppName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "Web app name."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "sku": {
      "type": "string",
      "defaultValue": "F1",
      "metadata": {
        "description": "The SKU of App Service Plan."
      }
    },
    "language": {
      "type": "string",
      "defaultValue": ".net",
      "allowedValues": [
        ".net",
        "php",
        "node",
        "html"
      ],
      "metadata": {
        "description": "The language stack of the app."
      }
    },
    "helloWorld": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "true = deploy a sample Hello World app."
      }
    },
    "repoUrl": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Optional Git Repo URL"
      }
    }
  },
  "variables": {
    "appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]",
    "gitRepoReference": {
      ".net": "https://github.com/Azure-Samples/app-service-web-dotnet-get-started",
      "node": "https://github.com/Azure-Samples/nodejs-docs-hello-world",
      "php": "https://github.com/Azure-Samples/php-docs-hello-world",
      "html": "https://github.com/Azure-Samples/html-docs-hello-world"
    },
    "gitRepoUrl": "[if(bool(parameters('helloWorld')), variables('gitRepoReference')[toLower(parameters('language'))], parameters('repoUrl'))]",
    "configReference": {
      ".net": {
        "comments": ".Net app. No additional configuration needed."
      },
      "html": {
        "comments": "HTML app. No additional configuration needed."
      },
      "php": {
        "phpVersion": "7.4"
      },
      "node": {
        "appSettings": [
          {
            "name": "WEBSITE_NODE_DEFAULT_VERSION",
            "value": "12.15.0"
          }
        ]
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2023-01-01",
      "name": "[variables('appServicePlanPortalName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('sku')]"
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2023-01-01",
      "name": "[parameters('webAppName')]",
      "location": "[parameters('location')]",
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "siteConfig": "[variables('configReference')[parameters('language')]]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
        "httpsOnly": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
      ]
    },
    {
      "condition": "[contains(variables('gitRepoUrl'), 'http')]",
      "type": "Microsoft.Web/sites/sourcecontrols",
      "apiVersion": "2023-01-01",
      "name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
      "properties": {
        "repoUrl": "[variables('gitRepoUrl')]",
        "branch": "master",
        "isManualIntegration": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
      ]
    }
  ]
}

Dua sumber daya Azure yang ditentukan dalam templat:

Templat ini berisi beberapa parameter yang telah ditentukan sebelumnya untuk kenyamanan Anda. Lihat tabel untuk default parameter dan deskripsinya:

Parameter Jenis Nilai default Deskripsi
webAppName string webApp-<uniqueString> Nama aplikasi berdasarkan nilai string unik
appServicePlanName string webAppPlan-<uniqueString> Nama Paket App Service berdasarkan nilai string unik
lokasi string [resourceGroup().location] Wilayah aplikasi
sku string F1 Ukuran instans (F1 = Free Tier)
bahasa string .NET Tumpukan bahasa pemrograman (.NET, php, node, html)
helloWorld Boolean False Benar = Sebarkan aplikasi "Hello World"
repoUrl string Repo Git eksternal (opsional)

Templat yang digunakan di mulai cepat ini berasal dari Templat Mulai Cepat Azure. Ia menyebarkan paket App Service dan aplikasi App Service pada Linux. Ia kompatibel dengan semua bahasa pemrograman yang didukung pada App Service.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "10602523904429381366"
    }
  },
  "parameters": {
    "webAppName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "Web app name."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "sku": {
      "type": "string",
      "defaultValue": "F1",
      "metadata": {
        "description": "The SKU of App Service Plan."
      }
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "DOTNETCORE|3.0",
      "metadata": {
        "description": "The Runtime stack of current web app"
      }
    },
    "repoUrl": {
      "type": "string",
      "defaultValue": " ",
      "metadata": {
        "description": "Optional Git Repo URL"
      }
    }
  },
  "variables": {
    "appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('appServicePlanPortalName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('sku')]"
      },
      "kind": "linux",
      "properties": {
        "reserved": true
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2021-02-01",
      "name": "[parameters('webAppName')]",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]",
          "minTlsVersion": "1.2",
          "ftpsState": "FtpsOnly"
        }
      },
      "identity": {
        "type": "SystemAssigned"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
      ]
    },
    {
      "condition": "[contains(parameters('repoUrl'), 'http')]",
      "type": "Microsoft.Web/sites/sourcecontrols",
      "apiVersion": "2021-02-01",
      "name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
      "properties": {
        "repoUrl": "[parameters('repoUrl')]",
        "branch": "master",
        "isManualIntegration": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
      ]
    }
  ]
}

Dua sumber daya Azure yang ditentukan dalam templat:

Templat ini berisi beberapa parameter yang telah ditentukan sebelumnya untuk kenyamanan Anda. Lihat tabel untuk default parameter dan deskripsinya:

Parameter Jenis Nilai default Deskripsi
webAppName string webApp-<uniqueString> Nama aplikasi berdasarkan nilai string unik
appServicePlanName string webAppPlan-<uniqueString> Nama Paket App Service berdasarkan nilai string unik
lokasi string [resourceGroup().location] Wilayah aplikasi
sku string F1 Ukuran instans (F1 = Free Tier)
linuxFxVersion string DOTNETCORE|3.0 "Tumpukan bahasa pemrograman | Versi"
repoUrl string Repo Git eksternal (opsional)

Templat yang digunakan di mulai cepat ini berasal dari Templat Mulai Cepat Azure. Ini menyebarkan paket App Service dan aplikasi App Service pada kontainer Windows.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.25.53.49325",
      "templateHash": "10193476814580854111"
    }
  },
  "parameters": {
    "appServiceWebAppName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "Web App name."
      }
    },
    "appServicePlanName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "App Service Plan name."
      }
    },
    "skuTier": {
      "type": "string",
      "defaultValue": "P1v3"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2023-01-01",
      "name": "[parameters('appServiceWebAppName')]",
      "location": "[parameters('location')]",
      "tags": {
        "[format('hidden-related:{0}', resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName')))]": "empty"
      },
      "properties": {
        "siteConfig": {
          "appSettings": [
            {
              "name": "PORT",
              "value": "8080"
            }
          ],
          "appCommandLine": "",
          "windowsFxVersion": "DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp"
        },
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
      ]
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2023-01-01",
      "name": "[parameters('appServicePlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('skuTier')]"
      },
      "kind": "windows",
      "properties": {
        "hyperV": true
      }
    }
  ]
}

Dua sumber daya Azure yang ditentukan dalam templat:

Templat ini berisi beberapa parameter yang telah ditentukan sebelumnya untuk kenyamanan Anda. Lihat tabel untuk default parameter dan deskripsinya:

Parameter Jenis Nilai default Deskripsi
webAppName string webApp-<uniqueString> Nama aplikasi berdasarkan nilai string unik
appServicePlanName string webAppPlan-<uniqueString> Nama Paket App Service berdasarkan nilai string unik
lokasi string [resourceGroup().location] Wilayah aplikasi
skuTier string P1v3 Ukuran instans (Lihat SKU yang tersedia)
appSettings string [{"name": "PORT","value": "8080"}] Port mendengarkan App Service. Harus 8080.
jenis string windows Sistem Operasi
hyperv string true Mode isolasi
windowsFxVersion string DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp Gambar kontainer

Menyebarkan templat

Azure CLI digunakan di sini untuk menyebarkan templat. Anda juga dapat menggunakan Azure PowerShell, Azure CLI, dan REST API. Untuk mempelajari metode penyebaran lainnya, lihat Menyebarkan templat.

Kode berikut membuat grup sumber daya, paket App Service, dan aplikasi web. Grup sumber daya default, paket App Service, dan lokasi telah ditetapkan untuk Anda. Ganti <app-name> dengan nama aplikasi yang unik secara global (karakter yang valid adalah a-z, 0-9, dan -).

Jalankan perintah berikut untuk menyebarkan aplikasi .NET framework di Windows.

az group create --name myResourceGroup --location "southcentralus"

az deployment group create --resource-group myResourceGroup \
--parameters language=".NET" helloWorld="true" webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows/azuredeploy.json"

Jalankan perintah berikut untuk membuat aplikasi Python di Linux:

az group create --name myResourceGroup --location "southcentralus"

az deployment group create --resource-group myResourceGroup --parameters webAppName="<app-name>" linuxFxVersion="PYTHON|3.9" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-linux/azuredeploy.json"

Untuk menyebarkan tumpukan bahasa yang berbeda, perbarui linuxFxVersion dengan nilai yang sesuai. Sampel ditampilkan dalam tabel. Untuk menampilkan versi saat ini, jalankan perintah berikut ini di Cloud Shell: az webapp config show --resource-group myResourceGroup --name <app-name> --query linuxFxVersion

Bahasa Contoh
.NET linuxFxVersion="DOTNETCORE|3.0"
PHP linuxFxVersion="PHP|7.4"
Node.js linuxFxVersion="NODE|10.15"
Java linuxFxVersion="JAVA|1.8 |TOMCAT|9.0"
Python linuxFxVersion="PYTHON|3.7"

Jalankan perintah berikut untuk menyebarkan aplikasi .NET pada kontainer Windows.

az group create --name myResourceGroup --location "southcentralus"

az deployment group create --resource-group myResourceGroup \
--parameters webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows-container/azuredeploy.json"

Catatan

Anda dapat menemukan lebih banyak sampel templat Azure App Service di sini.

Memvalidasi penyebaran

Telusuri http://<app_name>.azurewebsites.net/ ke dan verifikasi bahwa ini telah dibuat.

Screenshot of the Windows code experience.

Screenshot of the Linux experience.

Screenshot of the Windows container experience.

Membersihkan sumber daya

Saat tidak lagi diperlukan, hapus grup sumber daya.

Langkah berikutnya