Skip to content

Commit

Permalink
Convert to backend repo (#331)
Browse files Browse the repository at this point in the history
* rename backend to src

* add .venv to root

* move config files to root

* reference src

* reference src

* reference src

* add fixture

* reference sec

* comment out not implement tests

* comment out not implemented test

* reference src

* use new cfl package

* ignore long line

* fix tasks

* ignore .venv

* set service is root

* use new cfl package

* fix: typed model meta import

* fix: config

* configure workspace

* call main

* fix relative path

* new py package
  • Loading branch information
SKairinos authored Jun 7, 2024
1 parent 4ac0b1f commit 339e659
Show file tree
Hide file tree
Showing 99 changed files with 103 additions and 315 deletions.
10 changes: 6 additions & 4 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"tamasfe.even-better-toml",
"github.vscode-github-actions",
"codecov.codecov",
"ritwickdey.liveserver"
"ritwickdey.liveserver",
"esbenp.prettier-vscode"
]
}
},
Expand All @@ -41,13 +42,14 @@
}
},
"mounts": [
"source=./codeforlife-portal-frontend,target=/workspace/codeforlife-portal-frontend,type=bind,consistency=cached",
"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"
],
"name": "portal-react",
"postCreateCommand": "./setup",
"name": "portal-backend",
"postCreateCommand": "sudo chmod u+x ./setup && ./setup",
"remoteUser": "root",
"service": "base-service",
"shutdownAction": "none",
"workspaceFolder": "/workspace/codeforlife-portal-react"
"workspaceFolder": "/workspace/codeforlife-portal-backend"
}
15 changes: 15 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/Pipfile
/Pipfile.lock
/manage.py
/.devcontainer.json
/.github
/.venv
/.vscode
/.gitignore
/codecov.yml
/*.toml
/*.code-*
/*.md
/setup
/run
/frontend
161 changes: 2 additions & 159 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,164 +5,7 @@ on:
pull_request:
workflow_dispatch:

env:
CYPRESS_WAIT_ON: http://localhost:8000
CYPRESS_WAIT_ON_TIMEOUT: 600
CYPRESS_SPEC: cypress/e2e/**/*.cy.ts
SERVICE: portal
PYTHON_VERSION: 3.8

jobs:
test-backend:
uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main
main:
uses: ocadotechnology/codeforlife-workspace/.github/workflows/backend.yaml@main
secrets: inherit
with:
working-directory: backend

# # The below code was adapted from this documentation.
# # https://docs.cypress.io/guides/continuous-integration/github-actions#Parallelization
# # https://github.com/cypress-io/cypress-docker-images/tree/master/browsers
# test-chrome:
# runs-on: ubuntu-latest
# steps:
# - name: 🛫 Checkout
# uses: actions/checkout@v3

# - name: 🐍 Setup Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# architecture: "x64"

# - name: 🧪 Test on Chrome
# uses: cypress-io/[email protected]
# with:
# working-directory: frontend
# #TODO: Currently using the run script for local development
# start: bash ../run
# wait-on: ${{ env.CYPRESS_WAIT_ON }}
# wait-on-timeout: ${{ env.CYPRESS_WAIT_ON_TIMEOUT }}
# browser: chrome
# record: true
# spec: ${{ env.CYPRESS_SPEC }}
# cache-key: os-${{ runner.os }}-dependencies-${{ hashFiles('yarn.lock') }}
# env:
# CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NODE_ENV: production
# # TODO: load these from a file.
# REACT_APP_API_BASE_URL: 'http://localhost:8000/api/'
# REACT_APP_PORTAL_BASE_URL: 'http://localhost:8000'

# - name: 🔍 Report test info
# working-directory: frontend
# run: npx cypress info

# - name: 🔍 Report CPU info
# working-directory: frontend
# run: node -p 'os.cpus()'

# - name: ✅ Upload coverage to Codecov
# uses: codecov/[email protected]

