From de1e50713907258403604bc64a50f1a93289a90e Mon Sep 17 00:00:00 2001 From: Andy Mears Date: Sun, 15 Sep 2024 12:57:46 -0500 Subject: [PATCH 1/3] Add or update the Azure App Service build and deployment workflow config --- .github/workflows/main_waapiv1.yml | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/main_waapiv1.yml diff --git a/.github/workflows/main_waapiv1.yml b/.github/workflows/main_waapiv1.yml new file mode 100644 index 000000000..6cc027b6c --- /dev/null +++ b/.github/workflows/main_waapiv1.yml @@ -0,0 +1,78 @@ +# 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 - waapiv1 + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python version + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - 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@v4 + with: + name: python-app + path: | + 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@v4 + with: + name: python-app + + - name: Unzip artifact for deployment + run: unzip release.zip + + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_3B58C25D60C746B5A38CD41F9BF31767 }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_B567D3ABFD7B410DBC055CA161DE5CC5 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_6FA6934485F646D2B87868D22C29996B }} + + - name: 'Deploy to Azure Web App' + uses: azure/webapps-deploy@v3 + id: deploy-to-webapp + with: + app-name: 'waapiv1' + slot-name: 'Production' + \ No newline at end of file From 7c98d52d0695e8aa71f5db4d691c1bb06035fca8 Mon Sep 17 00:00:00 2001 From: Andy Mears Date: Sun, 15 Sep 2024 19:14:14 -0500 Subject: [PATCH 2/3] Update app.py Add API sections --- app.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app.py b/app.py index 3d1808cf6..508e4f41f 100644 --- a/app.py +++ b/app.py @@ -27,6 +27,38 @@ def hello(): print('Request for hello page received with no name or blank name -- redirecting') return redirect(url_for('index')) +# Sample data +companies = [ + {"id": 1, "name": "Company One", "summary": "Summary of Company One"}, + {"id": 2, "name": "Company Two", "summary": "Summary of Company Two"} +] + +# Companies endpoint +@app.route('/companies', methods=['GET']) +def get_companies(): + return jsonify(companies) + +# Companies/all endpoint +@app.route('/companies/all', methods=['GET']) +def get_all_companies(): + return jsonify(companies) + +# Companies/[id] endpoint +@app.route('/companies/', methods=['GET']) +def get_company(id): + company = next((comp for comp in companies if comp["id"] == id), None) + if company: + return jsonify(company) + return jsonify({"error": "Company not found"}), 404 + +# Companies/[id]/summary endpoint +@app.route('/companies//summary', methods=['GET']) +def get_company_summary(id): + company = next((comp for comp in companies if comp["id"] == id), None) + if company: + return jsonify({"id": company["id"], "summary": company["summary"]}) + return jsonify({"error": "Company not found"}), 404 + if __name__ == '__main__': app.run() From 915161bd05224156a1623399515462a18f8f78b3 Mon Sep 17 00:00:00 2001 From: Andy Mears Date: Sun, 15 Sep 2024 19:20:04 -0500 Subject: [PATCH 3/3] Update app.py Add jsonify --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 508e4f41f..10c7a9e4f 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,6 @@ import os -from flask import (Flask, redirect, render_template, request, +from flask import (Flask, redirect, render_template, jsonify, request, send_from_directory, url_for) app = Flask(__name__)