App Services Deployment

This section covers various methods and best practices for deploying your applications to Azure App Services.

Deploying with Git

Azure App Services integrates seamlessly with Git repositories, allowing for continuous deployment directly from your source code.

Local Git Deployment

You can set up your App Service to deploy from a local Git repository. Azure provides a Git endpoint for your App Service.

  1. Navigate to your App Service in the Azure portal.
  2. Under Deployment Center, select Local Git.
  3. Follow the instructions to set up your Git credentials and repository.

GitHub/Azure DevOps Integration

Connect your App Service directly to your GitHub or Azure DevOps repository for automated deployments on code commits.

Steps:

  1. In the Deployment Center, choose GitHub or Azure DevOps.
  2. Authorize Azure to access your repository.
  3. Configure your build and deployment settings.
Tip: Enable Continuous Deployment to automatically deploy changes whenever new code is pushed to your connected repository.

Zip Push Deployment

This method allows you to deploy your application by zipping your project files and pushing them directly to the App Service. This is useful for one-off deployments or when you don't want to set up a Git repository.

Using Azure CLI

You can use the Azure CLI to zip and deploy your application:

az webapp deploy --resource-group MyResourceGroup --name MyWebApp --src-path /path/to/your/app.zip --type zip

Using Zip File Upload in Portal

Alternatively, you can upload a zip file directly through the Azure portal:

  1. Go to your App Service in the Azure portal.
  2. Navigate to Deployment Center.
  3. Select Local Git and then choose the Zip Push Deploy option.
  4. Upload your zip file.

Container Deployment

Azure App Services supports deploying applications packaged as Docker containers. This provides a consistent environment across development, testing, and production.

Deploying from Docker Hub or Other Registries

Configure your App Service to pull images from public or private Docker registries.

  1. In the Azure portal, go to your App Service.
  2. Under Deployment, select Container settings.
  3. Choose your container registry (Docker Hub, Azure Container Registry, etc.).
  4. Provide the image name and tag.
  5. Configure optional settings like port mapping and environment variables.

Azure Container Registry (ACR)

For private images, Azure Container Registry is the recommended solution. It integrates seamlessly with App Services.

Note: Ensure your App Service has the necessary permissions to access your private container registry.

Build and Deploy from Source Code (using Dockerfile)

You can also configure App Services to build your Docker image directly from your source code and a Dockerfile.

# Example Dockerfile
            FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
            WORKDIR /app
            COPY . .
            RUN dotnet restore
            RUN dotnet build --no-restore -c Release -o /app/build

            FROM build AS publish
            RUN dotnet publish --no-build -c Release -o /app/publish

            FROM base AS final
            WORKDIR /app
            COPY --from=publish /app/publish .
            ENTRYPOINT ["dotnet", "YourApp.dll"]

CI/CD Integration

Automate your build and deployment pipeline using popular CI/CD tools to ensure faster, more reliable releases.

Azure Pipelines

Azure Pipelines offers a robust CI/CD solution that integrates perfectly with Azure App Services.

Key Features:

Azure Pipelines Diagram

GitHub Actions

Leverage GitHub Actions to create custom workflows that trigger deployments to Azure App Services directly from your GitHub repository.

Example Workflow Snippet:

name: Deploy to Azure App Service

            on:
              push:
                branches:
                  - main

            jobs:
              build-and-deploy:
                runs-on: ubuntu-latest
                steps:
                - uses: actions/checkout@v2
                - name: Set up .NET Core
                  uses: actions/setup-dotnet@v1
                  with:
                    dotnet-version: '3.1.x'
                - name: Build with dotnet
                  run: dotnet build --configuration Release
                - name: Publish with dotnet
                  run: dotnet publish --configuration Release --output ./publish
                - name: 'Deploy to Azure Web App'
                  uses: azure/webapps-deploy@v2
                  with:
                    app-name: 'MyWebApp'
                    publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
                    package: './publish'

Other CI/CD Tools

App Services also supports integration with other popular CI/CD tools like Jenkins, Travis CI, and CircleCI.