MSDN Documentation

Azure App Service Deployment

Deploying Your Application to Azure App Service

Azure App Service is a powerful Platform as a Service (PaaS) offering from Microsoft Azure that enables you to build, deploy, and scale web applications, mobile backends, and APIs. This tutorial will guide you through the process of deploying a sample application to Azure App Service using various methods.

Prerequisites

  • An active Azure subscription. If you don't have one, you can create a free account.
  • A sample application to deploy (e.g., a Node.js, Python, .NET, or Java web app).
  • Azure CLI installed and configured, or access to the Azure portal.

Understanding Azure App Service Components

Before we start deploying, let's briefly touch upon the core components:

  • App Service Plan: Defines the location, size, and features of the web server farm that hosts your app. It determines the compute resources your app runs on.
  • Web App: The actual application instance you deploy.
  • Deployment Slots: Allow you to manage deployed app versions. You can use staging slots for testing before swapping to production.

Deployment Methods

Azure App Service supports several deployment methods. We'll cover a few of the most common ones.

Method 1: Deployment via Azure Portal (Drag and Drop/Zip Deploy)

This is the simplest method for quick deployments or small applications.

1

Create an App Service

Navigate to the Azure portal, search for "App Services", and click "Create". Choose your subscription, resource group, name your app, select a runtime stack (e.g., Node 18 LTS), and choose a region. Select an appropriate App Service plan.

2

Deploy Your Code

Once the App Service is created, navigate to its resource page. Under the "Deployment" section, select "Deployment Center". Here you can choose "Local Git" or "FTP" for manual uploads. Alternatively, go to the "Overview" page, click "Get publish profile", and use this profile with tools like Visual Studio or FTP clients.

For zip deploy: Package your application into a zip file. Then, in the App Service menu, go to "Advanced Tools" -> "Go advanced" -> "_httpPlatformHandler.js" and upload your zip file to the wwwroot folder. Or, use the Kudu API for programmatic zip deployment.

Method 2: Deployment via Azure CLI

The Azure Command-Line Interface (CLI) provides a powerful and scriptable way to manage Azure resources.

1

Log in and Set Up Resources

First, log in to your Azure account:

az login

Create a resource group (if you don't have one):

az group create --name myResourceGroup --location eastus

Create an App Service Plan:

az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku B1 --is-linux
2

Create and Deploy the Web App

Create the Web App itself:

az webapp create --name myUniqueAppName --plan myAppServicePlan --resource-group myResourceGroup --runtime "NODE|18-lts"

Deploy your application code (assuming you are in your project's root directory):

az webapp deploy --resource-group myResourceGroup --name myUniqueAppName --src-path . --type zip

This command packages your current directory into a zip file and deploys it.

Method 3: Continuous Deployment with Git

Set up your App Service to automatically deploy code from a Git repository (Azure Repos, GitHub, Bitbucket).

1

Configure Deployment Center

In the Azure portal, navigate to your App Service, then "Deployment Center". Select your desired code repository provider (e.g., GitHub).

2

Authorize and Select Repository

Authorize the connection to your repository. Select the repository and branch you want to deploy from.

3

Build and Deploy Settings

Configure build settings if needed (e.g., Node.js build command like npm install && npm run build). Once saved, your App Service will automatically deploy any new commits pushed to the selected branch.

Managing Deployments with Deployment Slots

Deployment slots are invaluable for zero-downtime deployments. You can deploy to a staging slot, test it, and then "swap" it with the production slot.

1

Create a Staging Slot

In your App Service menu, go to "Deployment slots" and click "Add Slot". Give it a name (e.g., "staging") and configure it similarly to your production slot.

2

Deploy to Staging

Deploy your application code to this new staging slot using any of the methods described above.

3

Test and Swap

Once you're satisfied with the staging deployment, go back to "Deployment slots" and click the "Swap" button. Select your staging slot and the production slot. Azure will perform a zero-downtime swap, making your staged version live.

Troubleshooting Common Issues

  • Application not starting: Check the logs in the "Log stream" section of your App Service. Ensure your application's startup command is correct.
  • Configuration errors: Use "Application settings" in the Azure portal to store environment-specific configurations securely.
  • Deployment failures: Verify your deployment package integrity and check build logs for errors.

This tutorial provides a foundational understanding of deploying applications to Azure App Service. Explore the Azure documentation for more advanced configurations, CI/CD integrations, and scaling options.