Mulai Cepat: Buat aplikasi App Service menggunakan templat ARM
Memulai Azure App Service dengan menyebarkan aplikasi ke cloud menggunakan templat ARM dan Azure CLI di Cloud Shell. Karena Anda menggunakan tingkat App Service gratis, Anda tidak dikenakan biaya untuk menyelesaikan mulai cepat ini. Template tersebut menggunakan sintaksis deklaratif.
Jika lingkungan Anda memenuhi prasyarat dan Anda sudah terbiasa menggunakan templat ARM, pilih tombol Sebarkan ke Azure. Templat tersebut akan terbuka di portal Microsoft Azure.
1. Menyiapkan lingkungan Anda
Jika Anda tidak memiliki Langganan Azure, buat Akun gratis Azure sebelum memulai.
2. 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.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"type": "string",
"defaultValue": "[concat('webApp-', 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": "[concat('AppServicePlan-', 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": "2020-06-01",
"name": "[variables('appServicePlanPortalName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('sku')]"
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2020-06-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
],
"properties": {
"siteConfig": "[variables('configReference')[parameters('language')]]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
},
"resources": [
{
"condition": "[contains(variables('gitRepoUrl'),'http')]",
"type": "sourcecontrols",
"apiVersion": "2020-06-01",
"name": "web",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
],
"properties": {
"repoUrl": "[variables('gitRepoUrl')]",
"branch": "master",
"isManualIntegration": true
}
}
]
}
]
}
Sumber daya dan parameter apa saja yang ditentukan dalam templat?
Dua sumber daya Azure yang ditentukan dalam templat:
- Microsoft.Web/serverfarms: buat paket App Service.
- Microsoft.Web/sites: buat aplikasi App Service.
Tabel berikut ini merinci parameter default dan deskripsinya:
| Parameter | Jenis | Nilai default | Deskripsi |
|---|---|---|---|
| webAppName | string | "webApp- <uniqueString> " |
Nama aplikasi |
| lokasi | string | "[resourceGroup().location]" | Wilayah aplikasi |
| sku | string | "F1" | Ukuran instans (F1 = Free Tier) |
| bahasa | string | ".net" | Stack bahasa pemrograman (.net, php, node, html) |
| helloWorld | boolean | Salah | Benar = Sebarkan aplikasi "Hello World" |
| 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 Windows.
{
"$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'))]"
]
}
]
}
Templat ini mencakup sumber daya Azure dan parameter yang ditentukan untuk kenyamanan Anda.
Sumber daya dan parameter apa saja yang ditentukan dalam templat?
Dua sumber daya Azure yang ditentukan dalam templat:
- Microsoft.Web/serverfarms: buat paket App Service.
- Microsoft.Web/sites: buat aplikasi App Service.
Tabel berikut ini merinci parameter default dan deskripsinya:
| Parameter | Jenis | Nilai default | Deskripsi |
|---|---|---|---|
| webAppName | string | "webApp- <uniqueString> " |
Nama aplikasi |
| 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) |
3. Menyebarkan templat
Jalankan kode di bawah ini untuk menyebarkan aplikasi .NET framework di Windows menggunakan Azure CLI.
Ganti <app-name> dengan nama yang unik secara global. Untuk mempelajari metode penyebaran lainnya, lihat Menyebarkan templat. Anda dapat menemukan lebih banyak sampel templat Azure App Service di sini.
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 kode di bawah ini untuk membuat aplikasi Python di Linux.
Ganti <nama aplikasi> dengan nama yang unik secara global. Karakter yang valid adalah a-z, 0-9, dan -.
az group create --name myResourceGroup --location "southcentralus" &&
az deployment group create --resource-group myResourceGroup --parameters webAppName="<app-name>" linuxFxVersion="PYTHON|3.7" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-linux/azuredeploy.json"
Apa yang dilakukan oleh kode?
Perintah melakukan berbagai tindakan berikut:
- Membuat grup sumber daya default.
- Membuat paket App Service default.
- Membuat aplikasi App Service dengan nama tertentu.
Bagaimana cara menerapkan tumpukan bahasa yang berbeda?
Untuk menyebarkan tumpukan bahasa yang berbeda, perbaruiparameter bahasa dengan nilai yang sesuai. Untuk Java, lihat Membuat aplikasi Java.| Parameter | Jenis | Nilai default | Deskripsi |
|---|---|---|---|
| bahasa | string | ".net" | Stack bahasa pemrograman (.net, php, node, html) |
Bagaimana cara untuk menggunakan tumpukan bahasa lainnya?
Untuk menyebarkan stack bahasa yang berbeda, perbarui linuxFxVersion dengan nilai yang sesuai. Sampel ditunjukkan di bawah ini. 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" |
| Ruby | linuxFxVersion="RUBY|2.6" |
4. Memvalidasi penyebaran
Telusuri http://<app_name>.azurewebsites.net/ ke dan verifikasi bahwa ini telah dibuat.
5. Membersihkan sumber daya
Saat tidak lagi diperlukan, hapus grup sumber daya.
Langkah berikutnya
- Sebarkan dari Git - lokal ASP.NET Core dengan SQL Database - Python dengan PostgresPHP - dengan MySQL - Sambungkan ke database Azure SQL dengan Java