2 min read
GitHub Actions for Azure Deployments
GitHub Actions integrates natively with Azure for seamless CI/CD. Push to main, deploy to Azure.
Azure Login Action
name: Deploy to Azure
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
Setting Up Credentials
# Create service principal
az ad sp create-for-rbac --name "github-actions" --role contributor \
--scopes /subscriptions/{subscription-id} --sdk-auth
# Output JSON goes to GitHub secret AZURE_CREDENTIALS
Deploy to App Service
- name: Build and deploy
uses: azure/webapps-deploy@v2
with:
app-name: 'my-web-app'
package: './dist'
Deploy to AKS
- name: Set AKS context
uses: azure/aks-set-context@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
cluster-name: myAKSCluster
resource-group: myResourceGroup
- name: Deploy to AKS
uses: azure/k8s-deploy@v1
with:
manifests: |
kubernetes/deployment.yaml
kubernetes/service.yaml
images: |
myregistry.azurecr.io/myapp:${{ github.sha }}
Deploy ARM Template
- name: Deploy ARM Template
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
resourceGroupName: myResourceGroup
template: ./azuredeploy.json
parameters: environment=production
Complete Workflow
name: Build and Deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: npm ci && npm run build
- name: Test
run: npm test
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: dist
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy
uses: azure/webapps-deploy@v2
with:
app-name: my-app
package: .
GitHub Actions + Azure = streamlined DevOps.