mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
use azure container registry
This commit is contained in:
75
.github/workflows/dev_syncrow(dev).yml
vendored
75
.github/workflows/dev_syncrow(dev).yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Build and deploy Node.js app to Azure Web App - syncrow
|
||||
name: Build and deploy Docker image to Azure Web App for Containers
|
||||
|
||||
on:
|
||||
push:
|
||||
@ -7,65 +7,36 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
NODE_VERSION: '20.x'
|
||||
AZURE_WEB_APP_NAME: 'syncrow'
|
||||
AZURE_SLOT_NAME: 'dev'
|
||||
AZURE_WEB_APP_SLOT_NAME: 'dev'
|
||||
ACR_REGISTRY: 'syncrow.azurecr.io' # Replace with your ACR name
|
||||
IMAGE_NAME: 'backend' # Replace with your image name
|
||||
IMAGE_TAG: 'latest' # Consider using dynamic tags, e.g., GitHub SHA
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build_and_deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
npm install
|
||||
npm run build --if-present
|
||||
npm run test --if-present
|
||||
|
||||
- name: Zip artifact for deployment
|
||||
run: zip -r release.zip . -x node_modules\* \*.git\* \*.github\* \*tests\*
|
||||
|
||||
- name: Upload artifact for deployment job
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: node-app
|
||||
path: release.zip
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
environment:
|
||||
name: 'dev'
|
||||
# Dynamically set or adjust as needed
|
||||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||
permissions:
|
||||
id-token: write # For federated credentials, if applicable
|
||||
|
||||
steps:
|
||||
- name: Download artifact from build job
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: node-app
|
||||
|
||||
- name: Unzip artifact for deployment
|
||||
run: unzip release.zip
|
||||
|
||||
- name: Login to Azure
|
||||
- name: Log in to Azure
|
||||
uses: azure/login@v1
|
||||
with:
|
||||
creds: ${{ secrets.AZURE_CREDENTIALS }} # JSON Service Principal credentials for Azure in a secret
|
||||
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
||||
|
||||
- name: Deploy to Azure Web App
|
||||
uses: azure/webapps-deploy@v2
|
||||
with:
|
||||
app-name: ${{ env.AZURE_WEB_APP_NAME }}
|
||||
slot-name: ${{ env.AZURE_SLOT_NAME }}
|
||||
package: release.zip
|
||||
- name: Log in to Azure Container Registry
|
||||
run: az acr login --name ${{ env.ACR_REGISTRY }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
run: |
|
||||
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
|
||||
run: |
|
||||
az webapp config container set \
|
||||
--name ${{ env.AZURE_WEB_APP_NAME }} \
|
||||
--resource-group YourResourceGroupName \ # Replace with your resource group name
|
||||
--docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
|
||||
--docker-registry-server-url https://${{ env.ACR_REGISTRY }}
|
||||
|
Reference in New Issue
Block a user