MSDN Documentation

Your Comprehensive Guide to Microsoft Technologies

Deploying Your Application to App Services

This guide provides detailed instructions and best practices for deploying your web applications, APIs, and mobile backends to Azure App Service. We cover various deployment methods, from continuous integration to manual deployments.

Supported Deployment Methods

Azure App Service offers a flexible deployment experience, supporting a wide range of tools and workflows:

  • Source Control Integration: Connect directly to repositories like GitHub, Azure Repos, Bitbucket, and GitLab for continuous deployment.
  • Azure DevOps: Leverage Azure Pipelines for robust CI/CD workflows, including build, test, and deployment stages.
  • Docker Containers: Deploy custom Docker images for consistent environments across development and production.
  • FTP/FTPS: For simple, manual deployments or quick updates.
  • Web Deploy (MSDeploy): A powerful tool for deploying ASP.NET applications.
  • Local Git Repository: Push your code directly from a local Git repository.

Continuous Deployment from GitHub

Automate your deployments by linking your App Service to a GitHub repository. Every push to your main branch will trigger a new deployment.

Steps:

  1. Navigate to your App Service in the Azure portal.
  2. Under "Deployment", select "Deployment Center".
  3. Choose "GitHub" as your source.
  4. Authenticate with your GitHub account and select your repository and branch.
  5. Configure build settings if necessary (App Service can often detect your application type).
  6. Click "Save" to set up continuous deployment.
Tip: Ensure your build pipeline is configured to produce deployable artifacts. App Service can automatically detect and deploy certain application types (e.g., Node.js, Python, .NET Core).

Deploying with Azure DevOps Pipelines

For more complex scenarios, Azure DevOps Pipelines provide a comprehensive CI/CD solution.

Example Azure Pipeline (YAML):


trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: AzureWebApp@1
  displayName: 'Deploy to Azure App Service'
  inputs:
    azureSubscription: ''
    appName: ''
    package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    deploymentMethod: 'zipDeploy'

Replace <your-azure-subscription-service-connection> and <your-app-service-name> with your specific details. This task assumes you have a ZIP package ready for deployment.

Deploying Docker Containers

App Service supports deploying single or multi-container applications using Docker Compose.

Steps for Single Container:

  1. Ensure your Docker image is available in a registry (e.g., Docker Hub, Azure Container Registry).
  2. In your App Service configuration, select "Docker Container" as the deployment source.
  3. Provide the image source, image name, tag, and registry credentials.

Deployment Slots

Deployment slots allow you to deploy different versions of your application to a staging environment before swapping them into production. This minimizes downtime and risk.

Benefits of Deployment Slots:

  • Zero-Downtime Deployments: Swap staging to production seamlessly.
  • Testing: Test new versions in a production-like environment.
  • Rollback: Quickly roll back to a previous version by swapping back.
Important: Always deploy to a staging slot first, test thoroughly, and then perform a "Swap" operation to move your application to the production slot.

Troubleshooting Common Deployment Issues

If your deployment fails, check the following:

  • Build Artifacts: Ensure the build process generates the correct deployable files.
  • Configuration: Verify connection strings, app settings, and environment variables.
  • Permissions: Check if the service principal or user account has the necessary permissions to deploy.
  • Logs: Review deployment logs in the Azure portal (Deployment Center) and application logs for error messages.
Warning: Be cautious when deploying sensitive changes directly to production. Utilize deployment slots for safety.