DEV Community

Tracy Chinedu
Tracy Chinedu

Posted on • Edited on

Deploy a Website using Azure CLI and ARM Template

Deploying a website to Azure can be a straightforward process, especially when you leverage the power of Azure CLI and ARM (Azure Resource Manager) templates. This guide will walk you through the steps of deploying a website using these tools, from setting up your environment to deploying your site. Let’s dive in!

Prerequisites

Before we get started, make sure you have the following:

Azure Account: If you don’t have one, sign up for a free Azure account here.
Azure CLI: Install Azure CLI on your machine. You can download it from the official site.
Text Editor: You’ll need a text editor to write your ARM template. Visual Studio Code is a popular choice.

Prepare ARM Template
ARM (Azure Resource Manager) templates are JSON files that define the infrastructure and configuration for your Azure resources.
Here's a simple ARM template to deploy an Azure Web App:

Template.json File:


{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
      {
        "type": "Microsoft.Web/serverfarms",
        "apiVersion": "2021-01-15",
        "name": "[parameters('appServicePlanName')]",
        "location": "[resourceGroup().location]",
        "sku": {
          "name": "F1",
          "tier": "Free",
          "size": "F1",
          "family": "F",
          "capacity": 1
        }
      },
      {
        "type": "Microsoft.Web/sites",
        "apiVersion": "2021-01-15",
        "name": "[parameters('webAppName')]",
        "location": "[resourceGroup().location]",
        "properties": {
          "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
          "siteConfig": {
            "appSettings": [
              {
                "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
                "value": "true"
              }
            ]
          }
        }
      }
    ],
    "parameters": {
      "appServicePlanName": {
        "type": "string"
      },
      "webAppName": {
        "type": "string"
      }
    }
  }

Enter fullscreen mode Exit fullscreen mode

Customize ARM Parameters
Parameters.json file:

`{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appServicePlanName": {
      "value": "TracyServicePlan"
    },
    "webAppName": {
      "value": "ChineduOnyinye78"
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Deploy the ARM Template using Azure CLI:

  • First, make sure you have the Azure CLI installed. You can download it from the Azure CLI installation page.

  • Authenticate to Azure using the CLI:

     az login
    
  • Create a resource group (if you don't already have one):

     az group create --name myResourceGroup --location eastus
    
    • Deploy ARM template
   az deployment group create --resource-group myRG --template-file 
   template.json --parameters parameter.json

Enter fullscreen mode Exit fullscreen mode

Fork Github Repo -
https://github.com/tracyee0/MyPortfolio

Export Webapp to Azure

az webapp deployment source config --name MyTracyPortfolio25  --resource-group myRG --repo-url https://github.com/tracyee0/MyPortfolio --branch master --manual-integration


Enter fullscreen mode Exit fullscreen mode

Configure Your Web App
Navigate to the Azure Portal, go to your Web App's resource page, and configure settings such as custom domains, SSL certificates, or additional settings as needed.

Check Your Website
Open the URL of your web app in a browser. It should display your website as configured.https://mytracyportfolio25.azurewebsites.net/

Image description

Conclusion
Deploying a website using Azure CLI and ARM templates streamlines the process, making it more manageable and repeatable. By following these steps, you’ve not only learned how to deploy a basic website but also gained a foundation for more complex deployments.

Feel free to expand upon this template based on your specific needs and resources. Azure’s flexibility and the power of ARM templates can handle a wide variety of deployment scenarios, so the sky’s the limit!

Happy deploying!

Top comments (0)