|
| 1 | +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy |
| 2 | +# More GitHub Actions for Azure: https://github.com/Azure/actions |
| 3 | +# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions |
| 4 | + |
| 5 | +name: GPTSmartSearch Apps Deployment |
| 6 | +env: |
| 7 | + DO_BUILD_DURING_DEPLOYMENT: true |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: |
| 12 | + - github-actions-apps |
| 13 | + - main |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + env-name: ${{steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT}} |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + |
| 24 | + - name: Set up Python version |
| 25 | + uses: actions/setup-python@v1 |
| 26 | + with: |
| 27 | + python-version: '3.10' |
| 28 | + |
| 29 | + - name: Set environment for branch |
| 30 | + id: set-deploy-env |
| 31 | + run: | |
| 32 | + if [[ $GITHUB_REF_NAME == 'refs/heads/main' ]]; then |
| 33 | + echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT" |
| 34 | + elif [[ $GITHUB_REF_NAME == 'refs/heads/develop' ]]; then |
| 35 | + echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT" |
| 36 | + elif [[ $GITHUB_REF_NAME == 'refs/heads/release' ]]; then |
| 37 | + echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT" |
| 38 | + else |
| 39 | + echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT" |
| 40 | + fi |
| 41 | + - name: merge backend and common folder |
| 42 | + run: | |
| 43 | + echo "Prepare backend source for enviroment [${{ steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT }}]" |
| 44 | + mkdir -p ./target/backend |
| 45 | + cp -r ./apps/backend ./target |
| 46 | + cp -r ./common/*.* ./target/backend |
| 47 | +
|
| 48 | + - name: Create and start virtual environment in backend folder |
| 49 | + if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }} |
| 50 | + run: | |
| 51 | + python -m venv ./target/backend/venv |
| 52 | + source ./target/backend/venv/bin/activate |
| 53 | + |
| 54 | + - name: Install backend dependencies |
| 55 | + if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }} |
| 56 | + run: pip install -r ./target/backend/requirements.txt |
| 57 | + |
| 58 | + - name: merge frontend and common folder |
| 59 | + run: | |
| 60 | + echo "Prepare frontend source for enviroment [${{ steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT }}]" |
| 61 | + mkdir -p ./target/frontend |
| 62 | + cp -r ./apps/frontend ./target |
| 63 | + cp -r ./common/*.* ./target/frontend |
| 64 | +
|
| 65 | + - name: Create and start virtual environment in frontend folder |
| 66 | + if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }} |
| 67 | + run: | |
| 68 | + python -m venv ./target/frontend/venv |
| 69 | + source ./target/frontend/venv/bin/activate |
| 70 | + |
| 71 | + - name: Install frontend dependencies |
| 72 | + if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }} |
| 73 | + run: pip install -r ./target/frontend/requirements.txt |
| 74 | + # Optional: Add step to run tests here (PyTest, Django test suites, etc.) |
| 75 | + |
| 76 | + - name: Upload artifacts for backend deployment jobs |
| 77 | + uses: actions/upload-artifact@v2 |
| 78 | + with: |
| 79 | + name: python-backend-app |
| 80 | + path: | |
| 81 | + ./target/backend |
| 82 | + |
| 83 | + - name: Upload artifacts for frontend deployment jobs |
| 84 | + uses: actions/upload-artifact@v2 |
| 85 | + with: |
| 86 | + name: python-frontend-app |
| 87 | + path: | |
| 88 | + ./target/frontend |
| 89 | + |
| 90 | + deploy: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: build |
| 93 | + environment: |
| 94 | + name: ${{ needs.build.outputs.env-name}} |
| 95 | + url: ${{ steps.deploy-frontend-to-webapp.outputs.webapp-url }} |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Download backend artifact from build job |
| 99 | + uses: actions/download-artifact@v2 |
| 100 | + with: |
| 101 | + name: python-backend-app |
| 102 | + path: ./backend |
| 103 | + |
| 104 | + - name: 'Deploy backend to Azure Web App' |
| 105 | + uses: azure/webapps-deploy@v2 |
| 106 | + id: deploy-backend-to-webapp |
| 107 | + with: |
| 108 | + app-name: ${{ vars.AZURE_WEBAPP_BACKEND_NAME }} |
| 109 | + package: ./backend |
| 110 | + publish-profile: ${{ secrets.AZUREAPPSERVICE_BACKEND_PUBLISHPROFILE}} |
| 111 | + |
| 112 | + - name: Download frontend artifact from build job |
| 113 | + uses: actions/download-artifact@v2 |
| 114 | + with: |
| 115 | + name: python-frontend-app |
| 116 | + path: ./frontend |
| 117 | + |
| 118 | + - name: 'Deploy frontend to Azure Web App' |
| 119 | + uses: azure/webapps-deploy@v2 |
| 120 | + id: deploy-frontend-to-webapp |
| 121 | + with: |
| 122 | + app-name: ${{ vars.AZURE_WEBAPP_FRONTEND_NAME }} |
| 123 | + package: ./frontend |
| 124 | + publish-profile: ${{ secrets.AZUREAPPSERVICE_FRONTEND_PUBLISHPROFILE}} |
0 commit comments