Azure App Service offers a flexible and robust platform for hosting web applications. Deploying your code to App Service can be achieved through various methods, catering to different workflows and development preferences. This document outlines the most common and recommended deployment strategies.
The best deployment method depends on your team's workflow, the tools you use, and your need for continuous integration and continuous delivery (CI/CD).
GitHub Actions provides a powerful way to automate your build and deployment pipeline directly from your GitHub repository. Here’s a simplified example of a workflow to deploy to Azure App Service:
name: Deploy to Azure App Service
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm test --if-present
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: 'your-app-service-name'
package: '.'
slot-name: 'production' # Or your deployment slot name
Ensure you have set up the AZURE_CREDENTIALS
secret in your GitHub repository's settings, containing your Azure service principal credentials.
The Azure Command-Line Interface (CLI) is a versatile tool for managing Azure resources. You can deploy your application using the az webapp deploy
command.
# Log in to your Azure account
az login
# Set your subscription context (if you have multiple)
az account set --subscription "Your Subscription Name or ID"
# Deploy from a local zip file
az webapp deploy --resource-group "YourResourceGroup" --name "YourAppServiceName" --src-path "./path/to/your/app.zip" --type zip
# Deploy from a local folder (using zip deploy implicitly)
az webapp deploy --resource-group "YourResourceGroup" --name "YourAppServiceName" --src-path "./your-app-folder/"
# Deploy from a local Git repository
az webapp deployment source config-local-git --name "YourAppServiceName" --resource-group "YourResourceGroup" --git-url "https://github.com/yourusername/yourrepo.git" --branch main
Replace placeholders like YourResourceGroup
, YourAppServiceName
, and ./path/to/your/app.zip
with your actual values.