Skip to content

App Service

Create an App Service and deploy with source code

Prerequisite

  • Create an Azure Account
  • Setup Azure CLI
  • Log in with Azure CLI
  • Create a resource group.
  • To learn these steps, please check Azure CLI content.

Create an App Service plan

  • Command:
    Terminal window
    $ az appservice plan create \
    --name <APP_SERVICE_PLAN_NAME> \
    --resource-group <RESOURCE_GROUP_NAME> \
    --location <LOCATION> \
    --is-linux \
    --sku <SKU>
  • To list all existing service plans, use az appservice plan list --output table.
  • To list all locations, use az account list-locations --output table.
  • SKU value are B1, B2, B3, D1, F1, FREE, I1, I1v2, I2, I2v2, I3, I3v2, P1V2, P1V3, P2V2, P2V3, P3V2, P3V3, PC2, PC3, PC4, S1, S2, S3, SHARED.
    • Free SKU is for free pricing tier.
    • B1 SKU is for the cheapest pricing tier for Linux OS.
  • More details for App Service plan
  • Example code to create an app service plan with free pricing tier:
    Terminal window
    $ az appservice plan create \
    --name codesanook-example-app-service-plan \
    --resource-group codesanook-example-resource-group \
    --location southeastasia \
    --is-linux \
    --sku FREE
  • Example code to create an app service plan with the cheapest pricing tier:
    Terminal window
    $ az appservice plan create \
    --name codesanook-example-app-service-plan \
    --resource-group codesanook-example-resource-group \
    --location southeastasia \
    --is-linux \
    --sku B1

Create an App Service for deploying with source code

  • Command:
    Terminal window
    $ az webapp create \
    --name <APP_SERVICE_NAME> \
    --plan <APP_SERVICE_PLAN_NAME> \
    --resource-group <RESOURCE_GROUP_NAME> \
    --runtime <RUNTIME>
  • Access a website as https://APP_SERVICE_NAME.azurewebsites.net.
  • To list all existing App Service, use az webapp list --output table.
  • To list all supported runtime, use az webapp list-runtimes.
  • Note, you need to wrap double quote to a runtime value.
  • After your App Service is ready, it will deploy your source code from a Git server. You can log in to Azure portable to check deployment status.
  • More details for App Service
  • Example code to create an empty app service that we will deploy with GitHub Actions:
    Terminal window
    $ az webapp create \
    --name codesanook-example-app-service \
    --plan codesanook-example-app-service-plan \
    --resource-group codesanook-example-resource-group \
    --runtime "DOTNETCORE:8.0"

Deploy a project with GitHub Actions

  • You can use our GitHub Actions workflow script to deploy your project to Azure App Service that you’ve just created.
  • To deploy with GitHub Actions, you need to have Azure App Service publish profile.
  • Before getting App Service profile you need to WEBSITE_WEBDEPLOY_USE_SCM configuration’s value to true

Update Azure App Service configuration

  • Command:
    Terminal window
    $ az webapp config appsettings set \
    --name <APP_SERVICE_NAME> \
    --resource-group <RESOURCE_GROUP_NAME> \
    --settings @<CONFIGURATION_JSON_FILE>
  • Example code to update Azure App Service configuration:
    Terminal window
    $ az webapp config appsettings set \
    --name codesanook-example-app-service \
    --resource-group codesanook-example-resource-group \
    --settings @app-service-configuration.json
  • Example content of a configuration JSON file:
    app-service-configuration.json
    [
    {
    "name": "WEBSITE_WEBDEPLOY_USE_SCM",
    "value": "true",
    "slotSetting": false
    }
    ]

Get Azure App Service publish profile

  • Command:

    Terminal window
    $ az webapp deployment list-publishing-profiles \
    --name <APP_SERVICE_NAME> \
    --resource-group <RESOURCE_GROUP_NAME> \
    --xml
  • Example code to get Azure App Service publish profile:

    Terminal window
    $ az webapp deployment list-publishing-profiles \
    --name codesanook-example-app-service \
    --resource-group codesanook-example-resource-group \
    --xml
  • After you have App Service publish profile, you can use it in our custom GitHub workflow to deploy App Service with source code.

  • Deploy .NET app to Azure App Service code

Get FTPS Credentials

  • Go to Azure portal.
  • Select your app service.
  • In app service page that you have selected, select Deployment Center. Then click FTPS credentials tab.
  • You will find all required information to make an FTPS connection.
    • FTPS endpoint
    • Username
    • Password

Other useful commands

Delete an existing Azure App Service

  • Command:
    Terminal window
    $ az webapp delete \
    --name <APP_SERVICE_NAME> \
    --resource-group <RESOURCE_GROUP_NAME>
  • Example code to delete an existing App Service:
    Terminal window
    $ az webapp delete \
    --name codesanook-example-app-service \
    --resource-group codesanook-example-resource-group

Create for a container

Terminal window
az webapp create \
--name md-burner \
--plan codesanook-example-app-service-plan \
--resource-group codesaook-example-group \
--deployment-container-image-name mcr.microsoft.com/dotnet/samples:aspnetapp \
--debug

Useful resources

Add a custom domain

  • Command:
Terminal window
az webapp config hostname add \
--webapp-name <app-name> \
--resource-group <resource_group_name> \
--hostname <fully_qualified_domain_name>
  • Example code to create a custom domain
Terminal window
az webapp config hostname add \
--webapp-name codesanook-example-app-service \
--resource-group codesanook-example-resource-group \
--hostname www.codesanook-example.com

Delete a custom domain

  • Command:
Terminal window
az webapp config hostname delete \
--webapp-name <app-name> \
--resource-group <resource_group_name> \
--hostname <fully_qualified_domain_name>
  • Example code to create a custom domain
Terminal window
az webapp config hostname delete \
--webapp-name codesanook-example-app-service \
--resource-group codesanook-example-resource-group \
--hostname www.codesanook-example.com

ref https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-custom-domain?tabs=root%2Cazurecli

  • Get verification ID
Terminal window
# add extension to Azure CLI
az extension add --name resource-graph
# Run query
az graph query -q "Resources | project name, properties.customDomainVerificationId, type | where type == 'microsoft.web/sites'"
query="Resources"
query+=" | project name, properties.customDomainVerificationId, type"
query+=" | where type == 'microsoft.web/sites'"
az graph query -q "$query"

Building on SupriyaGangineni’s reply…

The domain verification id is the same for all app services on the same subscription. the following query gives you a list of all subscriptions you have access to.

Terminal window
az graph query -q "Resources | join kind=leftouter (ResourceContainers | where type=='microsoft.resources/subscriptions' | project SubName=name, subscriptionId) on subscriptionId | where type == 'microsoft.web/sites'| project vid = tostring(properties.customDomainVerificationId), SubName | distinct *"