mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
use azure container registry
This commit is contained in:
73
.github/workflows/dev_syncrow(dev).yml
vendored
73
.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:
|
on:
|
||||||
push:
|
push:
|
||||||
@ -7,65 +7,36 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NODE_VERSION: '20.x'
|
|
||||||
AZURE_WEB_APP_NAME: 'syncrow'
|
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:
|
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
|
|
||||||
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: Log in to Azure
|
- name: Log in to Azure
|
||||||
uses: azure/login@v1
|
uses: azure/login@v1
|
||||||
with:
|
with:
|
||||||
creds: ${{ secrets.AZURE_CREDENTIALS }} # JSON Service Principal credentials for Azure in a secret
|
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
||||||
|
|
||||||
- name: Deploy to Azure Web App
|
- name: Log in to Azure Container Registry
|
||||||
uses: azure/webapps-deploy@v2
|
run: az acr login --name ${{ env.ACR_REGISTRY }}
|
||||||
with:
|
|
||||||
app-name: ${{ env.AZURE_WEB_APP_NAME }}
|
- name: Build and push Docker image
|
||||||
slot-name: ${{ env.AZURE_SLOT_NAME }}
|
run: |
|
||||||
package: 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
|
||||||
|
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