Webalkalmazás létrehozása és kód üzembe helyezése átmeneti környezetben

Ez a példaszkript egy webalkalmazást hoz létre az App Service-ben egy további, staging nevű üzembehelyezési ponttal együtt, majd egy mintaalkalmazást telepít a staging pontba.

Ha szükséges, telepítse a Azure PowerShell a Azure PowerShell útmutatóban található utasítással, majd futtassa a parancsot Connect-AzAccount az Azure-ral való kapcsolat létrehozásához.

Példaszkript

Megjegyzés

Javasoljuk, hogy az Azure Az PowerShell-modult használja az Azure-ral való kommunikációhoz. Az első lépésekhez tekintse meg az Azure PowerShell telepítését ismertető szakaszt. Az Az PowerShell-modulra történő migrálás részleteiről lásd: Az Azure PowerShell migrálása az AzureRM modulból az Az modulba.

# Replace the following URL with a public GitHub repo URL
$gitrepo="https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"
$webappname="mywebapp$(Get-Random)"
$location="West Europe"

# Create a resource group.
New-AzResourceGroup -Name myResourceGroup -Location $location

# Create an App Service plan in Free tier.
New-AzAppServicePlan -Name $webappname -Location $location `
-ResourceGroupName myResourceGroup -Tier Free

# Create a web app.
New-AzWebApp -Name $webappname -Location $location `
-AppServicePlan $webappname -ResourceGroupName myResourceGroup

# Upgrade App Service plan to Standard tier (minimum required by deployment slots)
Set-AzAppServicePlan -Name $webappname -ResourceGroupName myResourceGroup `
-Tier Standard

#Create a deployment slot with the name "staging".
New-AzWebAppSlot -Name $webappname -ResourceGroupName myResourceGroup `
-Slot staging

# Configure GitHub deployment to the staging slot from your GitHub repo and deploy once.
$PropertiesObject = @{
    repoUrl = "$gitrepo";
    branch = "master";
    isManualIntegration = "true"; #remove isManualIntegration for continuous deployment from a GitHub repo you own
}
Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName myResourceGroup `
-ResourceType Microsoft.Web/sites/slots/sourcecontrols `
-ResourceName $webappname/staging/web -ApiVersion 2015-08-01 -Force

# Swap the verified/warmed up staging slot into production.
Switch-AzWebAppSlot -Name $webappname -ResourceGroupName myResourceGroup `
-SourceSlotName staging -DestinationSlotName production

Az üzemelő példány eltávolítása

A példaszkript futtatása után a következő paranccsal távolítható el az erőforráscsoport, a webalkalmazás és az összes kapcsolódó erőforrás.

Remove-AzResourceGroup -Name myResourceGroup -Force

Szkript ismertetése

A szkript a következő parancsokat használja. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
New-AzResourceGroup Létrehoz egy erőforráscsoportot, amely az összes erőforrást tárolja.
New-AzAppServicePlan Létrehoz egy App Service-csomagot.
New-AzWebApp Webalkalmazást hoz létre.
Set-AzAppServicePlan Egy App Service-csomag tarifacsomagját módosítja.
New-AzWebAppSlot Üzembehelyezési pontot hoz létre egy webalkalmazáshoz.
Set-AzResource Módosít egy erőforrást egy erőforráscsoportban.
Switch-AzWebAppSlot Egy webalkalmazás üzembehelyezési pontját éles környezetbe helyezi át.

Következő lépések

Az Azure PowerShell modullal kapcsolatos további információért lásd az Azure PowerShell dokumentációját.

A Azure App Service Web Apps további Azure PowerShell mintái megtalálhatók a Azure PowerShell mintákban.