-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #770 from MetaCell/feature/ch-59
CH-59 Update/Refactor the django application template
- Loading branch information
Showing
36 changed files
with
438 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
application-templates/django-app/backend/__APP_NAME__/controllers/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import __APP_NAME__.controllers.test as test_controller |
File renamed without changes.
18 changes: 2 additions & 16 deletions
18
application-templates/django-app/backend/__APP_NAME__/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,10 @@ | ||
import os | ||
|
||
from django.db import migrations | ||
|
||
|
||
def create_kc_client_and_roles(apps, schema_editor): | ||
if os.environ.get("KUBERNETES_SERVICE_HOST", None): | ||
# running in K8S so create the KC client and roles | ||
from cloudharness_django.services import get_auth_service, get_user_service, init_services | ||
|
||
init_services() | ||
get_auth_service().create_client() | ||
get_user_service().sync_kc_users_groups() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cloudharness_django", "0001_initial"), | ||
("django_baseapp", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_kc_client_and_roles), | ||
] | ||
operations = [] |
File renamed without changes.
25 changes: 2 additions & 23 deletions
25
application-templates/django-app/backend/__APP_NAME__/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,3 @@ | ||
import mimetypes | ||
from pathlib import Path | ||
from django.shortcuts import render | ||
|
||
from django.conf import settings | ||
from django.http import FileResponse, HttpResponseRedirect | ||
from django.urls import reverse | ||
from django.utils._os import safe_join | ||
|
||
|
||
def view_404(request, exception=None): | ||
return HttpResponseRedirect(reverse("index")) | ||
|
||
|
||
def index(request, path=""): | ||
if path == "": | ||
path = "index.html" | ||
fullpath = Path(safe_join(settings.STATIC_ROOT, "www", path)) | ||
content_type, encoding = mimetypes.guess_type(str(fullpath)) | ||
content_type = content_type or "application/octet-stream" | ||
try: | ||
fullpath.open("rb") | ||
except FileNotFoundError: | ||
return index(request, "") # index.html | ||
return FileResponse(fullpath.open("rb"), content_type=content_type) | ||
# Create your views here. |
1 change: 0 additions & 1 deletion
1
application-templates/django-app/backend/api/controllers/__init__.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
application-templates/django-app/backend/django_baseapp/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
from django.db import migrations | ||
|
||
|
||
def create_kc_client_and_roles(apps, schema_editor): | ||
if os.environ.get("KUBERNETES_SERVICE_HOST", None): | ||
# running in K8S so create the KC client and roles | ||
from cloudharness_django.services import get_auth_service, get_user_service, init_services | ||
|
||
init_services() | ||
get_auth_service().create_client() | ||
get_user_service().sync_kc_users_groups() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cloudharness_django", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_kc_client_and_roles), | ||
] |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
application-templates/django-app/backend/django_baseapp/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import mimetypes | ||
from pathlib import Path | ||
|
||
from django.conf import settings | ||
from django.http import FileResponse, HttpResponseRedirect | ||
from django.urls import reverse | ||
from django.utils._os import safe_join | ||
|
||
|
||
def view_404(request, exception=None): | ||
return HttpResponseRedirect(reverse("index")) | ||
|
||
|
||
def index(request, path=""): | ||
if path == "": | ||
path = "index.html" | ||
fullpath = Path(safe_join(settings.STATIC_ROOT, "www", path)) | ||
content_type, encoding = mimetypes.guess_type(str(fullpath)) | ||
content_type = content_type or "application/octet-stream" | ||
try: | ||
fullpath.open("rb") | ||
except FileNotFoundError: | ||
return index(request, "") # index.html | ||
return FileResponse(fullpath.open("rb"), content_type=content_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
CURRENT_PATH=$(pwd) | ||
CH_DIRECTORY="../../cloud-harness" | ||
INSTALL_PYTEST=false | ||
CURRENT_DIRECTORY="$(pwd)" | ||
APP_NAME="__APP_NAME__" | ||
|
||
pip_upgrade_error() { | ||
echo "Unable to upgrade pip" | ||
exit 1 | ||
} | ||
|
||
install_error () { | ||
echo "Unable to install $1" 1>&2 | ||
exit 1 | ||
} | ||
|
||
while getopts ch_directory:pytest arg; | ||
do | ||
case "$arg" in | ||
ch_directory) CH_DIRECTORY=${OPTARG};; | ||
pytest) INSTALL_PYTEST=true;; | ||
esac | ||
done | ||
|
||
pip install --upgrade pip || pip_upgrade_error | ||
|
||
# Install pip dependencies from cloudharness-base-debian image | ||
|
||
if $INSTALL_PYTEST; then | ||
pip install pytest || install_error pytest | ||
fi | ||
|
||
pip install -r "$CH_DIRECTORY/libraries/models/requirements.txt" || install_error "models requirements" | ||
pip install -r "$CH_DIRECTORY/libraries/cloudharness-common/requirements.txt" || install_error "cloudharness-common requirements" | ||
pip install -r "$CH_DIRECTORY/libraries/client/cloudharness_cli/requirements.txt" || install_error "cloudharness_cli requirements" | ||
|
||
pip install -e "$CH_DIRECTORY/libraries/models" || install_error models | ||
pip install -e "$CH_DIRECTORY/libraries/cloudharness-common" || install_error cloudharness-common | ||
pip install -e "$CH_DIRECTORY/libraries/client/cloudharness_cli" || install_error cloudharness_cli | ||
|
||
# Install pip dependencies from cloudharness-django image | ||
|
||
pip install -r "$CH_DIRECTORY/infrastructure/common-images/cloudharness-django/libraries/fastapi/requirements.txt" || install_error "cloudharness-django fastapi requirements" | ||
pip install -e "$CH_DIRECTORY/infrastructure/common-images/cloudharness-django/libraries/cloudharness-django" || install_error cloudharness-django | ||
|
||
# Install application | ||
|
||
pip install -r "$CURRENT_DIRECTORY/backend/requirements.txt" || install_error "$APP_NAME dependencies" | ||
pip install -e "$CURRENT_DIRECTORY/backend" || install_error "$APP_NAME" |
24 changes: 24 additions & 0 deletions
24
deployment-configuration/vscode-django-app-debug-template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"args": [ | ||
"--host", | ||
"0.0.0.0", | ||
"--port", | ||
"8000", | ||
"main:app" | ||
], | ||
"console": "integratedTerminal", | ||
"cwd": "${workspaceFolder}/applications/__APP_NAME__/backend", | ||
"env": { | ||
"ACCOUNTS_ADMIN_PASSWORD": "metacell", | ||
"ACCOUNTS_ADMIN_USERNAME": "admin", | ||
"CH_CURRENT_APP_NAME": "__APP_NAME__", | ||
"CH_VALUES_PATH": "${workspaceFolder}/deployment/helm/values.yaml", | ||
"DJANGO_SETTINGS_MODULE": "django_baseapp.settings", | ||
"KUBERNETES_SERVICE_HOST": "ssdds" | ||
}, | ||
"justMyCode": false, | ||
"module": "uvicorn", | ||
"name": "__APP_NAME__ backend", | ||
"request": "launch", | ||
"type": "debugpy" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.