Build and Deploy Container Image to App Service #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Container Image to App Service | |
on: | |
workflow_dispatch: | |
defaults: | |
run: | |
working-directory: ./blue-green-deployment/src | |
# Note: The use of :latest for the container image is not recommeded for production environments. | |
jobs: | |
build-container-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Checkout GitHub Action' | |
uses: actions/checkout@main | |
- name: 'Login via Azure CLI' | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: 'Build and Push Image to ACR' | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }} | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- run: | | |
docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/hellobluegreenwebapp:latest | |
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/hellobluegreenwebapp:latest | |
deploy-to-blue-slot: | |
needs: build-container-image | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Checkout GitHub Action' | |
uses: actions/checkout@main | |
- name: 'Login via Azure CLI' | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: 'Get App Name' | |
id: getwebappname | |
run: | | |
a=$(az webapp list -g ${{ secrets.AZURE_RG }} --query '[].{Name:name}' -o tsv) | |
echo "::set-output name=appName::$a" | |
- name: 'Deploy to Blue Slot' | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ steps.getwebappname.outputs.appName }} | |
images: ${{ secrets.REGISTRY_LOGIN_SERVER }}/hellobluegreenwebapp:latest | |
slot-name: 'blue' | |
swap-to-green-slot: | |
runs-on: ubuntu-latest | |
environment: Dev | |
needs: deploy-to-blue-slot | |
steps: | |
- name: 'Checkout GitHub Action' | |
uses: actions/checkout@main | |
- name: 'Login via Azure CLI' | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: 'Get App Name' | |
id: getwebappname | |
run: | | |
a=$(az webapp list -g ${{ secrets.AZURE_RG }} --query '[].{Name:name}' -o tsv) | |
echo "::set-output name=appName::$a" | |
- name: 'Swap to green slot' | |
uses: Azure/cli@v1 | |
with: | |
inlineScript: | | |
az webapp deployment slot swap --slot 'blue' --resource-group ${{ secrets.AZURE_RG }} --name ${{ steps.getwebappname.outputs.appName }} |