Skip to content

Commit

Permalink
feat: Bundle front end and add Django backend (ocadotechnology#27)
Browse files Browse the repository at this point in the history
* feat: Bundle frontend and integrate Django project

* Try fixing run script and update test workflow

* Specify frontend dir

* Move it to with args

* Update run script dir

* Setup Python and install pipenv

* Increase timeout

* Use relative imports for now

* Update CFL JS package

* Merge main

* updated lock file

Co-Authored-By: SKairinos <stefan.kairinos@ocado.com>
  • Loading branch information
faucomte97 and SKairinos authored May 4, 2023
1 parent ff6f163 commit 48b1c95
Show file tree
Hide file tree
Showing 189 changed files with 3,940 additions and 607 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Main
on: [push]

env:
CYPRESS_WAIT_ON: http://localhost:3000
CYPRESS_WAIT_ON_TIMEOUT: 120
CYPRESS_SPEC: cypress/e2e/**/*.cy.ts
CYPRESS_WAIT_ON: http://localhost:8000
CYPRESS_WAIT_ON_TIMEOUT: 300
CYPRESS_SPEC: frontend/cypress/e2e/**/*.cy.ts

jobs:
# The below code was adapted from this documentation.
Expand All @@ -17,25 +17,34 @@ jobs:
- name: 🛫 Checkout
uses: actions/checkout@v3

- name: 🐍 Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
architecture: "x64"

- name: 🧪 Test on Chrome
uses: cypress-io/github-action@v5.6.1
with:
build: yarn build
start: yarn serve
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') }}
cache-key: os-${{ runner.os }}-dependencies-${{ hashFiles('frontend/yarn.lock') }}
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- 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
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

#IDE files
/.idea

# dependencies
/node_modules
*/node_modules
/.pnp
.pnp.js

Expand All @@ -26,3 +29,10 @@ yarn-error.log*
/.nyc_output
/cypress/videos
/cypress/screenshots

# files generated by the Django bundler and settings
/backend/*/static/react
/backend/*/templates/portal.html
/backend/static
*.sqlite3
/frontend/build
12 changes: 12 additions & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
codeforlife = {ref = "v0.1.12", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}

[dev-packages]

[requires]
python_version = "3.11"
124 changes: 124 additions & 0 deletions backend/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
22 changes: 22 additions & 0 deletions backend/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'service.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
File renamed without changes.
3 changes: 3 additions & 0 deletions backend/portal/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/portal/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PortalConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'portal'
File renamed without changes.
3 changes: 3 additions & 0 deletions backend/portal/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Empty file.
3 changes: 3 additions & 0 deletions backend/portal/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions backend/portal/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import url

from . import views

urlpatterns = [
url(r".*", views.render_react, name="react_app"),
]
5 changes: 5 additions & 0 deletions backend/portal/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.shortcuts import render


def render_react(request):
return render(request, "portal.html")
Empty file added backend/service/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions backend/service/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for service project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'service.settings')

application = get_asgi_application()
Loading

0 comments on commit 48b1c95

Please sign in to comment.