mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
Add or update the Azure App Service build and deployment workflow config
This commit is contained in:
80
.github/workflows/dev_syncrow(dev).yml
vendored
80
.github/workflows/dev_syncrow(dev).yml
vendored
@ -1,4 +1,7 @@
|
|||||||
name: Backend deployment to Azure App Service
|
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
||||||
|
# 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:
|
||||||
@ -6,56 +9,63 @@ 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: '${{ github.sha }}' # Use commit SHA for unique tagging
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_deploy:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node.js
|
- name: Set up Node.js version
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20.x'
|
||||||
|
|
||||||
- name: Clear npm cache and install dependencies
|
- name: npm install, build, and test
|
||||||
run: |
|
run: |
|
||||||
npm cache clean --force
|
|
||||||
npm install
|
npm install
|
||||||
|
npm run build --if-present
|
||||||
|
npm run test --if-present
|
||||||
|
|
||||||
- name: Build project
|
- name: Zip artifact for deployment
|
||||||
run: npm run build
|
run: zip release.zip ./* -r
|
||||||
|
|
||||||
- name: Log in to Azure
|
- name: Upload artifact for deployment job
|
||||||
uses: azure/login@v1
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
name: node-app
|
||||||
|
path: release.zip
|
||||||
|
|
||||||
- name: Log in to Azure Container Registry
|
deploy:
|
||||||
run: az acr login --name ${{ env.ACR_REGISTRY }}
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment:
|
||||||
|
name: 'dev'
|
||||||
|
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||||
|
permissions:
|
||||||
|
id-token: write #This is required for requesting the JWT
|
||||||
|
|
||||||
- name: List build output
|
steps:
|
||||||
run: ls -R dist/
|
- name: Download artifact from build job
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Unzip artifact for deployment
|
||||||
run: |
|
run: unzip release.zip
|
||||||
docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
|
||||||
docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
|
||||||
|
|
||||||
- name: Set Web App with Docker container
|
- name: Login to Azure
|
||||||
run: |
|
uses: azure/login@v2
|
||||||
az webapp config container set \
|
with:
|
||||||
--name ${{ env.AZURE_WEB_APP_NAME }} \
|
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_E77A43669F9E4C9F9A97FD80A1C3A72F }}
|
||||||
--resource-group backend \
|
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_A54F5D02243E4655B8F85616C61EAE15 }}
|
||||||
--docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
|
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_8048D07E9A08403B9A293950B519EF30 }}
|
||||||
--docker-registry-server-url https://${{ env.ACR_REGISTRY }}
|
|
||||||
|
- name: 'Deploy to Azure Web App'
|
||||||
|
id: deploy-to-webapp
|
||||||
|
uses: azure/webapps-deploy@v3
|
||||||
|
with:
|
||||||
|
app-name: 'syncrow'
|
||||||
|
slot-name: 'dev'
|
||||||
|
package: .
|
||||||
|
|
||||||
- name: Restart Web App
|
|
||||||
run: az webapp restart --name ${{ env.AZURE_WEB_APP_NAME }} --resource-group backend
|
|
||||||
|
Reference in New Issue
Block a user