From 26d7ce2c279adf31bcb7a57e3f97303c6435db46 Mon Sep 17 00:00:00 2001 From: Jesus Camacho Rodriguez Date: Thu, 8 Feb 2024 15:25:04 -0800 Subject: [PATCH] webapp deploy workflow --- .github/workflows/webapp-deploy.yaml | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .github/workflows/webapp-deploy.yaml diff --git a/.github/workflows/webapp-deploy.yaml b/.github/workflows/webapp-deploy.yaml new file mode 100644 index 00000000..a498d432 --- /dev/null +++ b/.github/workflows/webapp-deploy.yaml @@ -0,0 +1,102 @@ +# Copyright (c) Microsoft Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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 - lst-bench + +on: + pull_request: + push: + paths: + - metrics/** + branches: + - main + workflow_dispatch: + +permissions: + contents: read + +env: + AZURE_WEBAPP_NAME: lst-bench + WORKING_DIRECTORY: './metrics/app' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: 'Set up Python version' + uses: actions/setup-python@v1 + with: + python-version: '3.11' + + - name: 'Create and start virtual environment' + working-directory: ${{ env.WORKING_DIRECTORY }} + run: | + python -m venv venv + source venv/bin/activate + + - name: 'Install dependencies' + working-directory: ${{ env.WORKING_DIRECTORY }} + run: | + pip install setuptools + pip install -r requirements.txt + + - name: Zip artifact for deployment + working-directory: ${{ env.WORKING_DIRECTORY }} + run: zip release.zip ./* -r + + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v3 + with: + name: python-app + path: | + ${{ env.WORKING_DIRECTORY }}/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.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 + id: deploy-to-webapp + with: + app-name: ${{ env.AZURE_WEBAPP_NAME }}