From 08bb93ea27622f5b0392752517aada7a455131e0 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 6 Jun 2024 16:23:43 +0100 Subject: [PATCH 01/11] reference source path --- .github/workflows/backend.yaml | 1 + .github/workflows/test-python-code.yaml | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 566eff1a..4f2203ee 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -25,6 +25,7 @@ jobs: secrets: inherit with: python-version: ${{ inputs.python-version }} + source-path: src deploy: runs-on: ubuntu-latest diff --git a/.github/workflows/test-python-code.yaml b/.github/workflows/test-python-code.yaml index 65b0595a..bb21059f 100644 --- a/.github/workflows/test-python-code.yaml +++ b/.github/workflows/test-python-code.yaml @@ -112,9 +112,19 @@ jobs: run: | if [ ${{ github.repository_owner_id }} = ${{ env.OCADO_TECH_ORG_ID }} ] then - pipenv run pytest -n=auto --cov=. --cov-report=xml:${{ env.COVERAGE_REPORT }} -c=${{ env.PYPROJECT_TOML }} ${{ inputs.source-path }} + pipenv run pytest \ + -n=auto \ + --cov=${{ inputs.source-path }} \ + --cov-report=xml:${{ env.COVERAGE_REPORT }} \ + -c=${{ env.PYPROJECT_TOML }} \ + ${{ inputs.source-path }} else - pipenv run pytest -n=auto --cov=. --cov-fail-under=90 -c=${{ env.PYPROJECT_TOML }} ${{ inputs.source-path }} + pipenv run pytest \ + -n=auto \ + --cov=${{ inputs.source-path }} \ + --cov-fail-under=90 \ + -c=${{ env.PYPROJECT_TOML }} \ + ${{ inputs.source-path }} fi - name: 📈 Upload Coverage Reports to Codecov From 4dac2062fb5d5ed39db7fa3c4149947f69020de7 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 10:18:27 +0100 Subject: [PATCH 02/11] get service name composite action --- .../gcloud/get-service-name/action.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/actions/gcloud/get-service-name/action.yaml diff --git a/.github/actions/gcloud/get-service-name/action.yaml b/.github/actions/gcloud/get-service-name/action.yaml new file mode 100644 index 00000000..8d519270 --- /dev/null +++ b/.github/actions/gcloud/get-service-name/action.yaml @@ -0,0 +1,21 @@ +name: "Code for Life - GCloud - Get Service Name" +description: "Get a service's name based on the name of the current repository." +outputs: + service-name: + description: "The name of the current service." + value: ${{ steps.get-service-name.outputs.service-name }} +runs: + using: composite + steps: + # Set name with convention "{ENV_NAME}-{REPO_NAME}" + # where ENV_NAME is the name of the branch / environment. + # where REPO_NAME is the name of the repo without the prefix "ocadotechnology/codeforlife-". + - name: 🪪 Get Service Name + id: get-service-name + shell: bash + run: | + name=${{ github.repository }} + name=${name#"ocadotechnology/codeforlife-"} + name="${{ github.ref_name }}-${name}" + + echo "service-name=$(echo $name)" >> $GITHUB_OUTPUT From 59a909575fd915f80523f7d20f53da369265e0a2 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 10:20:18 +0100 Subject: [PATCH 03/11] get services name and test backend workflow --- .github/workflows/backend.yaml | 24 +++++++----------------- .github/workflows/frontend.yaml | 11 +++++------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 4f2203ee..45071264 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -29,7 +29,7 @@ jobs: deploy: runs-on: ubuntu-latest - needs: [validate-pr-refs, test] + needs: [test] #[validate-pr-refs, test] # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') environment: ${{ github.ref_name }} @@ -46,25 +46,16 @@ jobs: - name: 🏗️ Collect Static Files run: pipenv run python ./manage.py collectstatic --noinput --clear + - name: 🪪 Get Service Name + id: get-service-name + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@convert_to_backend_repo # TODO: use @main + # https://mikefarah.gitbook.io/yq/ # TODO: clean up app.yaml environment variables - name: 🖊️ Configure App Deployment uses: mikefarah/yq@master with: cmd: | - # Set name with convention "{ENV_NAME}-{REPO_NAME}" - name=${{ github.repository }} - name=${name#"ocadotechnology/codeforlife-"} - name="${{ github.ref_name }}-${name}" - - # Check if service is the client-facing service. - is_root=$( - if [ ${{ github.ref_name }} == "production" ] - then echo "1" - else echo "0" - fi - ) - # Set runtime with convention "python{PY_VERSION}". # The version must have the dot removed: "python3.8" -> "python38". runtime=python${{ inputs.python-version }} @@ -72,10 +63,9 @@ jobs: yq -i ' .runtime = "'$runtime'" | - .service = "'$name'" | + .service = "${{ steps.get-service-name.outputs.service-name }}" | + .env_variables.SERVICE_NAME = "${{ steps.get-service-name.outputs.service-name }}" | .env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" | - .env_variables.SERVICE_NAME = "$name" | - .env_variables.SERVICE_IS_ROOT = "$is_root" | .env_variables.MODULE_NAME = "${{ github.ref_name }}" ' app.yaml diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index ae9d4314..35a6b031 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -42,19 +42,18 @@ jobs: - name: 🏗️ Build App run: yarn build + - name: 🪪 Get Service Name + id: get-service-name + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@convert_to_backend_repo # TODO: use @main + # https://mikefarah.gitbook.io/yq/ - name: 🖊️ Configure App Deployment uses: mikefarah/yq@master with: cmd: | - # Set name with convention "{ENV_NAME}-{REPO_NAME}" - name=${{ github.repository }} - name=${name#"ocadotechnology/codeforlife-"} - name="${{ github.ref_name }}-${name}" - yq -i ' .runtime = "nodejs${{ inputs.node-version }}" | - .service = "'$name'" + .service = "${{ steps.get-service-name.outputs.service-name }}" ' app.yaml - name: 🚀 Deploy App on GCloud From 11b8d37676146633d95c1be503115cb0bea9e9d2 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 13:16:46 +0100 Subject: [PATCH 04/11] test backend deploy --- .github/workflows/backend.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 45071264..01e736ff 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -31,8 +31,9 @@ jobs: runs-on: ubuntu-latest needs: [test] #[validate-pr-refs, test] # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. - if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') - environment: ${{ github.ref_name }} + # if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') + # environment: ${{ github.ref_name }} + environment: development steps: - name: 🐍 Set up Python ${{ inputs.python-version }} Environment uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main @@ -61,9 +62,11 @@ jobs: runtime=python${{ inputs.python-version }} runtime=${runtime//.} + echo "${{ steps.get-service-name.outputs.service-name }}" + yq -i ' .runtime = "'$runtime'" | - .service = "${{ steps.get-service-name.outputs.service-name }}" | + .service = "development-portal-backend" | .env_variables.SERVICE_NAME = "${{ steps.get-service-name.outputs.service-name }}" | .env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" | .env_variables.MODULE_NAME = "${{ github.ref_name }}" From 003ad6e23098684c0c0abef9de9e7325a73d1a72 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 14:29:05 +0100 Subject: [PATCH 05/11] don't install dev deps --- .github/workflows/backend.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 01e736ff..1a01c48f 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -39,7 +39,6 @@ jobs: uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main with: python-version: ${{ inputs.python-version }} - install-args: --dev - name: 🏗️ Generate requirements.txt run: pipenv requirements > requirements.txt From 155a71057b59dc48f5721f645ebf6eb064a38260 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 14:37:30 +0100 Subject: [PATCH 06/11] tidy up pipelines --- .github/workflows/backend.yaml | 13 +++++-------- .github/workflows/frontend.yaml | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 1a01c48f..20b3cbab 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -29,11 +29,10 @@ jobs: deploy: runs-on: ubuntu-latest - needs: [test] #[validate-pr-refs, test] + needs: [validate-pr-refs, test] # Only deploy if the repo's owner is Ocado Tech. and a change is made to an environment's branch. - # if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') - # environment: ${{ github.ref_name }} - environment: development + if: github.repository_owner_id == 2088731 && (github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging') + environment: ${{ github.ref_name }} steps: - name: 🐍 Set up Python ${{ inputs.python-version }} Environment uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main @@ -48,7 +47,7 @@ jobs: - name: 🪪 Get Service Name id: get-service-name - uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@convert_to_backend_repo # TODO: use @main + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@main # https://mikefarah.gitbook.io/yq/ # TODO: clean up app.yaml environment variables @@ -61,11 +60,9 @@ jobs: runtime=python${{ inputs.python-version }} runtime=${runtime//.} - echo "${{ steps.get-service-name.outputs.service-name }}" - yq -i ' .runtime = "'$runtime'" | - .service = "development-portal-backend" | + .service = "${{ steps.get-service-name.outputs.service-name }}" | .env_variables.SERVICE_NAME = "${{ steps.get-service-name.outputs.service-name }}" | .env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" | .env_variables.MODULE_NAME = "${{ github.ref_name }}" diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml index 35a6b031..1aceaaaa 100644 --- a/.github/workflows/frontend.yaml +++ b/.github/workflows/frontend.yaml @@ -44,7 +44,7 @@ jobs: - name: 🪪 Get Service Name id: get-service-name - uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@convert_to_backend_repo # TODO: use @main + uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@main # https://mikefarah.gitbook.io/yq/ - name: 🖊️ Configure App Deployment From 1bfff9d87135fad506bb0356de6bf1d1f4103f50 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 14:43:57 +0100 Subject: [PATCH 07/11] make script executable --- .devcontainer.json | 2 +- .submodules/config/configs.jsonc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer.json b/.devcontainer.json index e4d63e1e..b215d4c5 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -34,7 +34,7 @@ "ghcr.io/devcontainers/features/github-cli:1": {} }, "name": "workspace", - "postCreateCommand": ".submodules/recurse-fork/run", + "postCreateCommand": "sudo chmod u+x .submodules/recurse-fork/run && .submodules/recurse-fork/run", "remoteUser": "root", "service": "base-service", "shutdownAction": "none", diff --git a/.submodules/config/configs.jsonc b/.submodules/config/configs.jsonc index b3057f23..3f06ca8a 100644 --- a/.submodules/config/configs.jsonc +++ b/.submodules/config/configs.jsonc @@ -318,7 +318,7 @@ ], "description": "The devcontainer for a micro-service.", "devcontainer": { - "postCreateCommand": "chmod u+x ./setup && ./setup", + "postCreateCommand": "sudo chmod u+x ./setup && ./setup", "mounts": [ "source=./codeforlife-package-javascript,target=/workspace/codeforlife-package-javascript,type=bind,consistency=cached", "source=./codeforlife-package-python,target=/workspace/codeforlife-package-python,type=bind,consistency=cached" From 1669b21605ca1bf0c4db50349e1b8bf5b002a945 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 14:56:00 +0100 Subject: [PATCH 08/11] remove codeforlife-portal-react submodule --- .gitmodules | 3 --- codeforlife-portal-react | 1 - 2 files changed, 4 deletions(-) delete mode 160000 codeforlife-portal-react diff --git a/.gitmodules b/.gitmodules index 2de7c9ff..8bc0d7d8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,9 +19,6 @@ [submodule "codeforlife-service-template"] path = codeforlife-service-template url = https://github.com/ocadotechnology/codeforlife-service-template.git -[submodule "codeforlife-portal-react"] - path = codeforlife-portal-react - url = https://github.com/ocadotechnology/codeforlife-portal-react.git [submodule "codeforlife-sso"] path = codeforlife-sso url = https://github.com/ocadotechnology/codeforlife-sso.git diff --git a/codeforlife-portal-react b/codeforlife-portal-react deleted file mode 160000 index 0c42b56b..00000000 --- a/codeforlife-portal-react +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0c42b56bd5d37fc9dd3071d48f9671c4be9a9fcd From 96b0f1d791f21b556875d14d0cc8372d405b762e Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 14:56:15 +0100 Subject: [PATCH 09/11] add pytest args --- .submodules/config/configs.jsonc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.submodules/config/configs.jsonc b/.submodules/config/configs.jsonc index 3f06ca8a..867d7f2a 100644 --- a/.submodules/config/configs.jsonc +++ b/.submodules/config/configs.jsonc @@ -350,6 +350,13 @@ "settings": { "python.analysis.extraPaths": [ "../codeforlife-package-python" + ], + "!python.testing.pytestArgs": [ + "-n=auto", + "--cov=src", + "--cov-report=html", + "-c=pyproject.toml", + "src" ] }, "tasks": { From 9246b8330bdb9a7a671c9f0c412370cf849fb2c1 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 14:59:33 +0100 Subject: [PATCH 10/11] add codeforlife-portal-backend submodule --- .gitmodules | 3 +++ codeforlife-portal-backend | 1 + 2 files changed, 4 insertions(+) create mode 160000 codeforlife-portal-backend diff --git a/.gitmodules b/.gitmodules index 8bc0d7d8..c12a8278 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "codeforlife-portal-frontend"] path = codeforlife-portal-frontend url = https://github.com/ocadotechnology/codeforlife-portal-frontend.git +[submodule "codeforlife-portal-backend"] + path = codeforlife-portal-backend + url = https://github.com/ocadotechnology/codeforlife-portal-backend.git diff --git a/codeforlife-portal-backend b/codeforlife-portal-backend new file mode 160000 index 00000000..4ac0b1f3 --- /dev/null +++ b/codeforlife-portal-backend @@ -0,0 +1 @@ +Subproject commit 4ac0b1f391052af79e5b8a17a7adb10cad655aae From ac1246ffbebeb1c9b532b47cbd69924f26e42152 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 7 Jun 2024 15:00:22 +0100 Subject: [PATCH 11/11] reference backend --- .submodules/config/configs.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.submodules/config/configs.jsonc b/.submodules/config/configs.jsonc index 867d7f2a..8a8a6993 100644 --- a/.submodules/config/configs.jsonc +++ b/.submodules/config/configs.jsonc @@ -344,7 +344,7 @@ ], "description": "A devcontainer for a backend micro-service.", "submodules": [ - "codeforlife-portal-react" + "codeforlife-portal-backend" ], "vscode": { "settings": {