From a6b27f5d6d58d610fb657e644797b4d9cb158d0d Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Mon, 8 Apr 2024 15:36:27 +0100 Subject: [PATCH 1/4] Add secure_ssl config in `settings.py` --- app/api/api/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/api/api/settings.py b/app/api/api/settings.py index 7f30aff4a..5d03f3f52 100644 --- a/app/api/api/settings.py +++ b/app/api/api/settings.py @@ -41,6 +41,8 @@ ALLOWED_HOSTS = [ x.strip()[1:-1] for x in os.environ.get("ALLOWED_HOSTS")[1:-1].split(",") ] +SECURE_SSL_REDIRECT = True +SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # Application definition From 9bb9318cb8eb9e6849e1277ac13500cf2a63fece Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Mon, 8 Apr 2024 15:37:24 +0100 Subject: [PATCH 2/4] Temp changes to pipeline --- .github/workflows/deploy.yml | 200 +++++++++++++++++------------------ 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 95db47def..6acb5b3d2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Build and Deploy to Azure - ccom on: push: branches: - - master + - fix/640-updatre-django workflow_dispatch: env: @@ -152,102 +152,102 @@ jobs: images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' # Deploy Next.js Client App Dev - deploy-next-dev: - runs-on: ubuntu-latest - needs: [build-and-publish-next-app, deploy-web-dev] - environment: dev - - steps: - - uses: actions/checkout@v2 - - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - path: frontendwebapp - name: frontendwebapp - - - name: Deploy to Azure WebApp - uses: azure/webapps-deploy@v2 - with: - app-name: 'ccom-next-dev' - publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }} - package: ${{ github.workspace }}/frontendwebapp - - # Deploy Workers Test - deploy-workers-test: - runs-on: ubuntu-latest - needs: deploy-workers-dev - environment: test - - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - path: functionsapp - name: functionsapp - - - name: 'Run Azure Functions Action' - uses: Azure/functions-action@v1.3.2 - id: fa - with: - app-name: 'ccom-funcs-test' - slot-name: 'production' - package: ${{ github.workspace }}/functionsapp - publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} - - # Deploy Web App Test - deploy-web-test: - runs-on: ubuntu-latest - needs: [deploy-web-dev, deploy-workers-test] - environment: - name: 'test' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - steps: - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v2 - with: - app-name: 'ccom-test' - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' - - # Deploy Workers Production - deploy-workers-production: - runs-on: ubuntu-latest - needs: deploy-workers-test - environment: production - - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - path: functionsapp - name: functionsapp - - - name: 'Run Azure Functions Action' - uses: Azure/functions-action@v1.3.2 - id: fa - with: - app-name: 'ccom-funcs-prod' - slot-name: 'production' - package: ${{ github.workspace }}/functionsapp - publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} - - # Deploy Web App Production - deploy-web-production: - runs-on: ubuntu-latest - needs: [deploy-web-test, deploy-workers-production] - environment: - name: 'production' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - steps: - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v2 - with: - app-name: 'ccom' - slot-name: 'production' - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' + # deploy-next-dev: + # runs-on: ubuntu-latest + # needs: [build-and-publish-next-app, deploy-web-dev] + # environment: dev + + # steps: + # - uses: actions/checkout@v2 + + # - name: Download artifact from build job + # uses: actions/download-artifact@v4 + # with: + # path: frontendwebapp + # name: frontendwebapp + + # - name: Deploy to Azure WebApp + # uses: azure/webapps-deploy@v2 + # with: + # app-name: 'ccom-next-dev' + # publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }} + # package: ${{ github.workspace }}/frontendwebapp + + # # Deploy Workers Test + # deploy-workers-test: + # runs-on: ubuntu-latest + # needs: deploy-workers-dev + # environment: test + + # steps: + # - name: Download artifact from build job + # uses: actions/download-artifact@v4 + # with: + # path: functionsapp + # name: functionsapp + + # - name: 'Run Azure Functions Action' + # uses: Azure/functions-action@v1.3.2 + # id: fa + # with: + # app-name: 'ccom-funcs-test' + # slot-name: 'production' + # package: ${{ github.workspace }}/functionsapp + # publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} + + # # Deploy Web App Test + # deploy-web-test: + # runs-on: ubuntu-latest + # needs: [deploy-web-dev, deploy-workers-test] + # environment: + # name: 'test' + # url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + # steps: + # - name: Deploy to Azure Web App + # id: deploy-to-webapp + # uses: azure/webapps-deploy@v2 + # with: + # app-name: 'ccom-test' + # publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + # images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' + + # # Deploy Workers Production + # deploy-workers-production: + # runs-on: ubuntu-latest + # needs: deploy-workers-test + # environment: production + + # steps: + # - name: Download artifact from build job + # uses: actions/download-artifact@v4 + # with: + # path: functionsapp + # name: functionsapp + + # - name: 'Run Azure Functions Action' + # uses: Azure/functions-action@v1.3.2 + # id: fa + # with: + # app-name: 'ccom-funcs-prod' + # slot-name: 'production' + # package: ${{ github.workspace }}/functionsapp + # publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} + + # # Deploy Web App Production + # deploy-web-production: + # runs-on: ubuntu-latest + # needs: [deploy-web-test, deploy-workers-production] + # environment: + # name: 'production' + # url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + # steps: + # - name: Deploy to Azure Web App + # id: deploy-to-webapp + # uses: azure/webapps-deploy@v2 + # with: + # app-name: 'ccom' + # slot-name: 'production' + # publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + # images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' From 11d4b8e3b516ad8505dcb9fc94329e6d69eb75c8 Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Mon, 8 Apr 2024 15:49:50 +0100 Subject: [PATCH 3/4] Revert pipeline --- .github/workflows/deploy.yml | 200 +++++++++++++++++------------------ 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6acb5b3d2..95db47def 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Build and Deploy to Azure - ccom on: push: branches: - - fix/640-updatre-django + - master workflow_dispatch: env: @@ -152,102 +152,102 @@ jobs: images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' # Deploy Next.js Client App Dev - # deploy-next-dev: - # runs-on: ubuntu-latest - # needs: [build-and-publish-next-app, deploy-web-dev] - # environment: dev - - # steps: - # - uses: actions/checkout@v2 - - # - name: Download artifact from build job - # uses: actions/download-artifact@v4 - # with: - # path: frontendwebapp - # name: frontendwebapp - - # - name: Deploy to Azure WebApp - # uses: azure/webapps-deploy@v2 - # with: - # app-name: 'ccom-next-dev' - # publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }} - # package: ${{ github.workspace }}/frontendwebapp - - # # Deploy Workers Test - # deploy-workers-test: - # runs-on: ubuntu-latest - # needs: deploy-workers-dev - # environment: test - - # steps: - # - name: Download artifact from build job - # uses: actions/download-artifact@v4 - # with: - # path: functionsapp - # name: functionsapp - - # - name: 'Run Azure Functions Action' - # uses: Azure/functions-action@v1.3.2 - # id: fa - # with: - # app-name: 'ccom-funcs-test' - # slot-name: 'production' - # package: ${{ github.workspace }}/functionsapp - # publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} - - # # Deploy Web App Test - # deploy-web-test: - # runs-on: ubuntu-latest - # needs: [deploy-web-dev, deploy-workers-test] - # environment: - # name: 'test' - # url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - # steps: - # - name: Deploy to Azure Web App - # id: deploy-to-webapp - # uses: azure/webapps-deploy@v2 - # with: - # app-name: 'ccom-test' - # publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - # images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' - - # # Deploy Workers Production - # deploy-workers-production: - # runs-on: ubuntu-latest - # needs: deploy-workers-test - # environment: production - - # steps: - # - name: Download artifact from build job - # uses: actions/download-artifact@v4 - # with: - # path: functionsapp - # name: functionsapp - - # - name: 'Run Azure Functions Action' - # uses: Azure/functions-action@v1.3.2 - # id: fa - # with: - # app-name: 'ccom-funcs-prod' - # slot-name: 'production' - # package: ${{ github.workspace }}/functionsapp - # publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} - - # # Deploy Web App Production - # deploy-web-production: - # runs-on: ubuntu-latest - # needs: [deploy-web-test, deploy-workers-production] - # environment: - # name: 'production' - # url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - # steps: - # - name: Deploy to Azure Web App - # id: deploy-to-webapp - # uses: azure/webapps-deploy@v2 - # with: - # app-name: 'ccom' - # slot-name: 'production' - # publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - # images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' + deploy-next-dev: + runs-on: ubuntu-latest + needs: [build-and-publish-next-app, deploy-web-dev] + environment: dev + + steps: + - uses: actions/checkout@v2 + + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + path: frontendwebapp + name: frontendwebapp + + - name: Deploy to Azure WebApp + uses: azure/webapps-deploy@v2 + with: + app-name: 'ccom-next-dev' + publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }} + package: ${{ github.workspace }}/frontendwebapp + + # Deploy Workers Test + deploy-workers-test: + runs-on: ubuntu-latest + needs: deploy-workers-dev + environment: test + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + path: functionsapp + name: functionsapp + + - name: 'Run Azure Functions Action' + uses: Azure/functions-action@v1.3.2 + id: fa + with: + app-name: 'ccom-funcs-test' + slot-name: 'production' + package: ${{ github.workspace }}/functionsapp + publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} + + # Deploy Web App Test + deploy-web-test: + runs-on: ubuntu-latest + needs: [deploy-web-dev, deploy-workers-test] + environment: + name: 'test' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'ccom-test' + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' + + # Deploy Workers Production + deploy-workers-production: + runs-on: ubuntu-latest + needs: deploy-workers-test + environment: production + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + path: functionsapp + name: functionsapp + + - name: 'Run Azure Functions Action' + uses: Azure/functions-action@v1.3.2 + id: fa + with: + app-name: 'ccom-funcs-prod' + slot-name: 'production' + package: ${{ github.workspace }}/functionsapp + publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }} + + # Deploy Web App Production + deploy-web-production: + runs-on: ubuntu-latest + needs: [deploy-web-test, deploy-workers-production] + environment: + name: 'production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'ccom' + slot-name: 'production' + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}' From 5f83a66456b17d79e6df9f06ba737ac51d7a748a Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Tue, 9 Apr 2024 09:21:01 +0100 Subject: [PATCH 4/4] Add test file --- app/api/pyproject.toml | 2 +- app/api/test/settings.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 app/api/test/settings.py diff --git a/app/api/pyproject.toml b/app/api/pyproject.toml index a39f6d9f9..f576476ea 100644 --- a/app/api/pyproject.toml +++ b/app/api/pyproject.toml @@ -36,4 +36,4 @@ build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] minversion = "6.0" addopts = "-ra -q" -DJANGO_SETTINGS_MODULE = "api.settings" +DJANGO_SETTINGS_MODULE = "test.settings" diff --git a/app/api/test/settings.py b/app/api/test/settings.py new file mode 100644 index 000000000..9cc1d8ca2 --- /dev/null +++ b/app/api/test/settings.py @@ -0,0 +1,3 @@ +from api.settings import * + +SECURE_SSL_REDIRECT = False