# build-and-deploy:
# runs-on: ubuntu-latest
# needs: [test-chrome]
# if: github.ref_name == 'production' || github.ref_name == 'development' || github.ref_name == 'staging'
# environment: ${{ github.ref_name }}
# steps:
# - name: 🛫 Checkout
# uses: actions/checkout@v3

# - name: 🌐 Set up Node
# uses: actions/setup-node@v3
# with:
# node-version: 18

# - name: 🐍 Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.PYTHON_VERSION }}

# - name: 🗝 Authenticate with GCloud
# uses: google-github-actions/auth@v1
# with:
# credentials_json: ${{ secrets.GCP_CREDENTIALS }}

# - name: 🤖 Set up GCloud SDK
# uses: google-github-actions/setup-gcloud@v1

# - name: 🛠 Install Frontend Dependencies
# working-directory: ./frontend
# run: yarn install
# # TODO: fix dependencies and uncomment below lines
# # env:
# # NODE_ENV: production

# - name: 🛠 Build Frontend
# working-directory: ./frontend
# run: yarn run build
# env:
# NODE_ENV: production

# - name: 🛠 Bundle Frontend
# working-directory: ./frontend
# run: node djangoBundler.js
# env:
# NODE_ENV: production
# REACT_APP_API_BASE_URL: ${{ vars.REACT_APP_API_BASE_URL }}
# REACT_APP_PORTAL_BASE_URL: ${{ vars.REACT_APP_PORTAL_BASE_URL }}
# REACT_APP_SSO_SERVICE_NAME: ${{ vars.REACT_APP_SSO_SERVICE_NAME }}
# REACT_APP_SSO_SERVICE_PROTOCOL: 'https'
# REACT_APP_SSO_SERVICE_DOMAIN: 'codeforlife.education'
# REACT_APP_SSO_SERVICE_PORT: '443'

# - name: 🛠 Install Backend Dependencies
# working-directory: ./backend
# run: |
# python -m pip install --upgrade pip
# python -m pip install pipenv
# pipenv install

# - name: 🔎 Check Migrations
# working-directory: ./backend
# run: pipenv run python ./manage.py makemigrations --check --dry-run

# - name: 🛠 Generate requirements.txt
# working-directory: ./backend
# run: pipenv requirements > requirements.txt

# - name: 🛠 Collect Static Files
# working-directory: ./backend
# run: pipenv run python ./manage.py collectstatic --noinput --clear

# # https://mikefarah.gitbook.io/yq/
# - name: 🖊️ Configure App Deployment
# uses: mikefarah/yq@master
# with:
# cmd: |
# SERVICE_NAME=$(
# if [ ${{ github.ref_name }} == "production" ]
# then echo ${{ env.SERVICE_NAME }}
# else echo ${{ github.ref_name }}-${{ env.SERVICE_NAME }}
# fi
# )

# SERVICE_IS_ROOT=$(
# if [ ${{ github.ref_name }} == "production" ]
# then echo "1"
# else echo "0"
# fi
# )

# yq -i '
# .service = "${{ github.ref_name }}-${{ env.SERVICE }}" |
# .env_variables.SECRET_KEY = "${{ vars.SECRET_KEY }}" |
# .env_variables.SERVICE_NAME = "$SERVICE_NAME" |
# .env_variables.SERVICE_IS_ROOT = "$SERVICE_IS_ROOT" |
# .env_variables.MODULE_NAME = "${{ github.ref_name }}"
# ' backend/app.yaml

