From 6e1361c597ad1b23b82199dad1801fc64091921a Mon Sep 17 00:00:00 2001 From: Ahsen Tahir <147121714+AhsenTahir@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:37:26 +0500 Subject: [PATCH] Add GitHub Actions workflow for Azure deployment --- .github/workflows/azure-deploy.yml | 71 ++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/azure-deploy.yml diff --git a/.github/workflows/azure-deploy.yml b/.github/workflows/azure-deploy.yml new file mode 100644 index 0000000..14caa27 --- /dev/null +++ b/.github/workflows/azure-deploy.yml @@ -0,0 +1,71 @@ +name: Build and deploy Python app to Azure Web App - TrendXbtc + +on: + push: + branches: + - main # This triggers the workflow on every push to the main branch + workflow_dispatch: # Allows you to manually trigger the workflow + +jobs: + build: + runs-on: ubuntu-latest # Running on Ubuntu Linux + + steps: + - name: Checkout code + uses: actions/checkout@v4 # Checks out the code from the repository + + - name: Set up Python version + uses: actions/setup-python@v5 + with: + python-version: '3.11' # Set Python version to 3.11 + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r requirements.txt # Installs Python dependencies + + - name: Zip artifact for deployment + run: zip release.zip ./* -r # Zips the project files for deployment + + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v4 + with: + name: python-app + path: | + release.zip + !venv/ # Don't upload the virtual environment + + deploy: + runs-on: ubuntu-latest + needs: build # This job will run after the 'build' job + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} # URL of the deployed app + permissions: + id-token: write # Required to request the JWT for authentication + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + name: python-app # Download the artifact created by the 'build' job + + - name: Unzip artifact for deployment + run: unzip release.zip # Unzips the artifact + + - name: Login to Azure + uses: azure/login@v2 # Logs into Azure + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Deploy to Azure Web App + uses: azure/webapps-deploy@v3 # Deploys to Azure Web App + id: deploy-to-webapp + with: + app-name: 'TrendXbtc' # Your Azure Web App name + slot-name: 'Production' # Deployment slot (usually 'Production')