Refactor backend deployment workflow to use Docker container in Azure App Service

This commit is contained in:
faris Aljohari
2024-07-22 14:29:12 +03:00
parent b3b6bde41d
commit e6ceefdfe8

View File

@ -1,7 +1,4 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy name: Backend deployment to Azure App Service
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js app to Azure Web App - syncrow
on: on:
push: push:
@ -9,63 +6,50 @@ on:
- dev - dev
workflow_dispatch: workflow_dispatch:
env:
AZURE_WEB_APP_NAME: 'syncrow'
AZURE_WEB_APP_SLOT_NAME: 'dev'
ACR_REGISTRY: 'syncrow.azurecr.io'
IMAGE_NAME: 'backend'
IMAGE_TAG: 'latest'
jobs: jobs:
build: build_and_deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up Node.js version - name: Set up Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: '20.x' node-version: '20'
- name: npm install, build, and test - name: Install dependencies and build project
run: | run: |
npm install npm install
npm run build --if-present npm run build
npm run test --if-present
- name: Zip artifact for deployment - name: Log in to Azure
run: zip release.zip ./* -r uses: azure/login@v1
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with: with:
name: node-app creds: ${{ secrets.AZURE_CREDENTIALS }}
path: release.zip
deploy: - name: Log in to Azure Container Registry
runs-on: ubuntu-latest run: az acr login --name ${{ env.ACR_REGISTRY }}
needs: build
environment:
name: 'dev'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write #This is required for requesting the JWT
steps: - name: List build output
- name: Download artifact from build job run: ls -R dist/
uses: actions/download-artifact@v4
with:
name: node-app
- name: Unzip artifact for deployment - name: Build and push Docker image
run: unzip release.zip run: |
docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
- name: Login to Azure docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_485A0602D86D4DE38207E95F1F03EF5F }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_B749E5A71F514B84BFD9532F16ED0B06 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_3496607389F54BDABA9F6FBDEFF92464 }}
- name: 'Deploy to Azure Web App' - name: Set Web App with Docker container
id: deploy-to-webapp run: |
uses: azure/webapps-deploy@v3 az webapp config container set \
with: --name ${{ env.AZURE_WEB_APP_NAME }} \
app-name: 'syncrow' --resource-group backend \
slot-name: 'dev' --docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
package: . --docker-registry-server-url https://${{ env.ACR_REGISTRY }}