Skip to content

Commit

Permalink
Convert to backend repo (#112)
Browse files Browse the repository at this point in the history
* reference source path

* get service name composite action

* get services name and test backend workflow

* test backend deploy

* don't install dev deps

* tidy up pipelines

* make script executable

* remove codeforlife-portal-react submodule

* add pytest args

* add codeforlife-portal-backend submodule

* reference backend
  • Loading branch information
SKairinos committed Jun 7, 2024
1 parent 7779994 commit b4fbf91
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions .github/actions/gcloud/get-service-name/action.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 7 additions & 17 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
secrets: inherit
with:
python-version: ${{ inputs.python-version }}
source-path: src

deploy:
runs-on: ubuntu-latest
Expand All @@ -37,44 +38,33 @@ 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

- 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@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 }}
runtime=${runtime//.}
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
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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@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
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/test-python-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
[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
[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
11 changes: 9 additions & 2 deletions .submodules/config/configs.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -344,12 +344,19 @@
],
"description": "A devcontainer for a backend micro-service.",
"submodules": [
"codeforlife-portal-react"
"codeforlife-portal-backend"
],
"vscode": {
"settings": {
"python.analysis.extraPaths": [
"../codeforlife-package-python"
],
"!python.testing.pytestArgs": [
"-n=auto",
"--cov=src",
"--cov-report=html",
"-c=pyproject.toml",
"src"
]
},
"tasks": {
Expand Down
1 change: 1 addition & 0 deletions codeforlife-portal-backend
1 change: 0 additions & 1 deletion codeforlife-portal-react
Submodule codeforlife-portal-react deleted from 0c42b5

0 comments on commit b4fbf91

Please sign in to comment.