# - name: 🚀 Deploy App on GCloud
# working-directory: ./backend
# run: gcloud app deploy
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ yarn-error.log*
.nyc_output
cypress/videos
cypress/screenshots
/backend/.python-version
/backend/*/static/react
/backend/*/templates/portal.html
/backend/static
/src/.python-version
/src/*/static/react
/src/*/templates/portal.html
/src/static
*.sqlite3
/frontend/build
node_modules
Expand Down
File renamed without changes.
14 changes: 0 additions & 14 deletions .vscode/codeforlife.code-snippets
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
{
"javascript.module.doccomment": {
"body": [
"/**",
" * \u00a9 Ocado Group",
" * Created on $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR at $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND($CURRENT_TIMEZONE_OFFSET).",
" *",
" * ${1:__description__}",
" */"
],
"prefix": [
"/"
],
"scope": "javascript,typescript,javascriptreact,typescriptreact"
},
"python.module.docstring": {
"body": [
"\"\"\"",
Expand Down
9 changes: 1 addition & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
"request": "test",
"type": "debugpy"
},
{
"name": "React Dev Server",
"preLaunchTask": "start-react-dev-server",
"request": "launch",
"type": "chrome",
"url": "http://localhost:3000"
},
{
"args": [
"runserver",
Expand All @@ -40,7 +33,7 @@
"justMyCode": false,
"name": "Django Server",
"preLaunchTask": "migrate-db",
"program": "${workspaceFolder}/backend/manage.py",
"program": "${workspaceFolder}/manage.py",
"request": "launch",
"type": "debugpy"
}
Expand Down
17 changes: 6 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"--config",
"pyproject.toml"
],
"black-formatter.cwd": "${workspaceFolder}/backend",
"black-formatter.path": [
".venv/bin/python",
"-m",
Expand Down Expand Up @@ -38,17 +37,16 @@
"**/__pycache__": true
},
"isort.args": [
"--settings-file=backend/pyproject.toml"
"--settings-file=pyproject.toml"
],
"isort.path": [
"backend/.venv/bin/python",
".venv/bin/python",
"-m",
"isort"
],
"mypy-type-checker.args": [
"--config-file=pyproject.toml"
],
"mypy-type-checker.cwd": "${workspaceFolder}/backend",
"mypy-type-checker.path": [
".venv/bin/python",
"-m",
Expand All @@ -57,7 +55,6 @@
"pylint.args": [
"--rcfile=pyproject.toml"
],
"pylint.cwd": "${workspaceFolder}/backend",
"pylint.path": [
".venv/bin/python",
"-m",
Expand All @@ -66,16 +63,14 @@
"python.analysis.extraPaths": [
"../codeforlife-package-python"
],
"python.defaultInterpreterPath": "backend/.venv/bin/python",
"python.testing.cwd": "${workspaceFolder}/backend",
"python.defaultInterpreterPath": ".venv/bin/python",
"python.testing.pytestArgs": [
"-n=auto",
"--cov=.",
"--cov=src",
"--cov-report=html",
"-c=pyproject.toml",
"."
"src"
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"typescript.preferences.quoteStyle": "single"
"python.testing.unittestEnabled": false
}
19 changes: 0 additions & 19 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
{
"tasks": [
{
"isBackground": true,
"label": "start-react-dev-server",
"options": {
"env": {
"BROWSER": "none"
}
},
"path": "frontend",
"problemMatcher": [],
"script": "start",
"type": "npm"
},
{
"command": "pipenv install --dev",
"label": "pipenv-install-dev",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"type": "shell"
},
{
Expand All @@ -27,9 +11,6 @@
"pipenv-install-dev"
],
"label": "migrate-db",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"type": "shell"
}
],
Expand Down
6 changes: 3 additions & 3 deletions backend/Pipfile → Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name = "pypi"
# 5. Run `pipenv install --dev` in your terminal.

[packages]
codeforlife = {ref = "v0.16.9", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "v0.16.10", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
# 🚫 Don't add [packages] below that are inherited from the CFL package.
pyjwt = "==2.6.0" # TODO: upgrade to latest version
# TODO: Needed by RR. Remove when RR has moved to new system.
Expand All @@ -32,8 +32,8 @@ django-sekizai = "==2.0.0"
django-classy-tags = "==2.0.0"

[dev-packages]
codeforlife = {ref = "v0.16.9", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
# codeforlife = {file = "../../codeforlife-package-python", editable = true, extras = ["dev"]}
codeforlife = {ref = "v0.16.10", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]}
# codeforlife = {file = "../codeforlife-package-python", editable = true, extras = ["dev"]}
# 🚫 Don't add [dev-packages] below that are inherited from the CFL package.

[requires]
Expand Down
Loading

0 comments on commit 339e659

Please sign in to comment.