diff --git a/.github/workflows/master_kickoff-k8s.yml b/.github/workflows/master_kickoff-k8s.yml new file mode 100644 index 0000000..8081b00 --- /dev/null +++ b/.github/workflows/master_kickoff-k8s.yml @@ -0,0 +1,71 @@ +# 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 - kickoff-k8s + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read #This is required for actions/checkout + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python version + uses: actions/setup-python@v5 + with: + python-version: '3.14' + + # By default, when you enable GitHub CI/CD integration through the Azure portal, the platform automatically sets the SCM_DO_BUILD_DURING_DEPLOYMENT application setting to true. This triggers the use of Oryx, a build engine that handles application compilation and dependency installation (e.g., pip install) directly on the platform during deployment. Hence, we exclude the antenv virtual environment directory from the deployment artifact to reduce the payload size. + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v4 + with: + name: python-app + path: | + . + !antenv/ + + # 🚫 Opting Out of Oryx Build + # If you prefer to disable the Oryx build process during deployment, follow these steps: + # 1. Remove the SCM_DO_BUILD_DURING_DEPLOYMENT app setting from your Azure App Service Environment variables. + # 2. Refer to sample workflows for alternative deployment strategies: https://github.com/Azure/actions-workflow-samples/tree/master/AppService + + + deploy: + runs-on: ubuntu-latest + needs: build + permissions: + id-token: write #This is required for requesting the JWT + contents: read #This is required for actions/checkout + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + name: python-app + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_36EE29AB2FBC42D5A9A0A3E17A440346 }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_E281EFFDB2674A3580C8D9157072E1D8 }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_B7DD9C1C5DB84D16A34F7376939838EB }} + + - name: 'Deploy to Azure Web App' + uses: azure/webapps-deploy@v3 + id: deploy-to-webapp + with: + app-name: 'kickoff-k8s' + slot-name: 'Production' + + + + diff --git a/app.py b/app.py index 6320868..6448aae 100644 --- a/app.py +++ b/app.py @@ -1,42 +1,15 @@ -import os from flask import Flask -from flaskext.mysql import MySQL # For newer versions of flask-mysql -# from flask.ext.mysql import MySQL # For older versions of flask-mysql -app = Flask(__name__) - -mysql = MySQL() - -mysql_database_host = 'MYSQL_DATABASE_HOST' in os.environ and os.environ['MYSQL_DATABASE_HOST'] or 'localhost' - -# MySQL configurations -app.config['MYSQL_DATABASE_USER'] = 'db_user' -app.config['MYSQL_DATABASE_PASSWORD'] = 'Passw0rd' -app.config['MYSQL_DATABASE_DB'] = 'employee_db' -app.config['MYSQL_DATABASE_HOST'] = mysql_database_host -mysql.init_app(app) -conn = mysql.connect() +app = Flask(__name__) -cursor = conn.cursor() @app.route("/") def main(): - return "Welcome!" + return "Welcome! Hello, World!" @app.route('/how are you') def hello(): return 'I am good, how about you?' -@app.route('/read from database') -def read(): - cursor.execute("SELECT * FROM employees") - row = cursor.fetchone() - result = [] - while row is not None: - result.append(row[0]) - row = cursor.fetchone() - - return ",".join(result) - if __name__ == "__main__": app.run()