|
| 1 | +name: Build and deploy Python app to Azure Web App - EOAgriTool |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - github |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: read #This is required for actions/checkout |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Python version |
| 20 | + uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: '3.9' |
| 23 | + |
| 24 | + - name: Create and start virtual environment |
| 25 | + run: | |
| 26 | + python -m venv venv |
| 27 | + source venv/bin/activate |
| 28 | + |
| 29 | + - name: Install Python dependencies |
| 30 | + run: pip install -r requirements.txt |
| 31 | + |
| 32 | + # Optional: Add step to run tests here (PyTest, Django test suites, etc.) |
| 33 | + |
| 34 | + - name: Zip artifact for deployment |
| 35 | + run: zip release.zip ./* -r |
| 36 | + |
| 37 | + - name: Upload artifact for deployment jobs |
| 38 | + uses: actions/upload-artifact@v4 |
| 39 | + with: |
| 40 | + name: python-app |
| 41 | + path: | |
| 42 | + release.zip |
| 43 | + !venv/ |
| 44 | +
|
| 45 | + deploy: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: build |
| 48 | + environment: |
| 49 | + name: 'Production' |
| 50 | + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} |
| 51 | + permissions: |
| 52 | + id-token: write #This is required for requesting the JWT |
| 53 | + contents: read #This is required for actions/checkout |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Download artifact from build job |
| 57 | + uses: actions/download-artifact@v4 |
| 58 | + with: |
| 59 | + name: python-app |
| 60 | + |
| 61 | + - name: Unzip artifact for deployment |
| 62 | + run: unzip release.zip |
| 63 | + |
| 64 | + - name: Login to Azure |
| 65 | + uses: azure/login@v2 |
| 66 | + with: |
| 67 | + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_4B2AA51C8F3E408F929B19AAB9401302 }} |
| 68 | + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_39535BE70D534ABDB745C9214BE55081 }} |
| 69 | + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_BB2D4206F5AC44CDA3289568B63A38F7 }} |
| 70 | + |
| 71 | + - name: 'Deploy to Azure Web App' |
| 72 | + uses: azure/webapps-deploy@v3 |
| 73 | + id: deploy-to-webapp |
| 74 | + with: |
| 75 | + app-name: 'EOAgriTool' |
| 76 | + slot-name: 'Production' |
| 77 | + |
| 78 | + nodejs: |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: Checkout code from github branch |
| 82 | + uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: github |
| 85 | + |
| 86 | + - name: Set up Node.js |
| 87 | + uses: actions/setup-node@v3 |
| 88 | + with: |
| 89 | + node-version: '16' |
| 90 | + |
| 91 | + - name: Install Node.js dependencies |
| 92 | + run: npm install |
| 93 | + |
| 94 | + - name: Run Node.js API |
| 95 | + run: npm start |
0 commit comments