Skip to content

Commit b4fbf91

Browse files
authored
Convert to backend repo (#112)
* 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
1 parent 7779994 commit b4fbf91

File tree

9 files changed

+59
-32
lines changed

9 files changed

+59
-32
lines changed

.devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"ghcr.io/devcontainers/features/github-cli:1": {}
3535
},
3636
"name": "workspace",
37-
"postCreateCommand": ".submodules/recurse-fork/run",
37+
"postCreateCommand": "sudo chmod u+x .submodules/recurse-fork/run && .submodules/recurse-fork/run",
3838
"remoteUser": "root",
3939
"service": "base-service",
4040
"shutdownAction": "none",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "Code for Life - GCloud - Get Service Name"
2+
description: "Get a service's name based on the name of the current repository."
3+
outputs:
4+
service-name:
5+
description: "The name of the current service."
6+
value: ${{ steps.get-service-name.outputs.service-name }}
7+
runs:
8+
using: composite
9+
steps:
10+
# Set name with convention "{ENV_NAME}-{REPO_NAME}"
11+
# where ENV_NAME is the name of the branch / environment.
12+
# where REPO_NAME is the name of the repo without the prefix "ocadotechnology/codeforlife-".
13+
- name: 🪪 Get Service Name
14+
id: get-service-name
15+
shell: bash
16+
run: |
17+
name=${{ github.repository }}
18+
name=${name#"ocadotechnology/codeforlife-"}
19+
name="${{ github.ref_name }}-${name}"
20+
21+
echo "service-name=$(echo $name)" >> $GITHUB_OUTPUT

.github/workflows/backend.yaml

+7-17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
secrets: inherit
2626
with:
2727
python-version: ${{ inputs.python-version }}
28+
source-path: src
2829

2930
deploy:
3031
runs-on: ubuntu-latest
@@ -37,44 +38,33 @@ jobs:
3738
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@main
3839
with:
3940
python-version: ${{ inputs.python-version }}
40-
install-args: --dev
4141

4242
- name: 🏗️ Generate requirements.txt
4343
run: pipenv requirements > requirements.txt
4444

4545
- name: 🏗️ Collect Static Files
4646
run: pipenv run python ./manage.py collectstatic --noinput --clear
4747

48+
- name: 🪪 Get Service Name
49+
id: get-service-name
50+
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@main
51+
4852
# https://mikefarah.gitbook.io/yq/
4953
# TODO: clean up app.yaml environment variables
5054
- name: 🖊️ Configure App Deployment
5155
uses: mikefarah/yq@master
5256
with:
5357
cmd: |
54-
# Set name with convention "{ENV_NAME}-{REPO_NAME}"
55-
name=${{ github.repository }}
56-
name=${name#"ocadotechnology/codeforlife-"}
57-
name="${{ github.ref_name }}-${name}"
58-
59-
# Check if service is the client-facing service.
60-
is_root=$(
61-
if [ ${{ github.ref_name }} == "production" ]
62-
then echo "1"
63-
else echo "0"
64-
fi
65-
)
66-
6758
# Set runtime with convention "python{PY_VERSION}".
6859
# The version must have the dot removed: "python3.8" -> "python38".
6960
runtime=python${{ inputs.python-version }}
7061
runtime=${runtime//.}
7162
7263
yq -i '
7364
.runtime = "'$runtime'" |
74-
.service = "'$name'" |
65+
.service = "${{ steps.get-service-name.outputs.service-name }}" |
66+
.env_variables.SERVICE_NAME = "${{ steps.get-service-name.outputs.service-name }}" |
7567
.env_variables.SECRET_KEY = "${{ secrets.SECRET_KEY }}" |
76-
.env_variables.SERVICE_NAME = "$name" |
77-
.env_variables.SERVICE_IS_ROOT = "$is_root" |
7868
.env_variables.MODULE_NAME = "${{ github.ref_name }}"
7969
' app.yaml
8070

.github/workflows/frontend.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ jobs:
4242
- name: 🏗️ Build App
4343
run: yarn build
4444

45+
- name: 🪪 Get Service Name
46+
id: get-service-name
47+
uses: ocadotechnology/codeforlife-workspace/.github/actions/gcloud/get-service-name@main
48+
4549
# https://mikefarah.gitbook.io/yq/
4650
- name: 🖊️ Configure App Deployment
4751
uses: mikefarah/yq@master
4852
with:
4953
cmd: |
50-
# Set name with convention "{ENV_NAME}-{REPO_NAME}"
51-
name=${{ github.repository }}
52-
name=${name#"ocadotechnology/codeforlife-"}
53-
name="${{ github.ref_name }}-${name}"
54-
5554
yq -i '
5655
.runtime = "nodejs${{ inputs.node-version }}" |
57-
.service = "'$name'"
56+
.service = "${{ steps.get-service-name.outputs.service-name }}"
5857
' app.yaml
5958
6059
- name: 🚀 Deploy App on GCloud

.github/workflows/test-python-code.yaml

+12-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,19 @@ jobs:
112112
run: |
113113
if [ ${{ github.repository_owner_id }} = ${{ env.OCADO_TECH_ORG_ID }} ]
114114
then
115-
pipenv run pytest -n=auto --cov=. --cov-report=xml:${{ env.COVERAGE_REPORT }} -c=${{ env.PYPROJECT_TOML }} ${{ inputs.source-path }}
115+
pipenv run pytest \
116+
-n=auto \
117+
--cov=${{ inputs.source-path }} \
118+
--cov-report=xml:${{ env.COVERAGE_REPORT }} \
119+
-c=${{ env.PYPROJECT_TOML }} \
120+
${{ inputs.source-path }}
116121
else
117-
pipenv run pytest -n=auto --cov=. --cov-fail-under=90 -c=${{ env.PYPROJECT_TOML }} ${{ inputs.source-path }}
122+
pipenv run pytest \
123+
-n=auto \
124+
--cov=${{ inputs.source-path }} \
125+
--cov-fail-under=90 \
126+
-c=${{ env.PYPROJECT_TOML }} \
127+
${{ inputs.source-path }}
118128
fi
119129
120130
- name: 📈 Upload Coverage Reports to Codecov

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
[submodule "codeforlife-service-template"]
2020
path = codeforlife-service-template
2121
url = https://github.com/ocadotechnology/codeforlife-service-template.git
22-
[submodule "codeforlife-portal-react"]
23-
path = codeforlife-portal-react
24-
url = https://github.com/ocadotechnology/codeforlife-portal-react.git
2522
[submodule "codeforlife-sso"]
2623
path = codeforlife-sso
2724
url = https://github.com/ocadotechnology/codeforlife-sso.git
2825
[submodule "codeforlife-portal-frontend"]
2926
path = codeforlife-portal-frontend
3027
url = https://github.com/ocadotechnology/codeforlife-portal-frontend.git
28+
[submodule "codeforlife-portal-backend"]
29+
path = codeforlife-portal-backend
30+
url = https://github.com/ocadotechnology/codeforlife-portal-backend.git

.submodules/config/configs.jsonc

+9-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
],
319319
"description": "The devcontainer for a micro-service.",
320320
"devcontainer": {
321-
"postCreateCommand": "chmod u+x ./setup && ./setup",
321+
"postCreateCommand": "sudo chmod u+x ./setup && ./setup",
322322
"mounts": [
323323
"source=./codeforlife-package-javascript,target=/workspace/codeforlife-package-javascript,type=bind,consistency=cached",
324324
"source=./codeforlife-package-python,target=/workspace/codeforlife-package-python,type=bind,consistency=cached"
@@ -344,12 +344,19 @@
344344
],
345345
"description": "A devcontainer for a backend micro-service.",
346346
"submodules": [
347-
"codeforlife-portal-react"
347+
"codeforlife-portal-backend"
348348
],
349349
"vscode": {
350350
"settings": {
351351
"python.analysis.extraPaths": [
352352
"../codeforlife-package-python"
353+
],
354+
"!python.testing.pytestArgs": [
355+
"-n=auto",
356+
"--cov=src",
357+
"--cov-report=html",
358+
"-c=pyproject.toml",
359+
"src"
353360
]
354361
},
355362
"tasks": {

codeforlife-portal-backend

codeforlife-portal-react

-1
This file was deleted.

0 commit comments

Comments
 (0)