Github actions to deploy subdirectory flask project to Azure Web App

63 views Asked by At

I have this folder structure:

Folder Structure

It is a react web app, with backend folders included like flask and nodejs.

Due to requirements I'm required to combine my backend towards my frontend code.

Hence I've tried several ways and modifying my github actions file and finally managed to got it to working.

This is my yml file.

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: Build and deploy Python app to Azure Web App - app-backend-flask

on:
  push:
    branches:
      - master
    paths:
      - "backend-flask/**"
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: ./backend-flask
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python version
        uses: actions/setup-python@v1
        with:
          python-version: "3.9"

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate

      - name: Install dependencies
        run: pip install -r requirements.txt

      # Optional: Add step to run tests here (PyTest, Django test suites, etc.)

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v3
        with:
          name: python-app
          path: |
            backend-flask/release.zip
            !venv/

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: "Production"
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip

      - name: Login to Azure
        uses: azure/login@v1
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID }}

      - name: "Deploy to Azure Web App"
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: "app-backend-flask"
          slot-name: "Production"

As i just want to deploy my backend-flask/ folder to a azure web app, it takes a pretty long time.

Is waiting up to 22min normal? Deployment

My issue is almost the same as similar problem

I've tried using the solution by adding package name to backend-flask/ but

Deployment taking very long..

Else does my .yml have a problem?

After 40minutes it finally failed: Failed deployment

0

There are 0 answers