From 06fb9bf91183e067cad318b2e3ba224262cadbbb Mon Sep 17 00:00:00 2001 From: Alvaro Guadamillas Date: Sun, 8 Oct 2023 21:43:15 +0200 Subject: [PATCH] add: deployment to UAT --- .github/workflows/ie-bank-backend.yml | 32 +++++++++++++++++++++++++-- config.py | 11 ++++++++- iebank_api/__init__.py | 8 +++---- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ie-bank-backend.yml b/.github/workflows/ie-bank-backend.yml index 40278d1..66e91ad 100644 --- a/.github/workflows/ie-bank-backend.yml +++ b/.github/workflows/ie-bank-backend.yml @@ -12,6 +12,9 @@ permissions: env: BACKEND_WEBAPP_DEV: aguadamillas-be-dev + BACKEND_WEBAPP_UAT: aguadamillas-be-uat + source_branch_name: ${{ github.ref }} + pr_target_branch_name: ${{ github.base_ref }} jobs: build: @@ -49,7 +52,7 @@ jobs: path: | . - deploy: + deploy-dev: runs-on: ubuntu-latest needs: build environment: @@ -73,4 +76,29 @@ jobs: with: app-name: ${{ env.BACKEND_WEBAPP_DEV }} package: . - \ No newline at end of file + + deploy-uat: + runs-on: ubuntu-latest + needs: [build, deploy-dev] + # if: ${{ pr_target_branch_name == 'refs/heads/main' }} #deploys only on PR to main branch + environment: + name: 'User Acceptance Testing' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v2 + with: + name: python-app + path: . + + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: 'Deploy to Azure Web App' + uses: azure/webapps-deploy@v2 + id: deploy-to-webapp + with: + app-name: ${{ env.BACKEND_WEBAPP_UAT }} + package: . \ No newline at end of file diff --git a/config.py b/config.py index da8d30e..de129c6 100644 --- a/config.py +++ b/config.py @@ -24,4 +24,13 @@ class DevelopmentConfig(Config): dbhost=os.getenv('DBHOST'), dbname=os.getenv('DBNAME') ) - DEBUG = True \ No newline at end of file + DEBUG = True + +class UATConfig(Config): + SQLALCHEMY_DATABASE_URI = 'postgresql://{dbuser}:{dbpass}@{dbhost}/{dbname}'.format( + dbuser=os.getenv('DBUSER'), + dbpass=os.getenv('DBPASS'), + dbhost=os.getenv('DBHOST'), + dbname=os.getenv('DBNAME') + ) + DEBUG = False \ No newline at end of file diff --git a/iebank_api/__init__.py b/iebank_api/__init__.py index 2878bcf..9179b3d 100644 --- a/iebank_api/__init__.py +++ b/iebank_api/__init__.py @@ -19,9 +19,9 @@ elif os.getenv('ENV') == 'ghci': print("Running in github mode") app.config.from_object('config.GithubCIConfig') -else: - print("Running in production mode") - app.config.from_object('config.ProductionConfig') +elif os.getenv('ENV') == 'uat': + print("Running in UAT mode") + app.config.from_object('config.UATConfig') db = SQLAlchemy(app) @@ -34,7 +34,7 @@ from iebank_api import routes # Initialize Application Insights and force flushing application insights handler after each request -if(os.getenv('ENV') == 'dev'): +if(os.getenv('ENV') == 'dev' or os.getenv('ENV') == 'uat'): appinsights = AppInsights(app) @app.after_request def after_request(response):