diff --git a/.github/workflows/dev_syncrow(dev).yml b/.github/workflows/dev_syncrow(dev).yml index 8b04e13..88493c0 100644 --- a/.github/workflows/dev_syncrow(dev).yml +++ b/.github/workflows/dev_syncrow(dev).yml @@ -1,7 +1,4 @@ -# 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 +name: Backend deployment to Azure App Service on: push: @@ -9,63 +6,50 @@ on: - dev 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: - build: + build_and_deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Node.js version + - name: Set up Node.js uses: actions/setup-node@v3 with: - node-version: '20.x' + node-version: '20' - - name: npm install, build, and test + - name: Install dependencies and build project run: | npm install - npm run build --if-present - npm run test --if-present + npm run build - - name: Zip artifact for deployment - run: zip release.zip ./* -r - - - name: Upload artifact for deployment job - uses: actions/upload-artifact@v4 + - name: Log in to Azure + uses: azure/login@v1 with: - name: node-app - path: release.zip + creds: ${{ secrets.AZURE_CREDENTIALS }} - deploy: - 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: Log in to Azure Container Registry + run: az acr login --name ${{ env.ACR_REGISTRY }} - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - name: node-app + - name: List build output + run: ls -R dist/ - - name: Unzip artifact for deployment - run: unzip release.zip - - - name: Login to Azure - uses: azure/login@v2 - with: - client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_1D4E81E705C747DB89E8634382A379E0 }} - tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_B79D0E61EB9A49269E1713FBC09718C0 }} - subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_6509C9E02E59481C94EC41279E7F4532 }} + - 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: 'Deploy to Azure Web App' - id: deploy-to-webapp - uses: azure/webapps-deploy@v3 - with: - app-name: 'syncrow' - slot-name: 'dev' - package: . - \ No newline at end of file + - name: Set Web App with Docker container + run: | + az webapp config container set \ + --name ${{ env.AZURE_WEB_APP_NAME }} \ + --resource-group backend \ + --docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \ + --docker-registry-server-url https://${{ env.ACR_REGISTRY }} \ No newline at end of file